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

The following examples show how to use org.eclipse.xtext.naming.QualifiedName#append() . These examples are extracted from open source projects. 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
@Test public void testDeresolve_ImportNormalizer() throws Exception {
	QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
	QualifiedName xtextFQN = namespace.append("Xtext$Xtext");
	QualifiedName ytextFQN = namespace.skipLast(1).append("ytext");
	QualifiedName xytextFQN = namespace.append("ytext$ytext");

	ImportNormalizer importNormalizer = createImportNormalizer(xtextFQN, false);
	assertEquals(QualifiedName.create("Xtext"), importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(null, importNormalizer.deresolve(xytextFQN));
	
	importNormalizer = createImportNormalizer(xytextFQN, false);
	assertEquals(null, importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), importNormalizer.deresolve(xytextFQN));

	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(xtextFQN, true);
	assertEquals(null, wildcardImportNormalizer.deresolve(xtextFQN));
	assertEquals(null, wildcardImportNormalizer.deresolve(ytextFQN));
	assertEquals(null, wildcardImportNormalizer.deresolve(xytextFQN));
}
 
Example 2
@Test public void testDeresolve_ImportNormalizer() throws Exception {
	QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
	QualifiedName xtextFQN = namespace.append("Xtext");
	QualifiedName ytextFQN = namespace.skipLast(1).append("ytext");
	QualifiedName xytextFQN = namespace.append("ytext");

	ImportNormalizer importNormalizer = createImportNormalizer(xtextFQN, false);
	assertEquals(QualifiedName.create("Xtext"), importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(null, importNormalizer.deresolve(xytextFQN));
	
	importNormalizer = createImportNormalizer(xytextFQN, false);
	assertEquals(null, importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), importNormalizer.deresolve(xytextFQN));

	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(namespace, true);
	assertEquals(QualifiedName.create("Xtext"), wildcardImportNormalizer.deresolve(xtextFQN));
	assertEquals(null, wildcardImportNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), wildcardImportNormalizer.deresolve(xytextFQN));
}
 
Example 3
@Test public void testDeresolve() throws Exception {
	QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
	QualifiedName xtextFQN = namespace.append("Xtext");
	QualifiedName ytextFQN = namespace.skipLast(1).append("ytext");
	QualifiedName xytextFQN = namespace.append("ytext");

	ImportNormalizer importNormalizer = new ImportNormalizer(xtextFQN, false, false);
	assertEquals(QualifiedName.create("Xtext"), importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(null, importNormalizer.deresolve(xytextFQN));
	
	importNormalizer = new ImportNormalizer(xytextFQN, false, false);
	assertEquals(null, importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), importNormalizer.deresolve(xytextFQN));

	ImportNormalizer wildCardImportNormalizer = new ImportNormalizer(namespace, true, false);
	assertEquals(QualifiedName.create("Xtext"), wildCardImportNormalizer.deresolve(xtextFQN));
	assertEquals(null, wildCardImportNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), wildCardImportNormalizer.deresolve(xytextFQN));
}
 
Example 4
@Test public void testDeresolveIgnoreCase() throws Exception {
	QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
	QualifiedName xtextFQN = namespace.append("Xtext");
	QualifiedName ytextFQN = namespace.skipLast(1).append("ytext");
	QualifiedName xytextFQN = namespace.append("ytext");

	ImportNormalizer importNormalizer = new ImportNormalizer(xtextFQN.toUpperCase(), false, true);
	assertEquals(QualifiedName.create("Xtext"), importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(null, importNormalizer.deresolve(xytextFQN));
	
	importNormalizer = new ImportNormalizer(xytextFQN.toUpperCase(), false, true);
	assertEquals(null, importNormalizer.deresolve(xtextFQN));
	assertEquals(null, importNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), importNormalizer.deresolve(xytextFQN));

	ImportNormalizer wildCardImportNormalizer = new ImportNormalizer(namespace.toUpperCase(), true, true);
	assertEquals(QualifiedName.create("Xtext"), wildCardImportNormalizer.deresolve(xtextFQN));
	assertEquals(null, wildCardImportNormalizer.deresolve(ytextFQN));
	assertEquals(QualifiedName.create("ytext"), wildCardImportNormalizer.deresolve(xytextFQN));
}
 
Example 5
public QualifiedName qualifiedName(Event ele) {
	QualifiedName name = null;
	if (!Strings.isEmpty(ele.getName())) {
		name = nameConverter.toQualifiedName(ele.getName());
	}
	InterfaceScope scope = EcoreUtil2.getContainerOfType(ele,
			InterfaceScope.class);
	if (scope != null) {
		if (!Strings.isEmpty(scope.getName())) {
			QualifiedName namespace = nameConverter.toQualifiedName(scope
					.getName());
			name = namespace.append(name);
		}

	}
	return name;
}
 
Example 6
public QualifiedName qualifiedName(Property ele) {
	QualifiedName name = null;
	if (!Strings.isEmpty(ele.getName())) {
		name = nameConverter.toQualifiedName(ele.getName());
	}
	InterfaceScope scope = EcoreUtil2.getContainerOfType(ele,
			InterfaceScope.class);
	if (scope != null) {
		if (!Strings.isEmpty(scope.getName())) {
			QualifiedName namespace = nameConverter.toQualifiedName(scope
					.getName());
			name = namespace.append(name);
		}

	}
	return name;
}
 
Example 7
@Override
public ImageDescriptor getImageDescriptor(ITypeInfoRequestor typeInfoRequestor) {
	QualifiedName qualifiedName;
	final String enclosing = typeInfoRequestor.getEnclosingName();
	if (Strings.isEmpty(enclosing)) {
		final String packageName = typeInfoRequestor.getPackageName();
		if (Strings.isEmpty(packageName)) {
			qualifiedName = null;
		} else {
			qualifiedName = this.converter.toQualifiedName(packageName);
		}
	} else {
		qualifiedName = this.converter.toQualifiedName(enclosing);
	}
	final QualifiedName qn = this.converter.toQualifiedName(typeInfoRequestor.getTypeName());
	if (qualifiedName == null) {
		qualifiedName = qn;
	} else {
		qualifiedName = qualifiedName.append(qn);
	}
	return this.imageProvider.getImageDescriptorForQualifiedName(qualifiedName, this.typeProvider.getResourceSet(),
			this.typeProvider);
}
 
Example 8
/**
 * Null-safe appending of segments. If segment is null, null is returned. If prefix is null, a new qualified name
 * (with non-null segment) is created.
 */
protected static QualifiedName append(QualifiedName prefix, String segment) {
	if (segment == null) {
		return null;
	}
	if (prefix == null) {
		return QualifiedName.create(segment);
	}
	return prefix.append(segment);
}
 
Example 9
/**
 * Prefixing a qualified name. If the prefix segment is null, the suffix is returned, else if the suffix is null a
 * QN with only one segment is returned. Otherwise segment gets prefixed to suffix.
 */
protected static QualifiedName prepend(String segment, QualifiedName suffix) {
	if (segment == null) {
		return suffix;
	}
	QualifiedName qn = QualifiedName.create(segment);
	if (suffix != null) {
		qn = qn.append(suffix);
	}
	return qn;
}
 
Example 10
private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	String alias = declaration.getAlias();
	QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias,
			grammarAccess.getValidIDRule().getName())) : null;
	boolean createDatatypeProposals = !(model instanceof AbstractElement)
			&& modelOrContainerIs(model, AbstractRule.class);
	boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class);
	boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class);
	Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter);
	for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) {
		if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum
				&& createEnumProposals || classifier instanceof EClass && createClassProposals) {
			String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName());
			QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName
					.create(classifierName);
			IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier);
			ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
			if (proposal != null) {
				if (prefix != null)
					proposal.setDisplayString(classifier.getName() + " - " + alias);
				proposal.setPriority(proposal.getPriority() * 2);
			}
			acceptor.accept(proposal);
		}
	}
}
 
Example 11
protected QualifiedName concatNames(EObject obj, String name) {
	if (name == null)
		return null;
	QualifiedName parentName = getFullyQualifiedName(obj.eContainer());
	if (parentName == null)
		return null;
	return parentName.append(name);
}
 
Example 12
public QualifiedName qualifiedName(InterfaceScope ele) {
	QualifiedName name = null;
	if (!Strings.isEmpty(ele.getName())) {
		name = nameConverter.toQualifiedName(ele.getName());
	}
	QualifiedName namespace = getNamespace(ele);
	if (namespace != null && name != null) {
		name = namespace.append(name);
	}
	return name;
}
 
Example 13
protected QualifiedName getParentQualifiedName(final EObject ele,
		final QualifiedName childName) {
	EObject temp = ele;
	while (temp.eContainer() != null) {
		temp = temp.eContainer();
		QualifiedName parentsQualifiedName = getFullyQualifiedName(temp);
		if (parentsQualifiedName != null)
			return parentsQualifiedName.append(childName);
	}
	return childName;
}
 
Example 14
public QualifiedName qualifiedName(Scope ele) {
	QualifiedName name = null;
	String nameString = SimpleAttributeResolver.NAME_RESOLVER.apply(ele);
	if (!Strings.isEmpty(nameString)) {
		name = nameConverter.toQualifiedName(nameString);
	}

	QualifiedName namespace = getNamespace(ele);
	if (namespace != null && name != null) {
		name = namespace.append(name);
	}
	return name;
}
 
Example 15
public QualifiedName qualifiedName(Declaration ele) {
	QualifiedName name = null;
	QualifiedName namespace = getNamespace(ele);
	if (!Strings.isEmpty(ele.getName())) {
		name = nameConverter.toQualifiedName(ele.getName());
	}
	if (namespace != null && name != null) {
		return namespace.append(name);
	}
	if (namespace == null && name != null && ele instanceof ComplexType) {
		return getParentQualifiedName(ele, name);
	}
	return name;
}
 
Example 16
@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 17
@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 18
/**
 * Gets the ID for the extension to be created in the {@code plugin.xml} file. The extension consists
 * of catalog package as a prefix and ends with the name of the catalog, all in lower case
 * letters. This means that multiple resources with equal name may exist, but only when not in the same
 * package. Another consequence is that name comparison of resources is case <em>insensitive</em>.
 * <p>
 * Note that every extension point supported has unique extension IDs. The following rules apply:
 * <ul>
 * <li>extensions for the validator point have a ".validator" suffix
 * <li>extensions for the quickfix point have a ".quickfix" suffix
 * <li>extensions for the preference initializer point have a ".preference" suffix
 * </ul>
 * If this operation is called using {@link ExtensionType#ALL}, an ID without this last segment consisting of "." followed by the suffix is returned. Note
 * also that {@link #findExtensions(IPluginModelBase, String, ExtensionType)} with {@link ExtensionType#ALL} matches all extensions for a given catalog.
 * </p>
 * <p>
 * Returns {@code null} if none could be determined.
 * </p>
 *
 * @param catalogName
 *          qualified check catalog name
 * @param typeId
 *          the type id
 * @return the extension ID for current Catalog or {@code null}
 */
private String getExtensionId(final QualifiedName catalogName, final ExtensionType typeId) {
  QualifiedName result = catalogName;
  switch (typeId) {
  case VALIDATOR:
    result = catalogName.append("validator");
    break;
  case QUICKFIX:
    result = catalogName.append("quickfix");
    break;
  case PREFERENCE_INITIALIZER:
    result = catalogName.append("preference");
    break;
  case TOC:
    return null; // no ID
  case CONTEXTS:
    return null; // no ID
  case MARKERHELP:
    return null; // no ID
  default: // ALL
    break;
  }
  return result.toString().toLowerCase();
}
 
Example 19
/**
 * Qualifies a simple name with that of the container (if any).
 *
 * @param obj
 *          context object
 * @param name
 *          simple name of object
 * @return qualified name of object
 */
protected QualifiedName qualifyWithContainerName(final EObject obj, final QualifiedName name) {
  final QualifiedName parentName = getContainerQualifiedName(obj);
  if (parentName != null && !parentName.isEmpty()) {
    return parentName.append(name);
  }
  return name;
}