Java Code Examples for org.eclipse.xtext.resource.XtextResource#getAllContents()
The following examples show how to use
org.eclipse.xtext.resource.XtextResource#getAllContents() .
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: DefaultImportsConfiguration.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public Iterable<JvmDeclaredType> getLocallyDefinedTypes(XtextResource resource) { final List<JvmDeclaredType> locallyDefinedTypes = newArrayList(); for (TreeIterator<EObject> i = resource.getAllContents(); i.hasNext();) { EObject next = i.next(); if (next instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) next; locallyDefinedTypes.add(declaredType); addInnerTypes(declaredType, new IAcceptor<JvmDeclaredType>() { @Override public void accept(JvmDeclaredType t) { locallyDefinedTypes.add(t); } }); i.prune(); } if(next instanceof XExpression) { i.prune(); } } return locallyDefinedTypes; }
Example 2
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testRelativeContext() throws Exception { final XtextResource resource = getResource(new StringInputStream( "stuff { " + " baz { " + " datatype String " + " } " + " entity Person {}" + "}"), URI .createURI("relative.indextestlanguage")); Iterable<EObject> allContents = new Iterable<EObject>() { @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Entity entity = filter(allContents, Entity.class).iterator().next(); IScope scope = scopeProvider.getScope(entity, IndexTestLanguagePackage.eINSTANCE.getProperty_Type()); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("baz.String"))); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("stuff.baz.String"))); }
Example 3
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testRelativePath() throws Exception { final XtextResource resource = getResource(new StringInputStream( "stuff { " + " import baz.*" + " baz { " + " datatype String " + " } " + " entity Person {" + " }" + "}"), URI .createURI("relative.indextestlanguage")); Iterable<EObject> allContents = new Iterable<EObject>() { @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Entity entity = filter(allContents, Entity.class).iterator().next(); IScope scope = scopeProvider.getScope(entity, IndexTestLanguagePackage.eINSTANCE.getProperty_Type()); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("String"))); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("baz.String"))); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("stuff.baz.String"))); }
Example 4
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testReexports2() throws Exception { final XtextResource resource = getResource(new StringInputStream( "A { " + " B { " + " entity D {}" + " }" + "}" + "E {" + " import A.B.*" + " entity D {}" + " datatype Context" + "}"), URI .createURI("testReexports2.indextestlanguage")); Iterable<EObject> allContents = new Iterable<EObject>() { @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Datatype datatype = filter(allContents, Datatype.class).iterator().next(); IScope scope = scopeProvider.getScope(datatype, IndexTestLanguagePackage.eINSTANCE.getProperty_Type()); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("D"))); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("E.D"))); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("A.B.D"))); }
Example 5
Source File: ImportedNamespaceAwareLocalScopeProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testLocalElementsNotFromIndex() throws Exception { final XtextResource resource = getResource(new StringInputStream( "A { " + " B { " + " entity D {}" + " }" + "}" + "E {" + " datatype Context" + "}"), URI.createURI("foo23.indextestlanguage")); Iterable<EObject> allContents = new Iterable<EObject>() { @Override public Iterator<EObject> iterator() { return resource.getAllContents(); } }; Datatype datatype = filter(allContents, Datatype.class).iterator().next(); IScope scope = scopeProvider.getScope(datatype, IndexTestLanguagePackage.eINSTANCE.getProperty_Type()); assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("A.B.D"))); }
Example 6
Source File: SoliditySemanticHighlighter.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { TreeIterator<EObject> allContents = resource.getAllContents(); while (allContents.hasNext()) { EObject next = allContents.next(); if (next.eIsProxy()) { continue; } if (next instanceof ContractDefinition) { ContractDefinition definition = (ContractDefinition) next; provideHighligtingFor(definition, acceptor); } if (next instanceof Operation) { Operation operation = (Operation) next; provideHighligtingFor(operation, acceptor); } if (next instanceof Block) { Block block = (Block) next; provideHighligtingFor(block, acceptor); } if (next instanceof ElementReferenceExpression) { ElementReferenceExpression expression = (ElementReferenceExpression) next; provideHighligtingFor(expression, acceptor); } } }
Example 7
Source File: GamlSemanticHighlightingCalculator.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void provideHighlightingFor(final XtextResource resource, final IHighlightedPositionAcceptor arg1, final CancelIndicator arg2) { if (resource == null) { return; } acceptor = arg1; final TreeIterator<EObject> root = resource.getAllContents(); while (root.hasNext()) { process(root.next()); } done.clear(); highlightTasks(resource, acceptor); }