Java Code Examples for org.eclipse.xtext.naming.QualifiedName#toString()

The following examples show how to use org.eclipse.xtext.naming.QualifiedName#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NestedTypeAwareImportNormalizer.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private QualifiedName internalResolve(QualifiedName relativeName) {
	if (relativeName.getSegmentCount() != 1) {
		throw new IllegalArgumentException(relativeName.toString());
	}
	String lastImportSegment = getImportedNamespacePrefix().getLastSegment();
	int importDollarIndex = lastImportSegment.lastIndexOf('$');
	if (importDollarIndex != -1) {
		lastImportSegment = lastImportSegment.substring(importDollarIndex + 1);
	}
	String singleSegment = relativeName.getFirstSegment();
	if (lastImportSegment.equals(singleSegment)) {
		return getImportedNamespacePrefix();
	}
	if (singleSegment.startsWith(lastImportSegment) && singleSegment.charAt(lastImportSegment.length()) == '$') {
		if (importDollarIndex == -1)
			return getImportedNamespacePrefix().skipLast(1).append(relativeName);
		else {
			String resolvedLastSegment = getImportedNamespacePrefix().getLastSegment() + singleSegment.substring(lastImportSegment.length());
			return getImportedNamespacePrefix().skipLast(1).append(resolvedLastSegment);
		}
	}
	return null;
}
 
Example 2
Source File: AbstractConstantExpressionsInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected String getOperator(final XAbstractFeatureCall call) {
  String _switchResult = null;
  Resource _eResource = call.eResource();
  final Resource res = _eResource;
  boolean _matched = false;
  if (res instanceof StorageAwareResource) {
    boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage();
    if (_isLoadedFromStorage) {
      _matched=true;
      QualifiedName _operator = this.operatorMapping.getOperator(QualifiedName.create(call.getFeature().getSimpleName()));
      String _string = null;
      if (_operator!=null) {
        _string=_operator.toString();
      }
      return _string;
    }
  }
  if (!_matched) {
    _switchResult = call.getConcreteSyntaxFeatureName();
  }
  return _switchResult;
}
 
Example 3
Source File: EObjectDescriptionBasedStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public String getJavaStubSource(IEObjectDescription description, IResourceDescription resourceDescription) {
	if(isNestedType(description) || !isJvmDeclaredType(description)) {
		return null;
	}
	Multimap<QualifiedName, IEObjectDescription> owner2nested = LinkedHashMultimap.create();
	for(IEObjectDescription other: resourceDescription.getExportedObjects()) {
		if(isJvmDeclaredType(other) && isNestedType(other))
			owner2nested.put(getOwnerClassName(other.getQualifiedName()), other);
	}
	StringBuilder classSignatureBuilder = new StringBuilder();
	QualifiedName qualifiedName = description.getQualifiedName();
	if (qualifiedName.getSegments().size() > 1) {
		String string = qualifiedName.toString();
		classSignatureBuilder.append("package " + string.substring(0, string.lastIndexOf('.')) + ";");
	}
	appendType(description, owner2nested, classSignatureBuilder);
	return classSignatureBuilder.toString();
}
 
Example 4
Source File: FormatScopeNameProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a name function which returns an element's name based on baseNameFunction
 * and its index in a list of peers.
 *
 * @param all
 *          List of all candidates
 * @param baseNameFunction
 *          name function to use for name prefix
 * @return name function for elements in all
 */
public Function<EObject, QualifiedName> getIndexParameterNameFunction(final Function<EObject, QualifiedName> baseNameFunction, final List<? extends EObject> all) {
  return new Function<EObject, QualifiedName>() {
    @Override
    public QualifiedName apply(final EObject from) {
      final QualifiedName baseName = baseNameFunction.apply(from);
      Iterable<? extends EObject> nameTwins = Iterables.filter(all, new Predicate<EObject>() {
        @Override
        public boolean apply(final EObject input) {
          return baseName.equals(baseNameFunction.apply(input));
        }
      });
      if (Iterables.size(nameTwins) < 2) {
        return baseName;
      } else {
        StringBuilder name = new StringBuilder(baseName.toString());
        name.append('(');
        name.append(getIndexNameFunction(Lists.newArrayList(nameTwins)).apply(from));
        name.append(',');
        name.append(Iterables.size(nameTwins));
        name.append(')');
        return QualifiedName.create(name.toString());
      }
    }
  };
}
 
Example 5
Source File: N4JSModel.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IN4JSSourceContainer#findArtifact(QualifiedName, Optional)
 */
public SafeURI<?> findArtifact(IN4JSSourceContainer sourceContainer, QualifiedName name,
		Optional<String> fileExtension) {
	final String ext = fileExtension.or("").trim();
	final String extWithDot = !ext.isEmpty() && !ext.startsWith(".") ? "." + ext : ext;
	final String pathStr = name.toString("/") + extWithDot; // no need for IQualifiedNameConverter here!

	SafeURI<?> artifactLocation = findArtifactInFolder(workspace, sourceContainer.getLocation().toURI(),
			pathStr);
	if (null == artifactLocation) {
		artifactLocation = findArtifactInFolder(externalLibraryWorkspace, sourceContainer.getLocation().toURI(),
				pathStr);
	}
	return artifactLocation;
}
 
Example 6
Source File: GamlLabelProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param ele
 * @return
 */
private String attributeText(final S_Definition ele) {
	String type = EGaml.getInstance().getKeyOf(ele);
	String key = type.equals(IKeyword.CONST) ? type : null;
	final Map<String, Facet> map = EGaml.getInstance().getFacetsMapOf(ele);
	if (ele.getBlock() != null /* && ele.getBlock().getFunction() != null */) {
		key = "function";
	} else {
		if (map.containsKey(IKeyword.FUNCTION) || map.containsKey("->")) {
			type = "function";
		}
	}
	if (type.equals(IKeyword.VAR) || type.equals(IKeyword.CONST)) {
		final Facet f = map.get(IKeyword.TYPE);
		if (f != null) {
			type = EGaml.getInstance().getKeyOf(f.getExpr());
		}
	}
	String name = EGaml.getInstance().getNameOf(ele);
	if (name == null) {
		final Expression expr = ((Statement) ele).getExpr();
		if (expr != null) {
			name = EGaml.getInstance().getKeyOf(expr);
		}
	}
	if (name == null) {
		QualifiedName qn = null;
		try {
			qn = nameProvider.getFullyQualifiedName(ele);
			name = qn == null ? null : qn.toString();
		} catch (final IllegalArgumentException e) {
			name = null;
		}

	}
	return "Attribute " + (name == null ? "" : name)
			+ (type == null ? "" : " (" + type + ") " + (key == null ? "" : "(" + key + ") "));

}
 
Example 7
Source File: QIDValueConverter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String toString(String value) throws ValueConverterException {
	QualifiedName name = converter.toQualifiedName(value);
	QualifiedName result = QualifiedName.EMPTY;
	for (String str : name.getSegments()) {
		result = result.append(converterService.toString(str, "ID"));
	}
	return result.toString();
}
 
Example 8
Source File: QIDValueConverter.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String toValue(String string, INode node)
		throws ValueConverterException {
	QualifiedName name = converter.toQualifiedName(string);
	QualifiedName result = QualifiedName.EMPTY;
	for (String str : name.getSegments()) {
		result = result.append((String)converterService.toValue(str, "ID", node));
	}
	return result.toString();
}
 
Example 9
Source File: RecordingTypeScope.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	importedNames.add(name.toLowerCase());
	IEObjectDescription element = typeScope.getSingleElement(name);
	if (element == null) {
		ClassNameVariants nameVariants = new ClassNameVariants(name.toString());
		while (nameVariants.hasNext()) {
			String nextVariant = nameVariants.next();
			importedNames.add(getQualifiedNameConverter().toQualifiedName(nextVariant).toLowerCase());
		}
	}
	return element;
}
 
Example 10
Source File: RecordingTypeScope.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name, boolean binary) {
	importedNames.add(name.toLowerCase());
	IEObjectDescription element = typeScope.getSingleElement(name, binary);
	if (element == null) {
		ClassNameVariants nameVariants = new ClassNameVariants(name.toString());
		while (nameVariants.hasNext()) {
			String nextVariant = nameVariants.next();
			importedNames.add(getQualifiedNameConverter().toQualifiedName(nextVariant).toLowerCase());
		}
	}
	return element;
}
 
Example 11
Source File: ImportedNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNestedTypesIncludedOnUnresolvedFeatures_02() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.Unknown");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
    final Iterable<QualifiedName> importedNames = description.getImportedNames();
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
      String _string = it.toString();
      String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$Unknown".toLowerCase();
      return Boolean.valueOf(Objects.equal(_string, _lowerCase));
    };
    Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 12
Source File: ImportedNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNestedTypesIncludedOnUnresolvedFeatures() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val foo = types.StaticOuterClass.Unknown.StaticInnerClass.CONSTANT");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
    final Iterable<QualifiedName> importedNames = description.getImportedNames();
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
      String _string = it.toString();
      String _lowerCase = "types.StaticOuterClass$Unknown".toLowerCase();
      return Boolean.valueOf(Objects.equal(_string, _lowerCase));
    };
    Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 13
Source File: ImportedNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNestedTypesIncluded() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.StaticInnerClass.CONSTANT");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.file(_builder.toString());
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource());
    final Iterable<QualifiedName> importedNames = description.getImportedNames();
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
      String _string = it.toString();
      String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$StaticInnerClass".toLowerCase();
      return Boolean.valueOf(Objects.equal(_string, _lowerCase));
    };
    Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 14
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
	if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
		if ("true".equals(description.getUserData("nsURI"))) {
			String name = description.getUserData("name");
			if (name == null) {
				return new StyledString(description.getName().toString());
			}
			String string = name + " - " + description.getName();
			return new StyledString(string);
		}
	} else if(XtextPackage.Literals.GRAMMAR == description.getEClass()){
		QualifiedName qualifiedName = description.getQualifiedName();
		if(qualifiedName.getSegmentCount() >1) {
			return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
		}
		return new StyledString(qualifiedName.toString());
	} else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
		EObject object = description.getEObjectOrProxy();
		if (!object.eIsProxy()) {
			AbstractRule rule = (AbstractRule) object;
			Grammar grammar = GrammarUtil.getGrammar(rule);
			if (description instanceof EnclosingGrammarAwareDescription) {
				if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
					return getStyledDisplayString(rule, null, rule.getName());
				}
			}
			return getStyledDisplayString(rule,
					grammar.getName() + "." + rule.getName(),
					description.getName().toString().replace(".", "::"));	
		}
		
	}
	return super.getStyledDisplayString(description);
}
 
Example 15
Source File: PolyFilledProvision.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param qualifiedName
 *            with {@code #POLY}-marker to be converted to a String without the polyfill-marker.
 * @return string representation without polyfill marker
 */
public static String withoutPolyfillAsString(QualifiedName qualifiedName) {
	// Assumption: 2nd-last segment is "!POLY"
	String last = qualifiedName.getLastSegment();
	String poly = qualifiedName.skipLast(1).getLastSegment();
	assert (N4TSQualifiedNameProvider.POLYFILL_SEGMENT.equals(poly));
	QualifiedName ret = qualifiedName.skipLast(2).append(last);
	return ret.toString();
}
 
Example 16
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String getSymbolName(QualifiedName qualifiedName) {
	if (qualifiedName != null) {
		return qualifiedName.toString();
	}
	return null;
}
 
Example 17
Source File: DocumentSymbolMapper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String getName(QualifiedName qualifiedName) {
	if (qualifiedName != null) {
		return qualifiedName.toString();
	}
	return null;
}
 
Example 18
Source File: XbaseReferenceUpdater.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected String getLinkText(QualifiedName importRelativeName, String newReferenceText) {
	if(newReferenceText.endsWith("::")) 
		return importRelativeName.toString("::") + "::";
	else 
		return importRelativeName.toString(".");
}
 
Example 19
Source File: ProcQualifiedNameConverter.java    From bonita-studio with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Converts the given qualified name to a string.
 * 
 * @exception IllegalArgumentException
 *                when the qualified name is null.
 */
public String toString(QualifiedName qualifiedName) {
	if (qualifiedName == null)
		throw new IllegalArgumentException("Qualified name cannot be null");
	return qualifiedName.toString(getDelimiter());
}