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

The following examples show how to use org.eclipse.xtext.naming.QualifiedName#create() . 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: ImportNormalizer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public QualifiedName deresolve(QualifiedName fullyQualifiedName) {
	if (hasWildCard) {
		if (!ignoreCase) {
			if (fullyQualifiedName.startsWith(importedNamespacePrefix) 
					&& fullyQualifiedName.getSegmentCount() != importedNamespacePrefix.getSegmentCount()) {
				return fullyQualifiedName.skipFirst(importedNamespacePrefix.getSegmentCount());
			}
		} else {
			if (fullyQualifiedName.startsWithIgnoreCase(importedNamespacePrefix) 
				&& fullyQualifiedName.getSegmentCount() != importedNamespacePrefix.getSegmentCount()) {
				return fullyQualifiedName.skipFirst(importedNamespacePrefix.getSegmentCount());
			}
		}
	} else {
		if (!ignoreCase) {
			if (fullyQualifiedName.equals(importedNamespacePrefix))
				return QualifiedName.create(fullyQualifiedName.getLastSegment());
		} else {
			if (fullyQualifiedName.equalsIgnoreCase(importedNamespacePrefix))
				return QualifiedName.create(fullyQualifiedName.getLastSegment());
		}
	}
	return null;
}
 
Example 2
Source File: NestedTypeAwareImportNormalizerWithDotSeparatorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testResolve_ImportNormalizer() throws Exception {
	QualifiedName xtextRelativeName = QualifiedName.create("xtext");
	QualifiedName ytextRelativeName = QualifiedName.create("ytext");
	QualifiedName xytextRelativeName = QualifiedName.create("xtext", "ytext");
	QualifiedName xytextRelativeNameWithDollar = QualifiedName.create("xtext$ytext");

	QualifiedName namespace = QualifiedName.create("org", "eclipse", "xtext");
	ImportNormalizer importNormalizer = createImportNormalizer(namespace, false);
	assertEquals(namespace, importNormalizer.resolve(xtextRelativeName));
	assertEquals(null, importNormalizer.resolve(ytextRelativeName));
	assertEquals(namespace.skipLast(1).append(xytextRelativeName), importNormalizer.resolve(xytextRelativeName));
	assertEquals(namespace.skipLast(1).append(xytextRelativeName), importNormalizer.resolve(xytextRelativeNameWithDollar));
	
	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(namespace, true);
	assertEquals(namespace.append(xtextRelativeName), wildcardImportNormalizer.resolve(xtextRelativeName));
	assertEquals(namespace.append(ytextRelativeName), wildcardImportNormalizer.resolve(ytextRelativeName));
	assertEquals(namespace.append(xytextRelativeNameWithDollar), wildcardImportNormalizer.resolve(xytextRelativeName));
	assertEquals(namespace.append(xytextRelativeNameWithDollar), wildcardImportNormalizer.resolve(xytextRelativeNameWithDollar));

	ImportNormalizer xtextImportNormalizer = createImportNormalizer(xtextRelativeName, false);
	assertEquals(xtextRelativeName, xtextImportNormalizer.resolve(xtextRelativeName));
}
 
Example 3
Source File: SARLValidator.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Check if the given action has a valid name.
 *
 * @param action the action to test.
 * @see SARLFeatureNameValidator
 */
@Check(CheckType.FAST)
public void checkActionName(SarlAction action) {
	final JvmOperation inferredOperation = this.associations.getDirectlyInferredOperation(action);
	final QualifiedName name = QualifiedName.create(inferredOperation.getQualifiedName('.').split("\\.")); //$NON-NLS-1$
	if (isReallyDisallowedName(name)) {
		final String validName = Utils.fixHiddenMember(action.getName());
		error(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				INVALID_MEMBER_NAME,
				validName);
	} else if (!isIgnored(DISCOURAGED_FUNCTION_NAME)
			&& this.featureNames_.isDiscouragedName(name)) {
		warning(MessageFormat.format(
				Messages.SARLValidator_39,
				action.getName()),
				action,
				XTEND_FUNCTION__NAME,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				DISCOURAGED_FUNCTION_NAME);
	}
}
 
Example 4
Source File: ReferenceResolutionFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/** In case of main module, adjust the qualified name, e.g. index.Element -> react.Element */
private QualifiedName getImportName() {
	QualifiedName qfn = candidate.getQualifiedName();
	int qfnSegmentCount = qfn.getSegmentCount();
	String tmodule = (qfnSegmentCount >= 2) ? qfn.getSegment(qfnSegmentCount - 2) : null;

	QualifiedName candidateName;
	if (candidateProject != null && tmodule != null && tmodule.equals(candidateProject.getMainModule())) {
		N4JSProjectName projectName = candidateProject.getProjectName();
		N4JSProjectName definesPackage = candidateProject.getDefinesPackageName();
		if (definesPackage != null) {
			projectName = definesPackage;
		}
		String lastSegmentOfQFN = candidate.getQualifiedName().getLastSegment().toString();
		candidateName = QualifiedName.create(projectName.getRawName(), lastSegmentOfQFN);
	} else {
		candidateName = candidate.getQualifiedName();
	}
	return candidateName;
}
 
Example 5
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMultipleElementsByName_01() throws Exception {
	final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EATTRIBUTE, null);
	SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), true);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("COM"), true, true);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("DE"), true, true);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, true);
	
	assertNotNull(scope.getSingleElement(QualifiedName.create("Foo")));
	Iterable<IEObjectDescription> elements = scope.getLocalElementsByName(QualifiedName.create("Foo"));
	assertEquals(2,size(elements));
}
 
Example 6
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetAllWithDuplicates() throws Exception {
	final IEObjectDescription desc1 = EObjectDescription.create(QualifiedName.create("com","foo","bar"), EcorePackage.Literals.EANNOTATION);
	final IEObjectDescription desc2 = EObjectDescription.create(QualifiedName.create("com","foo","bar"), EcorePackage.Literals.EATTRIBUTE);
	SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), false);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, false);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, false);
	assertEquals(4,size(scope.getAllElements()));
}
 
Example 7
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAllAliasedElements_04() throws Exception {
	final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("com","bar"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc3 = new EObjectDescription(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE, null);
	final ArrayList<IEObjectDescription> newArrayList = newArrayList(desc1,desc2,desc3);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, true);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de"), true, true);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), IScope.NULLSCOPE, null, EcorePackage.Literals.EOBJECT, true);
	Iterable<IEObjectDescription> elements = scope.getAliasedElements(newArrayList);
	assertEquals(1,size(elements));
	assertSame(desc2,((AliasedEObjectDescription)elements.iterator().next()).getAliasedEObjectDescription());
}
 
Example 8
Source File: SGraphNameProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public QualifiedName qualifiedName(Statechart ele) {
	String scName = ele.getName();
	if (Strings.isEmpty(scName)) {
		return null;
	}
	QualifiedName name = QualifiedName.create(identifierConverter
			.toIdentifier(ele.getName()));
	if (!Strings.isEmpty(ele.getNamespace())) {
		name = nameConverter.toQualifiedName(ele.getNamespace()).append(
				name);
	}
	return name;
}
 
Example 9
Source File: NestedTypeAwareImportNormalizerWIthInvalidConfigTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testResolve_NestedTypes() throws Exception {
	QualifiedName mapEntry = QualifiedName.create("Map$Entry");
	QualifiedName mapEntryWithDot = QualifiedName.create("Map", "Entry");
	QualifiedName maps = QualifiedName.create("Maps");
	QualifiedName mapsInternal = QualifiedName.create("Maps$Internal");
	QualifiedName mapsInternalWithDot = QualifiedName.create("Maps", "Internal");
	QualifiedName imported = QualifiedName.create("java", "util", "Map");
	QualifiedName expected = QualifiedName.create("java", "util", "Map$Entry");
	ImportNormalizer importNormalizer = createImportNormalizer(imported, false);
	assertEquals(expected, importNormalizer.resolve(mapEntry));
	assertEquals(expected, importNormalizer.resolve(mapEntryWithDot));
	assertEquals(null, importNormalizer.resolve(maps));
	assertEquals(null, importNormalizer.resolve(mapsInternal));
	assertEquals(null, importNormalizer.resolve(mapsInternalWithDot));
	
	importNormalizer = createImportNormalizer(expected, false);
	assertEquals(QualifiedName.create("java", "util", "Map$Entry$Internal"), importNormalizer.resolve(QualifiedName.create("Entry$Internal")));
	assertEquals(QualifiedName.create("java", "util", "Map$Entry$Internal"), importNormalizer.resolve(QualifiedName.create("Entry", "Internal")));
	assertEquals(null, importNormalizer.resolve(QualifiedName.create("Entry2$Internal")));
	assertEquals(null, importNormalizer.resolve(QualifiedName.create("Entry2", "Internal")));
	
	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(imported, true);
	assertEquals(imported.append(mapEntry), wildcardImportNormalizer.resolve(mapEntry));
	assertEquals(imported.append(mapEntry), wildcardImportNormalizer.resolve(mapEntryWithDot));
	assertEquals(imported.append(maps), wildcardImportNormalizer.resolve(maps));
	assertEquals(imported.append(mapsInternal), wildcardImportNormalizer.resolve(mapsInternal));
	assertEquals(imported.append(mapsInternal), wildcardImportNormalizer.resolve(mapsInternalWithDot));
	
	ImportNormalizer invalidWildcardImportNormalizer = createImportNormalizer(expected, true);
	assertEquals(null, invalidWildcardImportNormalizer.resolve(mapEntry));
	assertEquals(null, invalidWildcardImportNormalizer.resolve(mapEntryWithDot));
	assertEquals(null, invalidWildcardImportNormalizer.resolve(maps));
	assertEquals(null, invalidWildcardImportNormalizer.resolve(mapsInternal));
}
 
Example 10
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetAllLocalElements_00() throws Exception {
	final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EATTRIBUTE, null);
	SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), true);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, true);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de"), true, true);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, true);
	
	Iterable<IEObjectDescription> elements = scope.getAllLocalElements();
	assertEquals(2,size(elements));
}
 
Example 11
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testAllAliasedElements_03() throws Exception {
	final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE, null);
	final ArrayList<IEObjectDescription> newArrayList = newArrayList(desc1,desc2);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("COM"), true, true);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("DE"), true, true);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), IScope.NULLSCOPE, null, EcorePackage.Literals.EOBJECT, true);
	Iterable<IEObjectDescription> elements = scope.getAliasedElements(newArrayList);
	assertEquals(0,size(elements));
}
 
Example 12
Source File: AbstractScopeResourceDescriptionsTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertExportedObject(Resource resource, String name) {
	IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
	IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
	assertNotNull(resourceDescription);
	QualifiedName qname = QualifiedName.create(name);
	assertFalse(isEmpty(resourceDescription.getExportedObjects(EcorePackage.Literals.EOBJECT, qname, false)));
}
 
Example 13
Source File: CheckCfgScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public QualifiedName getFullyQualifiedName(final EObject obj) {
  if (obj instanceof Check) {
    String name = ((Check) obj).getName();
    if (name != null) {
      return QualifiedName.create(name);
    }
  } else if (obj instanceof FormalParameter) {
    return QualifiedName.create(((FormalParameter) obj).getName());
  }
  return null;
}
 
Example 14
Source File: SpecInfosByName.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private RepoRelativePath computeRRP(FullMemberReference ref, TMember testMember) {
	IScope scope = globalScopeProvider.getScope(testMember.eResource(),
			N4JSPackage.Literals.IMPORT_DECLARATION__MODULE);
	QualifiedName qn = QualifiedName.create(ref.getModuleName().split("/"));
	IEObjectDescription eod = scope.getSingleElement(qn);
	if (eod != null) {
		FileURI uri = new FileURI(eod.getEObjectURI());
		RepoRelativePath rrp = RepoRelativePath.compute(uri, n4jsCore);
		return rrp;
	} else {
		issueAcceptor.addWarning("Cannot resolve testee " + ref, testMember);
		return null;
	}

}
 
Example 15
Source File: IndexedJvmTypeAccess.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public EObject getIndexedJvmType(URI javaObjectURI, ResourceSet resourceSet, boolean throwShadowedException) throws UnknownNestedTypeException {
	if (resourceSet != null) {
		URI withoutFragment = javaObjectURI.trimFragment();
		if (resourceSet instanceof ResourceSetImpl) {
			// if the resource uri is already available in the resource set, try to find it directly
			Map<URI, Resource> resourceMap = ((ResourceSetImpl) resourceSet).getURIResourceMap();
			if (resourceMap != null && resourceMap.containsKey(withoutFragment)) {
				EObject result = resourceSet.getEObject(javaObjectURI, true);
				if (result != null) {
					return result;
				}
			}
		}
		String fqn = withoutFragment.segment(withoutFragment.segmentCount() - 1);
		final String base = fqn;
		Iterator<String> variants = innerClassNameVariants.variantsFor(base);
		EObject jvmType = null;
		while (jvmType == null && variants.hasNext()) {
			fqn = variants.next();
			List<String> fqnSegments = Strings.split(fqn, '.');
			QualifiedName qualifiedName = QualifiedName.create(fqnSegments);
			jvmType = getIndexedJvmType(qualifiedName, javaObjectURI.fragment(), resourceSet, throwShadowedException);
		}
		return jvmType;
	}
	return null;
}
 
Example 16
Source File: ImportScopeTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testDuplicatesNotVisible_03_IgnoreCase() throws Exception {
	final IEObjectDescription desc1 = new EObjectDescription(QualifiedName.create("com","foo"), EcorePackage.Literals.EANNOTATION, null);
	final IEObjectDescription desc2 = new EObjectDescription(QualifiedName.create("de","foo"), EcorePackage.Literals.EATTRIBUTE, null);
	SimpleScope outer = new SimpleScope(newArrayList(desc1,desc2), true);
	ImportNormalizer n1 = new ImportNormalizer(QualifiedName.create("com"), true, true);
	ImportNormalizer n2 = new ImportNormalizer(QualifiedName.create("de"), true, true);
	TestableImportScope scope = new TestableImportScope(newArrayList(n1,n2), outer, new ScopeBasedSelectable(outer), EcorePackage.Literals.EOBJECT, true);
	
	assertNull(scope.getSingleElement(QualifiedName.create("Foo")));
	assertNotNull(scope.getSingleElement(QualifiedName.create("com","Foo")));
	assertNotNull(scope.getSingleElement(QualifiedName.create("de","Foo")));
}
 
Example 17
Source File: AbstractImportNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMap$Entry_Map$Entry_01() {
	QualifiedName map$entry = createMapEntryImport();
	ImportNormalizer normalizer = createImportNormalizer(map$entry, false);
	QualifiedName relative = QualifiedName.create("Map$Entry");
	doTestMap$Entry_Map$Entry(normalizer.resolve(relative));
}
 
Example 18
Source File: WorkingCopyOwnerProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected QualifiedName toQualifiedName(String packageName, String typeName) {
	List<String> splitPackage = Strings.split(packageName, '.');
	splitPackage.add(typeName);
	QualifiedName qn = QualifiedName.create(splitPackage);
	return qn;
}
 
Example 19
Source File: ImportWithDotDefaultNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void testIgnoreCase() {
	// no exception expected
	new ImportNormalizer(QualifiedName.create("a"), false, true);
}
 
Example 20
Source File: ClasspathTypeDescriptor.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public QualifiedName getQualifiedName() {
	List<String> segments = ClasspathTypeDescriptor.PACKAGE_AND_NESTED_CLASS_SPLITTER.splitToList(name);
	return QualifiedName.create(segments);
}