Example usage for org.eclipse.jdt.core.search IJavaSearchConstants SUPERTYPE_TYPE_REFERENCE

List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants SUPERTYPE_TYPE_REFERENCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.search IJavaSearchConstants SUPERTYPE_TYPE_REFERENCE.

Prototype

int SUPERTYPE_TYPE_REFERENCE

To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants SUPERTYPE_TYPE_REFERENCE.

Click Source Link

Document

Return only type references used as a super type or as a super interface.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocatorParser.java

License:Open Source License

protected void consumeClassHeaderExtends() {
    this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR);
    super.consumeClassHeaderExtends();
    if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
        TypeDeclaration typeDeclaration = (TypeDeclaration) this.astStack[this.astPtr];
        this.patternLocator.match(typeDeclaration.superclass, this.nodeSet);
    }/*from  ww w  . j  a v  a  2s .c om*/
    this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocatorParser.java

License:Open Source License

protected void consumeInterfaceType() {
    this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR);
    super.consumeInterfaceType();
    if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
        TypeReference typeReference = (TypeReference) this.astStack[this.astPtr];
        this.patternLocator.match(typeReference, this.nodeSet);
    }//  w ww  .  j  av a  2s. c om
    this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR);
}

From source file:org.spoofax.interpreter.library.ecj.ECJ_search_for_supertype_type_refs.java

License:LGPL

@Override
public boolean call(IContext env, Strategy[] svars, IStrategoTerm[] tvars) throws InterpreterException {

    if (!ECJTools.isIJavaElement(tvars[0]))
        return false;
    if (!Tools.isTermString(tvars[1]))
        return false;

    // TODO: This only works in 3.4, what to do for other versions? 

    // FIXME this method will currently only return exact type matches
    //       it is unclear whether searches for the supertype Foo<Object>
    //       should also allow Foo<Bar> to be returned; for now, it's explicitly
    //       forbidden

    final String className = Tools.asJavaString(tvars[1]);
    SearchPattern sp = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE,
            IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE,
            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

    try {//from w ww .jav a2  s  .  c o  m
        final IJavaSearchScope ss = SearchEngine
                .createJavaSearchScope(new IJavaElement[] { ECJTools.asIJavaElement(tvars[0]) });

        final Collection<IType> results = new LinkedList<IType>();

        SearchRequestor requestor = new SearchRequestor() {

            @Override
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                System.out.println(match.getElement() + "/" + match.getClass().toString() + "/"
                        + match.getElement().getClass().toString());
                IType t = (IType) match.getElement();
                System.out.println(t.getFullyQualifiedName());
                for (String s : t.getSuperInterfaceNames())
                    if (s.equals(className)) {
                        results.add(t);
                        return;
                    }
            }

        };

        SearchEngine se = new SearchEngine();

        se.search(sp, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, ss, requestor,
                null);
        IStrategoTerm[] r = new IStrategoTerm[results.size()];
        int pos = 0;
        for (IType t : results)
            r[pos++] = ECJFactory.wrap(t);
        env.setCurrent(env.getFactory().makeList(r));
    } catch (CoreException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}