Java Code Examples for org.eclipse.xtext.resource.IResourceDescription#getImportedNames()
The following examples show how to use
org.eclipse.xtext.resource.IResourceDescription#getImportedNames() .
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: ImportedNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testExtendedInterfaces() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("import java.util.List"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo implements List {"); _builder.newLine(); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable<QualifiedName> importedNames = description.getImportedNames(); final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> { return Boolean.valueOf(it.getLastSegment().equals("collection")); }; Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 2
Source File: StatefulResourceDescription.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Iterable<QualifiedName> getImportedNames() { IResourceDescription snapShot = snapShotProvider.get(); if (snapShot != null) return snapShot.getImportedNames(); return Collections.emptyList(); }
Example 3
Source File: ImportedNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testAnonymousClass() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("val foo = new Runnable() {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("override run() {}"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable<QualifiedName> importedNames = description.getImportedNames(); final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> { return Boolean.valueOf(it.getLastSegment().equals("runnable")); }; Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 4
Source File: ImportedNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testNestedTypesIncluded() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.StaticInnerClass.CONSTANT"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable<QualifiedName> importedNames = description.getImportedNames(); final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> { String _string = it.toString(); String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$StaticInnerClass".toLowerCase(); return Boolean.valueOf(Objects.equal(_string, _lowerCase)); }; Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 5
Source File: ImportedNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testNestedTypesIncludedOnUnresolvedFeatures() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("val foo = types.StaticOuterClass.Unknown.StaticInnerClass.CONSTANT"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable<QualifiedName> importedNames = description.getImportedNames(); final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> { String _string = it.toString(); String _lowerCase = "types.StaticOuterClass$Unknown".toLowerCase(); return Boolean.valueOf(Objects.equal(_string, _lowerCase)); }; Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 6
Source File: ImportedNamesTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testNestedTypesIncludedOnUnresolvedFeatures_02() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("package foo"); _builder.newLine(); _builder.newLine(); _builder.append("class Foo {"); _builder.newLine(); _builder.append("\t"); _builder.append("val foo = types.StaticOuterClass.StaticMiddleClass.Unknown"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(file.eResource()); final Iterable<QualifiedName> importedNames = description.getImportedNames(); final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> { String _string = it.toString(); String _lowerCase = "types.StaticOuterClass$StaticMiddleClass$Unknown".toLowerCase(); return Boolean.valueOf(Objects.equal(_string, _lowerCase)); }; Assert.assertTrue(("" + importedNames), IterableExtensions.<QualifiedName>exists(importedNames, _function)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 7
Source File: AbstractCachingResourceDescriptionManager.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Returns all resolved imported names from a given resource description. * * @param candidate * the resource description * @return a collection of names */ protected Pair<Collection<QualifiedName>, Collection<QualifiedName>> getResolvedAndUnresolvedImportedNames(final IResourceDescription candidate) { Iterable<QualifiedName> importedNames = candidate.getImportedNames(); Set<QualifiedName> resolved = Sets.newHashSetWithExpectedSize(Iterables.size(importedNames)); Set<QualifiedName> unresolved = Sets.newHashSet(); for (QualifiedName name : importedNames) { if (QualifiedNames.isUnresolvedName(name)) { unresolved.add(name); } else { resolved.add(name); } } return Tuples.<Collection<QualifiedName>, Collection<QualifiedName>> pair(resolved, unresolved); }
Example 8
Source File: ConcreteSyntaxAwareReferenceFinder.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override protected void findReferencesInDescription(TargetURIs targetURIs, IResourceDescription resourceDescription, IResourceAccess resourceAccess, Acceptor acceptor, IProgressMonitor monitor) { TargetURIKey.Data findReferencesData = keys.getData(targetURIs, resourceAccess); if (monitor.isCanceled()) throw new OperationCanceledException(); final Set<QualifiedName> typesOrModulesToFind = findReferencesData.getTypesOrModulesToFind(); if (typesOrModulesToFind.isEmpty()) { return; } Iterable<QualifiedName> importedNames = resourceDescription.getImportedNames(); // scenario 1: imported names from index // TODO check if imported names from editors are returned as a set? // maybe we need another check for instanceof SortedSet<?> if (importedNames instanceof List<?>) { List<QualifiedName> sorted = (List<QualifiedName>) importedNames; List<QualifiedName> searchMe = sorted; // Optimize search for (QualifiedName typeOrModuleToFind : typesOrModulesToFind) { int insertionIndex = Collections.binarySearch(searchMe, typeOrModuleToFind); if (insertionIndex >= 0) { resourceAccess.readOnly( resourceDescription.getURI(), (resourceSet) -> { findReferences(targetURIs, resourceSet.getResource(resourceDescription.getURI(), true), acceptor, monitor); return null; }); return; } else { int startFrom = -(insertionIndex + 1); if (startFrom >= sorted.size()) { return; } searchMe = sorted.subList(startFrom, sorted.size()); } } } else { for (QualifiedName importedName : importedNames) { if (typesOrModulesToFind.contains(importedName)) { resourceAccess.readOnly( resourceDescription.getURI(), (resourceSet) -> { findReferences(targetURIs, resourceSet.getResource(resourceDescription.getURI(), true), acceptor, monitor); return null; }); return; } } } }