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

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

Introduction

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

Prototype

int FIELD

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

Click Source Link

Document

The searched element is a field.

Usage

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipant.java

License:Open Source License

private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) {
    // Translate the IJavaSearchConstant element type constants to IJavaElement
    // type constants.
    int elementType;
    switch (query.getSearchFor()) {
    case IJavaSearchConstants.TYPE:
        elementType = IJavaElement.TYPE;
        break;/*from   www .ja v a2 s  .c o m*/
    case IJavaSearchConstants.FIELD:
        elementType = IJavaElement.FIELD;
        break;
    case IJavaSearchConstants.METHOD:
    case IJavaSearchConstants.CONSTRUCTOR:
        // IJavaElement.METHOD represents both methods & ctors
        elementType = IJavaElement.METHOD;
        break;
    default:
        // We only support searching for types, fields, methods, and ctors
        return Collections.emptySet();
    }

    return JavaRefIndex.getInstance().findElementReferences(query.getPattern(), elementType,
            query.isCaseSensitive());
}

From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipantTest.java

License:Open Source License

public void testPatternSearch() throws CoreException {
    Match[] expected;//from   w w  w.  j a  v a2s  .c  o m

    // Search for type references by simple name
    expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
            createWindowsTestMatch(1419, 50) };
    assertSearchMatches(expected, createQuery("InnerSub", IJavaSearchConstants.TYPE));

    // Search for type with different casing
    expected = new Match[] { createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
            createWindowsTestMatch(1419, 50) };
    assertSearchMatches(expected, createQuery("innersub", IJavaSearchConstants.TYPE));

    // Search for type with different casing with case-sensitive enabled
    QuerySpecification query = new PatternQuerySpecification("innersub", IJavaSearchConstants.TYPE, true,
            IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
    assertSearchMatches(NO_MATCHES, query);

    // Search for field references
    assertSearchMatch(createWindowsTestMatch(990, 5), createQuery("keith", IJavaSearchConstants.FIELD));

    // Search for method references using * wildcard
    expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5),
            createWindowsTestMatch(1340, 8) };
    assertSearchMatches(expected, createQuery("sayH*", IJavaSearchConstants.METHOD));

    // Search for method references using ? wildcard
    expected = new Match[] { createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5) };
    assertSearchMatches(expected, createQuery("sayH?", IJavaSearchConstants.METHOD));

    // Search for constructor references with qualified type name and parameters
    assertSearchMatch(createWindowsTestMatch(892, 3),
            createQuery("com.hello.client.JavaQueryParticipantTest.InnerSub.InnerSub(String)",
                    IJavaSearchConstants.CONSTRUCTOR));
}

From source file:com.iw.plugins.spindle.util.PublicStaticFieldSearchEngine.java

License:Mozilla Public License

/**
 * Searches for all types with public static fields in the given scope.
 * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and
 * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS
 *///from  w w w  . j a va2s.c o  m
public IType[] searchPublicStaticMethods(IProgressMonitor pm, IJavaSearchScope scope, int style)
        throws JavaModelException {
    List typesFound = new ArrayList(200);

    IJavaSearchResultCollector collector = new FieldCollector(typesFound, style, pm);
    new SearchEngine().search(TapestryPlugin.getDefault().getWorkspace(), "*", IJavaSearchConstants.FIELD,
            IJavaSearchConstants.DECLARATIONS, scope, collector);

    return (IType[]) typesFound.toArray(new IType[typesFound.size()]);
}

From source file:de.loskutov.dh.search.SearchHelper.java

License:Open Source License

private static SearchPattern createAnyFieldPattern(IType[] types) {
    if (types.length == 0) {
        return createAnyFieldPattern();
    }/*from   w w w.j ava  2 s.c o m*/
    SearchPattern result = null;
    for (IType type : types) {
        SearchPattern searchPattern = SearchPattern.createPattern(type.getFullyQualifiedName() + ".*",
                IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
        if (result == null) {
            result = searchPattern;
        } else {
            result = SearchPattern.createOrPattern(result, searchPattern);
        }
    }
    return result;
}

From source file:de.loskutov.dh.search.SearchHelper.java

License:Open Source License

private static SearchPattern createAnyFieldPattern() {
    return SearchPattern.createPattern("*", IJavaSearchConstants.FIELD, IJavaSearchConstants.DECLARATIONS,
            SearchPattern.R_PATTERN_MATCH);
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java

License:Open Source License

/********************************************************************************/

void handleJavaSearch(String proj, String bid, String patstr, String foritems, boolean defs, boolean refs,
        boolean impls, boolean equiv, boolean exact, boolean system, IvyXmlWriter xw) throws BedrockException {
    IJavaProject ijp = getJavaProject(proj);

    our_plugin.waitForEdits();//from  w  ww.j a  v  a 2 s.  co m

    int forflags = 0;
    if (foritems == null)
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("CLASS"))
        forflags = IJavaSearchConstants.CLASS;
    else if (foritems.equalsIgnoreCase("INTERFACE"))
        forflags = IJavaSearchConstants.INTERFACE;
    else if (foritems.equalsIgnoreCase("ENUM"))
        forflags = IJavaSearchConstants.ENUM;
    else if (foritems.equalsIgnoreCase("ANNOTATION"))
        forflags = IJavaSearchConstants.ANNOTATION_TYPE;
    else if (foritems.equalsIgnoreCase("CLASS&ENUM"))
        forflags = IJavaSearchConstants.CLASS_AND_ENUM;
    else if (foritems.equalsIgnoreCase("CLASS&INTERFACE"))
        forflags = IJavaSearchConstants.CLASS_AND_INTERFACE;
    else if (foritems.equalsIgnoreCase("TYPE"))
        forflags = IJavaSearchConstants.TYPE;
    else if (foritems.equalsIgnoreCase("FIELD"))
        forflags = IJavaSearchConstants.FIELD;
    else if (foritems.equalsIgnoreCase("METHOD"))
        forflags = IJavaSearchConstants.METHOD;
    else if (foritems.equalsIgnoreCase("CONSTRUCTOR"))
        forflags = IJavaSearchConstants.CONSTRUCTOR;
    else if (foritems.equalsIgnoreCase("PACKAGE"))
        forflags = IJavaSearchConstants.PACKAGE;
    else if (foritems.equalsIgnoreCase("FIELDWRITE"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.WRITE_ACCESSES;
    else if (foritems.equalsIgnoreCase("FIELDREAD"))
        forflags = IJavaSearchConstants.FIELD | IJavaSearchConstants.READ_ACCESSES;
    else
        forflags = IJavaSearchConstants.TYPE;

    int limit = 0;
    if (defs && refs)
        limit = IJavaSearchConstants.ALL_OCCURRENCES;
    else if (defs)
        limit = IJavaSearchConstants.DECLARATIONS;
    else if (refs)
        limit = IJavaSearchConstants.REFERENCES;
    else if (impls)
        limit = IJavaSearchConstants.IMPLEMENTORS;

    int mrule = SearchPattern.R_PATTERN_MATCH;
    if (equiv)
        mrule = SearchPattern.R_EQUIVALENT_MATCH;
    else if (exact)
        mrule = SearchPattern.R_EXACT_MATCH;

    SearchPattern pat = SearchPattern.createPattern(patstr, forflags, limit, mrule);
    if (pat == null) {
        throw new BedrockException(
                "Invalid java search pattern `" + patstr + "' " + forflags + " " + limit + " " + mrule);
    }

    FindFilter filter = null;
    if (forflags == IJavaSearchConstants.METHOD) {
        String p = patstr;
        int idx = p.indexOf("(");
        if (idx > 0)
            p = p.substring(0, idx);
        idx = p.lastIndexOf(".");
        if (idx > 0) {
            if (defs)
                filter = new ClassFilter(p.substring(0, idx));
        }
    }

    // TODO: create scope for only user's items
    IJavaElement[] pelt;
    if (ijp != null)
        pelt = new IJavaElement[] { ijp };
    else
        pelt = getAllProjects();

    ICompilationUnit[] working = getWorkingElements(pelt);
    for (ICompilationUnit xcu : working) {
        try {
            BedrockPlugin.logD("WORK WITH " + xcu.isWorkingCopy() + " " + xcu.getPath() + xcu.getSourceRange());
        } catch (JavaModelException e) {
            BedrockPlugin.logD("WORK WITH ERROR: " + e);
        }
    }

    IJavaSearchScope scp = null;
    int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
    if (system) {
        fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES;
        scp = SearchEngine.createWorkspaceScope();
    } else {
        scp = SearchEngine.createJavaSearchScope(pelt, fg);
    }

    SearchEngine se = new SearchEngine(working);
    SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    FindHandler fh = new FindHandler(xw, filter, system);

    BedrockPlugin.logD("BEGIN SEARCH " + pat);
    BedrockPlugin.logD("SEARCH SCOPE " + system + " " + fg + " " + scp);

    try {
        se.search(pat, parts, scp, fh, null);
    } catch (Throwable e) {
        throw new BedrockException("Problem doing Java search: " + e, e);
    }
}

From source file:org.eclim.plugin.jdt.command.search.SearchCommand.java

License:Open Source License

/**
 * Translates the string type to the int equivalent.
 *
 * @param type The String type./*from  ww  w . j a v a 2s  .c  om*/
 * @return The int type.
 */
protected int getType(String type) {
    if (TYPE_ANNOTATION.equals(type)) {
        return IJavaSearchConstants.ANNOTATION_TYPE;
    } else if (TYPE_CLASS.equals(type)) {
        return IJavaSearchConstants.CLASS;
    } else if (TYPE_CLASS_OR_ENUM.equals(type)) {
        return IJavaSearchConstants.CLASS_AND_ENUM;
    } else if (TYPE_CLASS_OR_INTERFACE.equals(type)) {
        return IJavaSearchConstants.CLASS_AND_INTERFACE;
    } else if (TYPE_CONSTRUCTOR.equals(type)) {
        return IJavaSearchConstants.CONSTRUCTOR;
    } else if (TYPE_ENUM.equals(type)) {
        return IJavaSearchConstants.ENUM;
    } else if (TYPE_FIELD.equals(type)) {
        return IJavaSearchConstants.FIELD;
    } else if (TYPE_INTERFACE.equals(type)) {
        return IJavaSearchConstants.INTERFACE;
    } else if (TYPE_METHOD.equals(type)) {
        return IJavaSearchConstants.METHOD;
    } else if (TYPE_PACKAGE.equals(type)) {
        return IJavaSearchConstants.PACKAGE;
    }
    return IJavaSearchConstants.TYPE;
}

From source file:org.grails.ide.eclipse.refactoring.rename.type.ServiceReferenceUpdater.java

License:Open Source License

@Override
public void createChanges(final ParticipantChangeManager changes, final RefactoringStatus status,
        IProgressMonitor pm) {//  w w  w . ja v a  2 s.  c o  m
    Assert.isNotNull(changes);
    try {
        IJavaSearchScope scope = RefactoringUtils.getSearchScope(project.getJavaProject());
        SearchEngine engine = new SearchEngine();

        final String fieldName = GrailsNameUtils.getPropertyName(renaming.getTarget().getFullyQualifiedName());
        final String fieldNewName = GrailsNameUtils.getPropertyName(renaming.getNewName());

        SearchPattern fieldByNamePat = SearchPattern.createPattern(fieldName, IJavaSearchConstants.FIELD,
                IJavaSearchConstants.ALL_OCCURRENCES,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

        SearchRequestor req = new SearchRequestor() {
            @Override
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                try {
                    if (match instanceof FieldDeclarationMatch || match instanceof FieldReferenceMatch) {
                        Object el = match.getElement();
                        if (el instanceof IJavaElement) {
                            IJavaElement jel = (IJavaElement) el;
                            ICompilationUnit cu = (ICompilationUnit) jel
                                    .getAncestor(IJavaElement.COMPILATION_UNIT);
                            if (cu != null) {
                                TextChange cuChange = changes.getCUChange(cu);
                                final int offset = match.getOffset();
                                final int length = match.getLength();
                                String text = cu.getBuffer().getText(offset, length);
                                if (text.equals(fieldName)) {
                                    //Only perform the edit if the text we are about to replace is what we expect!
                                    cuChange.addEdit(new ReplaceEdit(offset, length, fieldNewName));
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    //Ignore this match and log the exception...
                    //but keep processing other matches!
                    GrailsCoreActivator.log(e);
                }
            }

        };
        engine.search(fieldByNamePat, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                scope, req, pm);
    } catch (CoreException e) {
        GrailsCoreActivator.log(e);
    }
}

From source file:qwickie.util.DocumentHelper.java

License:Apache License

/**
 * marks all occurrences of the given string
 *///from w  ww . j  ava2  s  .com
public static void markOccurrence(final ITextEditor textEditor, final String string) {
    if (string == null) {
        return;
    }
    SearchPattern pattern = SearchPattern.createPattern(string, IJavaSearchConstants.FIELD,
            IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_EXACT_MATCH);

    SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(final SearchMatch match) {
            IAnnotationModel model = textEditor.getDocumentProvider()
                    .getAnnotationModel(textEditor.getEditorInput());
            Annotation annotation = new Annotation("org.eclipse.jdt.ui.occurrences", false,
                    "wicket id constant");
            model.addAnnotation(annotation, new Position(match.getOffset(), match.getLength()));
        }
    };

    SearchEngine searchEngine = new SearchEngine();
    try {
        searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor());
    } catch (CoreException e) {
    }
}