use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.
the class BuilderUtil method getIncomingReferences.
public static Set<IReferenceDescription> getIncomingReferences(URI uri) {
Set<IReferenceDescription> desc = Sets.newHashSet();
Iterable<IResourceDescription> descriptions = getBuilderState().getAllResourceDescriptions();
for (IResourceDescription res : descriptions) {
Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
for (IReferenceDescription ref : descriptions2) {
if (uri.hasFragment()) {
if (ref.getTargetEObjectUri().equals(uri))
desc.add(ref);
} else {
if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment()))
desc.add(ref);
}
}
}
return desc;
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.
the class SimpleProjectsIntegrationTest method testReexportedJarRemoved.
@Test
public void testReexportedJarRemoved() throws Exception {
IJavaProject foo = createJavaProject("foo");
IJavaProject bar = createJavaProject("bar");
IJavaProject baz = createJavaProject("baz");
addNature(foo.getProject(), XtextProjectHelper.NATURE_ID);
addNature(bar.getProject(), XtextProjectHelper.NATURE_ID);
addNature(baz.getProject(), XtextProjectHelper.NATURE_ID);
IFile file = foo.getProject().getFile("foo.jar");
file.create(JavaProjectSetupUtil.jarInputStream(new TextFile("foo/Foo" + F_EXT, "object Foo")), true, monitor());
IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(file.getFullPath(), null, null, true);
addToClasspath(foo, newLibraryEntry);
addToClasspath(bar, JavaCore.newProjectEntry(foo.getPath(), true));
addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false));
addSourceFolder(baz, "src");
IFile bazFile = createFile("baz/src/Baz" + F_EXT, "object Baz references Foo");
build();
assertEquals(0, countMarkers(bazFile));
deleteClasspathEntry(foo, newLibraryEntry.getPath());
build();
assertEquals(1, countMarkers(bazFile));
assertEquals(1, countResourcesInIndex());
Iterator<IReferenceDescription> references = getContainedReferences(URI.createPlatformResourceURI(bazFile.getFullPath().toString(), true)).iterator();
assertFalse(references.hasNext());
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.
the class SimpleProjectsIntegrationTest method testReexportedSource.
@Test
public void testReexportedSource() throws Exception {
IJavaProject foo = createJavaProject("foo");
IJavaProject bar = createJavaProject("bar");
IJavaProject baz = createJavaProject("baz");
addNature(foo.getProject(), XtextProjectHelper.NATURE_ID);
addNature(bar.getProject(), XtextProjectHelper.NATURE_ID);
addNature(baz.getProject(), XtextProjectHelper.NATURE_ID);
IFile file = foo.getProject().getFile("foo.jar");
file.create(JavaProjectSetupUtil.jarInputStream(new TextFile("foo/Foo" + F_EXT, "object Foo")), true, monitor());
IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(file.getFullPath(), null, null, true);
addToClasspath(foo, newLibraryEntry);
addToClasspath(bar, JavaCore.newProjectEntry(foo.getPath(), true));
addToClasspath(baz, JavaCore.newProjectEntry(bar.getPath(), false));
addSourceFolder(baz, "src");
IFile bazFile = createFile("baz/src/Baz" + F_EXT, "object Baz references Foo");
build();
assertEquals(0, countMarkers(bazFile));
assertEquals(2, countResourcesInIndex());
Iterator<IReferenceDescription> references = getContainedReferences(URI.createPlatformResourceURI(bazFile.getFullPath().toString(), true)).iterator();
IReferenceDescription next = references.next();
assertFalse(references.hasNext());
assertEquals("platform:/resource/baz/src/Baz.buildertestlanguage#/", next.getSourceEObjectUri().toString());
assertEquals("archive:platform:/resource/foo/foo.jar!/foo/Foo.buildertestlanguage#/", next.getTargetEObjectUri().toString());
assertEquals(-1, next.getIndexInList());
assertEquals(BuilderTestLanguagePackage.Literals.ELEMENT__REFERENCES, next.getEReference());
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.
the class ReferenceSearchResultContentProvider method inputChanged.
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
synchronized (viewer) {
if (rootNodes != null) {
rootNodes.clear();
}
if (oldInput instanceof ReferenceSearchResult) {
((ReferenceSearchResult) oldInput).removeListener(this);
}
if (newInput instanceof ReferenceSearchResult && viewer instanceof TreeViewer) {
((ReferenceSearchResult) newInput).addListener(this);
this.viewer = (TreeViewer) viewer;
for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput).getMatchingReferences()) {
addReference(referenceDescription, false);
}
}
}
}
use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.
the class RuleOverrideUtil method getOverridingRules.
public List<IEObjectDescription> getOverridingRules(final AbstractRule originalRule) {
Grammar grammar = GrammarUtil.getGrammar(originalRule);
final List<IEObjectDescription> overridingRules = newArrayList();
IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
@Override
public void accept(IReferenceDescription referenceToGrammar) {
if (referenceToGrammar.getEReference() == XtextPackage.Literals.GRAMMAR__USED_GRAMMARS) {
IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(referenceToGrammar.getSourceEObjectUri().trimFragment());
for (IEObjectDescription rule : resourceDescription.getExportedObjectsByType(originalRule.eClass())) {
if (Strings.equal(originalRule.getName(), rule.getQualifiedName().getLastSegment())) {
overridingRules.add(rule);
break;
}
}
}
}
};
referenceFinder.findAllReferences(singleton(EcoreUtil2.getPlatformResourceOrNormalizedURI(grammar)), localContextProvider, acceptor, new NullProgressMonitor());
return overridingRules;
}
Aggregations