org.eclipse.xtext.scoping.impl.ImportNormalizer Java Examples

The following examples show how to use org.eclipse.xtext.scoping.impl.ImportNormalizer. 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: ImportNormalizerTest.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 = new ImportNormalizer(namespace, false, false);
	assertEquals(namespace, importNormalizer.resolve(xtextRelativeName));
	assertEquals(null, importNormalizer.resolve(ytextRelativeName));
	assertEquals(null, importNormalizer.resolve(xytextRelativeName));
	assertEquals(null, importNormalizer.resolve(xytextRelativeNameWithDollar));
	
	ImportNormalizer wildcardImportNormalizer = new ImportNormalizer(namespace, true, false);
	assertEquals(namespace.append(xtextRelativeName), wildcardImportNormalizer.resolve(xtextRelativeName));
	assertEquals(namespace.append(ytextRelativeName), wildcardImportNormalizer.resolve(ytextRelativeName));
	assertEquals(namespace.append(xytextRelativeName), wildcardImportNormalizer.resolve(xytextRelativeName));
	assertEquals(namespace.append(xytextRelativeNameWithDollar), wildcardImportNormalizer.resolve(xytextRelativeNameWithDollar));

	ImportNormalizer xtextImportNormalizer = new ImportNormalizer(xtextRelativeName, false, false);
	assertEquals(xtextRelativeName, xtextImportNormalizer.resolve(xtextRelativeName));
}
 
Example #2
Source File: TypeScopeWithWildcardImports.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
	for(int i = 0; i < imports.length; i++) {
		ImportNormalizer[] chunk = imports[i];
		IEObjectDescription result = null;
		for(int j = 0; j < chunk.length; j++) {
			ImportNormalizer normalizer = chunk[j];
			QualifiedName resolvedName = normalizer.resolve(name);
			if (resolvedName != null) {
				IEObjectDescription candidate = typeScope.getSingleElement(resolvedName, true);
				if (candidate != null) {
					if (result == null) {
						result = candidate;
					} else {
						return null;
					}
				}
			}
		}
		if (result != null) {
			return result;
		}
	}
	return getSingleElementFromParent(name);
}
 
Example #3
Source File: SolidityImportedNamespaceAwareLocalScopeProvider.java    From solidity-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected List<ImportNormalizer> getSuperTypeImports(Resource res, EReference reference) {
	List<ImportNormalizer> result = Lists.newArrayList();
	TreeIterator<EObject> allContents = res.getAllContents();
	while (allContents.hasNext()) {
		EObject next = allContents.next();
		if (next instanceof ContractDefinition) {
			ContractDefinition contract = (ContractDefinition) next;
			EList<TypeSpecifier> superTypes = contract.getSuperTypes();
			for (TypeSpecifier superType : superTypes) {
				ImportNormalizer resolver = createImportedNamespaceResolver(superType.getType().getName() + ".*", false);
				result.add(resolver);
			}
			allContents.prune();
		}
	}
	return result;
}
 
Example #4
Source File: NestedTypeAwareImportNormalizerWIthInvalidConfigTest.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(xytextRelativeNameWithDollar), importNormalizer.resolve(xytextRelativeName));
	assertEquals(namespace.skipLast(1).append(xytextRelativeNameWithDollar), 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 #5
Source File: NestedTypeAwareImportNormalizerWIthInvalidConfigTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeesolve_NestedTypes() throws Exception {
	QualifiedName mapEntry = QualifiedName.create("Map$Entry");
	QualifiedName imported = QualifiedName.create("java", "util", "Map");
	QualifiedName fqnMapEntry = QualifiedName.create("java", "util", "Map$Entry");
	QualifiedName fqnMaps = QualifiedName.create("java", "util", "Maps");
	QualifiedName fqnMapsInternal = QualifiedName.create("java", "util", "Maps$Internal");

	ImportNormalizer importNormalizer = createImportNormalizer(imported, false);
	assertEquals(mapEntry, importNormalizer.deresolve(fqnMapEntry));
	assertEquals(null, importNormalizer.deresolve(fqnMaps));
	assertEquals(null, importNormalizer.deresolve(fqnMapsInternal));
	
	importNormalizer = createImportNormalizer(fqnMapEntry, false);
	assertEquals(QualifiedName.create("Entry"), importNormalizer.deresolve(fqnMapEntry));
	assertEquals(QualifiedName.create("Entry$Nested"), importNormalizer.deresolve(QualifiedName.create("java", "util", "Map$Entry$Nested")));

	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(QualifiedName.create("java", "util"), true);
	assertEquals(QualifiedName.create("Map$Entry"), wildcardImportNormalizer.deresolve(fqnMapEntry));
}
 
Example #6
Source File: NestedTypeAwareImportNormalizerWIthInvalidConfigTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #7
Source File: XbaseImportedNamespaceScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a new {@link ImportNormalizer} for the given namespace.
 * @param namespace the namespace.
 * @param ignoreCase <code>true</code> if the resolver should be case insensitive.
 * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid
 * qualified name.
 */
protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) {
	if (Strings.isEmpty(namespace))
		return null;
	QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
	if (importedNamespace == null || importedNamespace.isEmpty()) {
		return null;
	}
	boolean hasWildCard = ignoreCase ? 
			importedNamespace.getLastSegment().equalsIgnoreCase(getWildCard()) :
			importedNamespace.getLastSegment().equals(getWildCard());
	if (hasWildCard) {
		if (importedNamespace.getSegmentCount() <= 1)
			return null;
		return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase);
	} else {
		return doCreateImportNormalizer(importedNamespace, false, ignoreCase);
	}
}
 
Example #8
Source File: NestedTypeAwareImportNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@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 #9
Source File: XImportSectionNamespaceScopeProvider.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create a new {@link ImportNormalizer} for the given namespace.
 * @param namespace the namespace.
 * @param ignoreCase <code>true</code> if the resolver should be case insensitive.
 * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid
 * qualified name.
 */
protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) {
	if (Strings.isEmpty(namespace))
		return null;
	QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
	if (importedNamespace == null || importedNamespace.isEmpty()) {
		return null;
	}
	boolean hasWildcard = ignoreCase ? 
			importedNamespace.getLastSegment().equalsIgnoreCase(getWildcard()) :
			importedNamespace.getLastSegment().equals(getWildcard());
	if (hasWildcard) {
		if (importedNamespace.getSegmentCount() <= 1)
			return null;
		return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase);
	} else {
		return doCreateImportNormalizer(importedNamespace, false, ignoreCase);
	}
}
 
Example #10
Source File: NestedTypeAwareImportNormalizerTest.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("eclipse$xtext$ytext"), importNormalizer.resolve(xytextRelativeName));
	assertEquals(namespace.skipLast(1).append("eclipse$xtext$ytext"), importNormalizer.resolve(xytextRelativeNameWithDollar));
	
	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(namespace, true);
	assertEquals(null, wildcardImportNormalizer.resolve(xtextRelativeName));
	assertEquals(null, wildcardImportNormalizer.resolve(ytextRelativeName));
	assertEquals(null, wildcardImportNormalizer.resolve(xytextRelativeName));
	assertEquals(null, wildcardImportNormalizer.resolve(xytextRelativeNameWithDollar));

	ImportNormalizer xytextRelativeNameWithDollarNormalizer = createImportNormalizer(xytextRelativeNameWithDollar, false);
	assertEquals(xytextRelativeNameWithDollar, xytextRelativeNameWithDollarNormalizer.resolve(xytextRelativeNameWithDollar));
}
 
Example #11
Source File: NestedTypeAwareImportNormalizerWithDotSeparatorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeesolve_NestedTypes() throws Exception {
	QualifiedName mapEntry = QualifiedName.create("Map", "Entry");
	QualifiedName imported = QualifiedName.create("java", "util", "Map");
	QualifiedName fqnMapEntry = QualifiedName.create("java", "util", "Map", "Entry");
	QualifiedName fqnMaps = QualifiedName.create("java", "util", "Maps");
	QualifiedName fqnMapsInternal = QualifiedName.create("java", "util", "Maps", "Internal");

	ImportNormalizer importNormalizer = createImportNormalizer(imported, false);
	assertEquals(mapEntry, importNormalizer.deresolve(fqnMapEntry));
	assertEquals(null, importNormalizer.deresolve(fqnMaps));
	assertEquals(null, importNormalizer.deresolve(fqnMapsInternal));
	
	importNormalizer = createImportNormalizer(fqnMapEntry, false);
	assertEquals(QualifiedName.create("Entry"), importNormalizer.deresolve(fqnMapEntry));
	assertEquals(QualifiedName.create("Entry", "Nested"), importNormalizer.deresolve(QualifiedName.create("java", "util", "Map$Entry$Nested")));

	ImportNormalizer wildcardImportNormalizer = createImportNormalizer(QualifiedName.create("java", "util"), true);
	assertEquals(QualifiedName.create("Map", "Entry"), wildcardImportNormalizer.deresolve(fqnMapEntry));
}
 
Example #12
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 #13
Source File: FileAwareTestLanguageImportScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) {
	List<ImportNormalizer> resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase);
	if (context instanceof PackageDeclaration) {
		resolvers.add(new ImportNormalizer(getQualifiedNameConverter().toQualifiedName(((PackageDeclaration) context).getName()), true, false));
		for (Import imp : ((PackageDeclaration) context).getImports()) {
			QualifiedName name = getImportedNamespace(imp);
			resolvers.add(new ImportNormalizer(name, false, false));
		}
	}
	return resolvers;
}
 
Example #14
Source File: NestedTypeAwareImportNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testDeesolve_NestedTypes() throws Exception {
	QualifiedName imported = QualifiedName.create("java", "util", "Map$Entry");
	QualifiedName fqnMapEntry = QualifiedName.create("java", "util", "Map$Entry");
	QualifiedName fqnMaps = QualifiedName.create("java", "util", "Maps");
	QualifiedName fqnMapsInternal = QualifiedName.create("java", "util", "Maps$Internal");

	ImportNormalizer importNormalizer = createImportNormalizer(imported, false);
	assertEquals(QualifiedName.create("Entry"), importNormalizer.deresolve(fqnMapEntry));
	assertEquals(null, importNormalizer.deresolve(fqnMaps));
	assertEquals(null, importNormalizer.deresolve(fqnMapsInternal));
	
	importNormalizer = createImportNormalizer(fqnMapEntry, false);
	assertEquals(QualifiedName.create("Entry"), importNormalizer.deresolve(fqnMapEntry));
	assertEquals(QualifiedName.create("Entry$Nested"), importNormalizer.deresolve(QualifiedName.create("java", "util", "Map$Entry$Nested")));
}
 
Example #15
Source File: XtendImportedNamespaceScopeProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private AbstractScope getImportScope(List<ImportNormalizer> wildcardImports, List<JvmType> concreteImports, List<QualifiedName> importedNames,
		AbstractScope parent, RecordingTypeScope typeScope) {
	AbstractScope result = parent;
	if (wildcardImports != null) {
		result = new TypeScopeWithWildcardImports(wildcardImports, typeScope, result);
	}
	if (concreteImports != null) {
		if (importedNames != null)
			result = new LegacyKnownTypesScope(concreteImports, importedNames, result);
		else
			result = new KnownTypesScope(concreteImports, result);
	}
	return result;
}
 
Example #16
Source File: TypeScopeWithWildcardImports.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
	if (!(type instanceof JvmDeclaredType)) {
		return;
	}
	JvmDeclaredType declaredType = (JvmDeclaredType) type;
	String packageName = declaredType.getPackageName();
	if (!Strings.isEmpty(packageName)) {
		QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
		QualifiedName withDot = null;
		String withDollar = null; 
		for(int i = 0; i < imports.length; i++) {
			ImportNormalizer[] chunk = imports[i];
			for(int j = 0; j < chunk.length; j++) {
				ImportNormalizer normalizer = chunk[j];
				QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
				if (namespacePrefix.equals(qualifiedPackageName)) {
					if (withDot == null) {
						withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
						withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
					}
					result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
					if (withDollar != null) {
						result.add(EObjectDescription.create(withDollar, type));	
					}
				}
			}
		}
	}
	if (parent != null) {
		parent.doGetElements(type, result);
	} else {
		Iterables.addAll(result, typeScope.getElements(type));
	}
}
 
Example #17
Source File: ImportWithDollarDefaultNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test
public void testMap$Entry_Entry_01() {
	QualifiedName map$entry = createMapEntryImport();
	ImportNormalizer normalizer = createImportNormalizer(map$entry, false);
	QualifiedName relative = QualifiedName.create("Entry");
	assertNull(normalizer.resolve(relative));
}
 
Example #18
Source File: AbstractImportNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMap$Entry_Entry_01() {
	QualifiedName map$entry = createMapEntryImport();
	ImportNormalizer normalizer = createImportNormalizer(map$entry, false);
	QualifiedName relative = QualifiedName.create("Entry");
	doTestMap$Entry_Entry(normalizer.resolve(relative));
}
 
Example #19
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 #20
Source File: XtendImportedNamespaceScopeProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected AbstractScope getRootTypeScope(XtendFile rootContainer, RecordingTypeScope typeScope) {
	String packageName = rootContainer.getPackage();
	final ImportNormalizer[][] implicitImports;
	if (packageName != null && packageName.length() > 0) {
		QualifiedName packageQualifiedName = qualifiedNameConverter.toQualifiedName(packageName);
		implicitImports = new ImportNormalizer[][] {
			{
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(packageQualifiedName, true, false),
			},
			{
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(JAVA_LANG, true, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(XBASE_LIB, true, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(OLD_DATA_ANNOTATION, false, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(OLD_PROPERTY_ANNOTATION, false, false),
			}
		};
	} else {
		implicitImports = new ImportNormalizer[][] {
			{
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(JAVA_LANG, true, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(XBASE_LIB, true, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(OLD_DATA_ANNOTATION, false, false),
				AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(OLD_PROPERTY_ANNOTATION, false, false),
			}
		};
	}
	return new TypeScopeWithWildcardImports(implicitImports, typeScope);
}
 
Example #21
Source File: ImportWithDollarDefaultNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Test
public void testMap$Entry_Map$Entry_01() {
	QualifiedName map$entry = createMapEntryImport();
	ImportNormalizer normalizer = createImportNormalizer(map$entry, false);
	QualifiedName relative = QualifiedName.create("Map$Entry");
	assertEquals(map$entry, normalizer.resolve(relative));
}
 
Example #22
Source File: ScriptImportSectionNamespaceScopeProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
    List<ImportNormalizer> implicitImports = super.getImplicitImports(ignoreCase);
    implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_UNITS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_TYPES_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_ITEMS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_ITEMS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_PERSISTENCE_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(MODEL_SCRIPT_ACTIONS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(TIME_PACKAGE, true, false));
    return implicitImports;
}
 
Example #23
Source File: StextImportAwareScopeProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, boolean ignoreCase) {
	List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList();
	List<ImportScope> importScopes = null;
	if (context instanceof StateSpecification || context instanceof TransitionSpecification) {
		importScopes = EcoreUtil2.getAllContentsOfType(utils.getStatechart(context), ImportScope.class);
	} else {
		importScopes = EcoreUtil2.getAllContentsOfType(context, ImportScope.class);
	}
	for (ImportScope scope : importScopes) {
		importedNamespaceResolvers.addAll(createNamespaceResolver(scope, ignoreCase));
	}
	return importedNamespaceResolvers;
}
 
Example #24
Source File: NestedTypeAwareImportNormalizerWithDotSeparatorTest.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));
}
 
Example #25
Source File: StextImportAwareScopeProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<ImportNormalizer> createNamespaceResolver(Scope scope, boolean ignoreCase) {
	List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList();
	ImportScope importScope = (ImportScope) scope;
	for (String child : importScope.getImports()) {
		Optional<PackageImport> pkgImport = mapper.findPackageImport(scope.eResource(), child);
		if (pkgImport.isPresent()) {
			ImportNormalizer resolver = createImportedNamespaceResolver(pkgImport.get().getNamespace(), ignoreCase);
			if (resolver != null)
				importedNamespaceResolvers.add(resolver);
		}
	}
	return importedNamespaceResolvers;
}
 
Example #26
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_02() {
	QualifiedName map$entry = createMapEntryImport();
	ImportNormalizer normalizer = createImportNormalizer(map$entry, false);
	QualifiedName relative = QualifiedName.create("Map", "Entry");
	doTestMap$Entry_Map$Entry(normalizer.resolve(relative));
}
 
Example #27
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 #28
Source File: AbstractImportNormalizerTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMap_Map$Entry() {
	QualifiedName map = QualifiedName.create("java", "util", "Map");
	ImportNormalizer normalizer = createImportNormalizer(map, false);
	QualifiedName map$entry = QualifiedName.create("Map$Entry");
	doTestMap_Map$Entry(normalizer.resolve(map$entry));
}
 
Example #29
Source File: ScriptImportSectionNamespaceScopeProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) {
    List<ImportNormalizer> implicitImports = super.getImplicitImports(ignoreCase);
    implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_TYPES_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_LIBRARY_ITEMS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_ITEMS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(CORE_PERSISTENCE_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(MODEL_SCRIPT_ACTIONS_PACKAGE, true, false));
    implicitImports.add(doCreateImportNormalizer(JODA_TIME_PACKAGE, true, false));
    return implicitImports;
}
 
Example #30
Source File: NestedTypeAwareImportNormalizerTest.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$Entry");
	QualifiedName expected = QualifiedName.create("java", "util", "Map$Entry");
	ImportNormalizer importNormalizer = createImportNormalizer(imported, false);
	assertEquals(imported, importNormalizer.resolve(mapEntry));
	assertEquals(null, 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(null, wildcardImportNormalizer.resolve(mapEntry));
	assertEquals(null, wildcardImportNormalizer.resolve(mapEntryWithDot));
	assertEquals(null, wildcardImportNormalizer.resolve(maps));
	assertEquals(null, wildcardImportNormalizer.resolve(mapsInternal));
	assertEquals(null, wildcardImportNormalizer.resolve(mapsInternalWithDot));
}