protected IScope getResourceScope(Resource res, EReference reference) { if (reference == TypesPackage.Literals.COMPLEX_TYPE__SUPER_TYPES) return super.getResourceScope(res, reference); EObject context = res.getContents().get(0); IScope globalScope = getGlobalScope(res, reference); List<ImportNormalizer> normalizers = getSuperTypeImports(res, reference); if (!normalizers.isEmpty()) { globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference)); } return getResourceScope(globalScope, context, reference); }
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<ComplexType> superTypes = contract.getSuperTypes(); for (ComplexType complexType : superTypes) { // if (complexType.eIsProxy() || complexType.getName() == // null) // continue; ImportNormalizer resolver = createImportedNamespaceResolver(complexType.getName() + ".*", false); result.add(resolver); } allContents.prune(); } } return result; }
/** * 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); } }
/** * 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); } }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@Override protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, final boolean ignoreCase) { final List<ImportNormalizer> resolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase); if ((context instanceof PackageDeclaration)) { QualifiedName _qualifiedName = this.getQualifiedNameConverter().toQualifiedName(((PackageDeclaration)context).getName()); ImportNormalizer _importNormalizer = new ImportNormalizer(_qualifiedName, true, false); resolvers.add(_importNormalizer); EList<Import> _imports = ((PackageDeclaration)context).getImports(); for (final Import imp : _imports) { { final QualifiedName name = this.getImportedNamespace(imp); ImportNormalizer _importNormalizer_1 = new ImportNormalizer(name, false, false); resolvers.add(_importNormalizer_1); } } } return resolvers; }
@Override protected Iterable<IEObjectDescription> getAliasedElements(Iterable<IEObjectDescription> candidates) { Multimap<QualifiedName, IEObjectDescription> keyToDescription = LinkedHashMultimap.create(); Multimap<QualifiedName, ImportNormalizer> keyToNormalizer = HashMultimap.create(); for (IEObjectDescription imported : candidates) { QualifiedName fullyQualifiedName = imported.getName(); for (ImportNormalizer normalizer : normalizers) { QualifiedName alias = normalizer.deresolve(fullyQualifiedName); if (alias != null) { QualifiedName key = alias; if (isIgnoreCase()) { key = key.toLowerCase(); } keyToDescription.put(key, new AliasedEObjectDescription(alias, imported)); keyToNormalizer.put(key, normalizer); } } } return keyToDescription.values(); }
@Override protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) { List<IEObjectDescription> result = newArrayList(); ISelectable importFrom = getImportFrom(); for (ImportNormalizer normalizer : normalizers) { final QualifiedName resolvedName = normalizer.resolve(name); if (resolvedName != null) { Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(type, resolvedName, isIgnoreCase()); for (IEObjectDescription resolvedElement : resolvedElements) { QualifiedName alias = normalizer.deresolve(resolvedElement.getName()); if (alias == null) throw new IllegalStateException("Couldn't deresolve " + resolvedElement.getName() + " with import " + normalizer); final AliasedEObjectDescription aliasedEObjectDescription = new AliasedEObjectDescription(alias, resolvedElement); result.add(aliasedEObjectDescription); } } } return result; }
@SuppressWarnings("unchecked") private static List<ImportNormalizer> getNormalizers(IScope scope) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { assertNotNull(scope); assertThat(scope, is(instanceOf(ImportScope.class))); ImportScope importScope = (ImportScope) scope; Field normalizersField = scope.getClass().getDeclaredField("normalizers"); normalizersField.setAccessible(true); Object normalizers = normalizersField.get(importScope); assertThat(normalizers, is(instanceOf(List.class))); assertThat((List<?>) normalizers, everyItem(is(instanceOf(ImportNormalizer.class)))); return (List<ImportNormalizer>) normalizers; }
@Override protected IScope getResourceScope(Resource res, EReference reference) { EObject context = res.getContents().get(0); // ||-- changed super-impl here: // IDE-662 filtering ArgumentsType & EnumBaseType from globalScobe, since it is a VirtualBaseType. Predicate<IEObjectDescription> filter = p -> { String name = p.getName().toString(); return !("ArgumentsType".equals(name) || "EnumBaseType".equals(name)); }; IScope globalScope = getGlobalScope(res, reference, filter); // -- done change --|| List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference)); // IDE-1735 adding support for static-polyfills: TModule module = (TModule) res.getContents().get(1); if (module.isStaticPolyfillModule()) { // limit to situations of resources, that contain at least // one @StaticPolyfill normalizers.add(createImportedNamespaceResolver( module.getQualifiedName() + N4JSQualifiedNameConverter.DELIMITER + "*", false)); } if (!normalizers.isEmpty()) { globalScope = createImportScope(globalScope, normalizers, null, reference.getEReferenceType(), isIgnoreCase(reference)); } IScope resScope = getResourceScope(globalScope, context, reference); return resScope; }
@Override protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) { // "#global# List<ImportNormalizer> result = newArrayList(); result.add(createImportedNamespaceResolver( N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT + N4JSQualifiedNameConverter.DELIMITER + "*", ignoreCase)); return result; }
protected IScope getResourceScope(IScope globalScope, @SuppressWarnings("unused") Resource res, EReference reference) { IScope result = globalScope; ISelectable globalScopeSelectable = new ScopeBasedSelectable(result); // implicit imports (i.e. java.lang.*) List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference)); if (!normalizers.isEmpty()) { result = createImportScope(result, normalizers, globalScopeSelectable, reference.getEReferenceType(), isIgnoreCase(reference)); } return result; }
protected List<ImportNormalizer> getImportedNamespaceResolvers(final EObject context, final boolean ignoreCase) { return cache.get(Tuples.create(context, ignoreCase, "imports"), context.eResource(), new Provider<List<ImportNormalizer>>() { @Override public List<ImportNormalizer> get() { return internalGetImportedNamespaceResolvers(context, ignoreCase); } }); }
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(final EObject context, boolean ignoreCase) { List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList(); EList<EObject> eContents = context.eContents(); for (EObject child : eContents) { String value = getImportedNamespace(child); ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase); if (resolver != null) importedNamespaceResolvers.add(resolver); } return importedNamespaceResolvers; }
protected List<ImportNormalizer> internalGetImportedNamespaceResolvers(EObject context, boolean ignoreCase) { if(EcoreUtil.getRootContainer(context) != context) return Collections.emptyList(); XImportSection importSection = importsConfiguration.getImportSection((XtextResource) context.eResource()); if(importSection != null) { return getImportedNamespaceResolvers(importSection, ignoreCase); } return Collections.emptyList(); }
protected List<ImportNormalizer> getImportedNamespaceResolvers(XImportSection importSection, boolean ignoreCase) { List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations(); List<ImportNormalizer> result = Lists.newArrayListWithExpectedSize(importDeclarations.size()); for (XImportDeclaration imp: importDeclarations) { if (!imp.isStatic()) { String value = imp.getImportedNamespace(); if(value == null) value = imp.getImportedTypeName(); ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase); if (resolver != null) result.add(resolver); } } return result; }
public static ImportNormalizer createNestedTypeAwareImportNormalizer(QualifiedName importedNamespace, boolean wildcard, boolean ignoreCase) { for(int i = 0; i < importedNamespace.getSegmentCount(); i++) { if (importedNamespace.getSegment(i).indexOf('$') >= 0) { return new NestedTypeAwareImportNormalizer(importedNamespace, wildcard, ignoreCase); } } return new NestedTypeAwareImportNormalizerWithDotSeparator(importedNamespace, wildcard, ignoreCase); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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"))); }
@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)); }
@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)); }
@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(getStatechart(context), ImportScope.class); } else { importScopes = EcoreUtil2.getAllContentsOfType(context, ImportScope.class); } for (ImportScope scope : importScopes) { importedNamespaceResolvers.addAll(createNamespaceResolver(scope, ignoreCase)); } return importedNamespaceResolvers; }
protected List<ImportNormalizer> createNamespaceResolver(Scope scope, boolean ignoreCase) { List<ImportNormalizer> importedNamespaceResolvers = Lists.newArrayList(); ImportScope importScope = (ImportScope) scope; for (String child : importScope.getImports()) { PackageImport pkgImport = mapper.findPackageImport(scope.eResource(), child); if (pkgImport != null) { ImportNormalizer resolver = createImportedNamespaceResolver(pkgImport.getNamespace(), ignoreCase); if (resolver != null) importedNamespaceResolvers.add(resolver); } } return importedNamespaceResolvers; }