Search in sources :

Example 36 with IReferenceDescription

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;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 37 with IReferenceDescription

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 38 with IReferenceDescription

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) TextFile(org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil.TextFile) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 39 with IReferenceDescription

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);
            }
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 40 with IReferenceDescription

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IAcceptor(org.eclipse.xtext.util.IAcceptor) Grammar(org.eclipse.xtext.Grammar) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Aggregations

IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)42 URI (org.eclipse.emf.common.util.URI)18 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)17 EObject (org.eclipse.emf.ecore.EObject)12 Test (org.junit.Test)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)7 EReference (org.eclipse.emf.ecore.EReference)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Main (org.eclipse.xtext.linking.langATestLanguage.Main)3