Example usage for org.eclipse.jdt.core.search SearchPattern R_EXACT_MATCH

List of usage examples for org.eclipse.jdt.core.search SearchPattern R_EXACT_MATCH

Introduction

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

Prototype

int R_EXACT_MATCH

To view the source code for org.eclipse.jdt.core.search SearchPattern R_EXACT_MATCH.

Click Source Link

Document

Match rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern.

Usage

From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java

License:Open Source License

private int getMatchMode(String pattern) {
    if (pattern.indexOf('*') != -1 || pattern.indexOf('?') != -1)
        return SearchPattern.R_PATTERN_MATCH;

    if (SearchPattern.validateMatchRule(pattern,
            SearchPattern.R_CAMELCASE_MATCH) == SearchPattern.R_CAMELCASE_MATCH)
        return SearchPattern.R_CAMELCASE_MATCH;

    return SearchPattern.R_EXACT_MATCH;
}

From source file:ca.mcgill.cs.swevo.jayfx.FastConverter.java

License:Open Source License

/**
 * Returns a Java element associated with pElement. This method cannot track
 * local or anonymous types or any of their members, primitive types, or
 * array types. It also cannot find initializers, default constructors that
 * are not explicitly declared, or non-top-level types outside the project
 * analyzed. If such types are passed as argument, a ConversionException is
 * thrown./*from  ww w  .  ja  v  a 2s .  co  m*/
 * 
 * @param pElement
 *            The element to convert. Never null.
 * @return Never null.
 * @throws ConversionException
 *             If the element cannot be
 */
public IJavaElement getJavaElement(final IElement pElement) throws ConversionException {
    // assert( pElement!= null );
    IJavaElement lReturn = null;
    if (pElement.getCategory() == Category.CLASS) {
        lReturn = this.aTypeMap.get(pElement.getId());
        if (lReturn == null)
            // TODO Make this smarter in the case of multiple projects
            if (this.aTypeMap.size() > 0)
                try {
                    lReturn = this.aTypeMap.values().iterator().next().getJavaProject()
                            .findType(pElement.getId());
                } catch (final JavaModelException pException) {
                    // noting
                }
        if (lReturn == null)
            throw new ConversionException("Cannot find type " + pElement);
    } else if (pElement.getCategory() == Category.PACKAGE) {
        String id = pElement.getId();
        final SearchPattern pattern = SearchPattern.createPattern(id, IJavaSearchConstants.PACKAGE,
                IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
        Collection<SearchMatch> matches = SearchEngineUtil.search(pattern, null);
        if (matches.isEmpty())
            throw new ConversionException("Cannot find type " + pElement);
        else
            lReturn = (IJavaElement) matches.iterator().next().getElement();
    } else {
        final IJavaElement lDeclaringClass = this.getJavaElement(pElement.getDeclaringClass());
        if (pElement.getCategory() == Category.FIELD) {
            lReturn = ((IType) lDeclaringClass).getField(((FieldElement) pElement).getSimpleName());
            if (lReturn == null)
                throw new ConversionException("Cannot find field " + pElement);
        } else if (pElement.getCategory() == Category.METHOD)
            try {
                final IMethod[] lMethods = ((IType) lDeclaringClass).getMethods();
                lReturn = this.findMethod((MethodElement) pElement, lMethods);

                // if( lReturn == null &&
                // isDefaultConstructor((MethodElement)pElement)) {
                //
                // }

                if (lReturn == null)
                    throw new ConversionException("Cannot find method " + pElement);
            } catch (final JavaModelException pException) {
                throw new ConversionException("Cannot convert method " + pElement);
            }
        else
            throw new ConversionException("Unsupported element type " + pElement.getClass().getName());
    }
    // assert( lReturn != null );
    return lReturn;
}

From source file:ca.ubc.cs.ferret.tests.support.TestProject.java

License:Open Source License

public void waitForIndexer() throws JavaModelException {
    new SearchEngine().searchAllTypeNames(null, null, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.CLASS,
            SearchEngine.createJavaSearchScope(new IJavaElement[0]), new TypeNameRequestor() {
                // nothing needs to be done here...we accept everything
            }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
}

From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java

License:Open Source License

public static SearchPattern createMethodDeclarationPattern(ITraceClassMethod method) {
    if (method == null) {
        return null;
    }//from  w  ww.j  av a2  s.  com
    ITraceClass callingClass = method.getTraceClass();
    if (callingClass == null) {
        return null;
    }
    String className = callingClass.getName();
    className = Signature.toString(className);
    boolean isConstructor = false;
    String methodName = method.getName();
    isConstructor = methodName.startsWith("<init");
    if (isConstructor) {
        int lastDotIndex = className.lastIndexOf('.');
        if (lastDotIndex >= 0) {
            methodName = className.substring(lastDotIndex + 1);
        }
    }

    String methodString = Signature.toString(method.getSignature(), methodName, null, false, true);
    String returnType = "";
    if (!isConstructor) {
        int returnIndex = methodString.indexOf(' ');
        if (returnIndex > 0) {
            returnType = " " + methodString.substring(0, returnIndex);
            methodString = methodString.substring(returnIndex + 1, methodString.length());
        }
    }
    return SearchPattern.createPattern(className + '.' + methodString + returnType, IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
}

From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java

License:Open Source License

private static IJavaElement searchForType(String classSignature, IJavaSearchScope scope,
        IProgressMonitor monitor) throws CoreException, InterruptedException {
    try {/*from w w  w. j  a  v a 2s.  c om*/
        synchronized (cachedTypes) {
            IType found = cachedTypes.get(classSignature);
            if (found != null) {
                return found;
            }
            SearchEngine engine = new SearchEngine();
            SearchPattern pattern = null;
            SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
            LocalSearchRequestor requestor = new LocalSearchRequestor();
            pattern = SearchPattern.createPattern(classSignature.replace('$', '.'), IJavaSearchConstants.CLASS,
                    IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

            engine.search(pattern, new SearchParticipant[] { participant }, scope, requestor, monitor);
            if (requestor.matches.size() > 0) {
                found = (IType) requestor.matches.get(0).getElement();
                if (found.getFullyQualifiedName().equals(classSignature)) {
                    cachedTypes.put(classSignature, found);
                    return found;
                }

            }
            String[] className = classSignature.split("\\$");
            found = cachedTypes.get(className[0]);
            if (found == null) {

                //find the class
                pattern = SearchPattern.createPattern(className[0], IJavaSearchConstants.CLASS,
                        IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

                engine.search(pattern, new SearchParticipant[] { participant }, scope, requestor, monitor);
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                if (requestor.matches.size() > 0) {
                    found = (IType) requestor.matches.get(0).getElement();
                    if (found.getFullyQualifiedName().equals(classSignature)) {
                        for (SearchMatch match : requestor.matches) {
                            IType temp = (IType) match.getElement();
                            if (temp.getTypeRoot() instanceof ICompilationUnit) {
                                //prefer source types.
                                found = temp;
                                break;
                            }
                        }
                        if (cachedTypes.size() > 100) {
                            cachedTypes.clear();
                        }
                        cachedTypes.put(className[0], found);
                    } else {
                        found = null;
                    }
                }
            }
            if (found == null)
                return null;
            StringBuilder childTypeName = new StringBuilder();
            childTypeName.append(className[0]);
            //check each of the indexes for the sub-types
            for (int i = 1; i < className.length; i++) {
                childTypeName.append('$');
                childTypeName.append(className[i]);
                IType parent = found;
                found = cachedTypes.get(childTypeName.toString());

                if (found == null) {
                    boolean isAnonymous = false;
                    Integer occurrenceCount = -1;
                    try {
                        occurrenceCount = Integer.parseInt(className[i]);
                        isAnonymous = true;
                    } catch (NumberFormatException e) {
                        isAnonymous = false;
                    }
                    if (isAnonymous) {
                        if (!parent.isBinary()) {
                            found = parent.getType("", occurrenceCount);
                            if (found != null) {
                                if (found.exists()) {
                                    cachedTypes.put(childTypeName.toString(), found);
                                    continue;
                                } else {
                                    found = null;
                                }
                            }
                        } else {
                            //if it is a binary type, there is no hope for 
                            //finding an anonymous inner class. Use the number
                            //as the type name, and cache the handle.
                            found = parent.getType(className[i]);
                            cachedTypes.put(childTypeName.toString(), found);
                            continue;
                        }
                    }
                    ArrayList<IType> childTypes = new ArrayList<IType>();
                    LinkedList<IJavaElement> children = new LinkedList<IJavaElement>();
                    children.addAll(Arrays.asList(parent.getChildren()));
                    while (children.size() > 0) {
                        IJavaElement child = children.removeFirst();
                        if (child instanceof IType) {
                            childTypes.add((IType) child);
                        } else if (child instanceof IMember) {
                            children.addAll(Arrays.asList(((IMember) child).getChildren()));
                        }
                    }
                    int numIndex = 0;
                    while (numIndex < className[i].length()
                            && Character.isDigit(className[i].charAt(numIndex))) {
                        numIndex++;
                    }
                    String name = className[i];
                    try {
                        //get a number at the beginning to find out if 
                        //there is an occurrence count
                        if (numIndex <= name.length()) {
                            occurrenceCount = parseInt(name.substring(0, numIndex));
                            if (occurrenceCount == null) {
                                occurrenceCount = 1;
                            }
                            if (numIndex < name.length() - 1) {
                                name = name.substring(numIndex);
                            } else {
                                name = "";
                            }
                        }
                        for (IType childType : childTypes) {
                            if ("".equals(name)) {
                                if (childType.getOccurrenceCount() == occurrenceCount) {
                                    found = childType;
                                    break;
                                }
                            } else {
                                if (name.equals(childType.getElementName())
                                        && childType.getOccurrenceCount() == occurrenceCount) {
                                    found = childType;
                                    break;
                                }
                            }
                        }
                        if (found == null) {
                            if ("".equals(name)) {
                                found = parent.getTypeRoot().getJavaProject().findType(classSignature);
                                //found = parent.getType("" + occurrenceCount);
                            } else {
                                found = parent.getType(name, occurrenceCount);
                            }
                        }
                        cachedTypes.put(childTypeName.toString(), found);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            }
            return found;
        }
    } catch (Exception e) {
        SketchPlugin.getDefault().log(e);
        return null;
    }
}

From source file:com.android.ide.eclipse.adt.SourceRevealer.java

License:Open Source License

private List<SearchMatch> searchForPattern(String pattern, int searchFor,
        Predicate<SearchMatch> filterPredicate) {
    SearchEngine se = new SearchEngine();
    SearchPattern searchPattern = SearchPattern.createPattern(pattern, searchFor,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
    SearchResultAccumulator requestor = new SearchResultAccumulator(filterPredicate);
    try {/*from   w  w  w. j a  va 2s . co  m*/
        se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        AdtPlugin.printErrorToConsole(e.getMessage());
        return Collections.emptyList();
    }

    return requestor.getMatches();
}

From source file:com.android.ide.eclipse.pdt.internal.SourceRevealer.java

License:Apache License

@Override
public boolean revealMethod(String fqmn, String fileName, int lineNumber, String perspective) {
    SearchEngine se = new SearchEngine();
    SearchPattern searchPattern = SearchPattern.createPattern(fqmn, IJavaSearchConstants.METHOD,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
    MethodSearchRequestor requestor = new MethodSearchRequestor(perspective);
    try {/*w w w  . java  2s .  co  m*/
        se.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        return false;
    }

    return requestor.didMatch();
}

From source file:com.android.ide.eclipse.traceview.editors.TraceviewEditor.java

License:Apache License

public void handleMethod(MethodData method) {
    // it's a bit complicated to convert the signature we have with what the
    // search engine require, so we'll search by name only and test the signature
    // when we get the result(s).
    String methodName = method.getMethodName();
    String className = method.getClassName().replaceAll("/", "."); //$NON-NLS-1$  //$NON-NLS-21$
    String fqmn = className + "." + methodName; //$NON-NLS-1$

    try {/*  ww w . java 2s  .c  o  m*/
        SearchEngine se = new SearchEngine();
        se.search(
                SearchPattern.createPattern(fqmn, IJavaSearchConstants.METHOD,
                        IJavaSearchConstants.DECLARATIONS,
                        SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE),
                new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                SearchEngine.createWorkspaceScope(), new TraceSearchRequestor(method),
                new NullProgressMonitor());
    } catch (CoreException e) {

    }
}

From source file:com.arcbees.gwtp.plugin.core.presenter.CreatePresenterPage.java

License:Apache License

private List<ResolvedSourceType> findClassName(String name) {
    int searchFor = IJavaSearchConstants.CLASS;
    int limitTo = IJavaSearchConstants.TYPE;
    int matchRule = SearchPattern.R_EXACT_MATCH;
    SearchPattern searchPattern = SearchPattern.createPattern(name, searchFor, limitTo, matchRule);

    IJavaElement[] elements = new IJavaElement[] { getJavaProject() };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    final List<ResolvedSourceType> found = new ArrayList<ResolvedSourceType>();
    SearchRequestor requestor = new SearchRequestor() {
        @Override/*  ww w .  j  a v  a2s  . co  m*/
        public void acceptSearchMatch(SearchMatch match) {
            // TODO
            System.out.println(match);
            Object element = match.getElement();
            found.add((ResolvedSourceType) element);
        }
    };

    SearchEngine searchEngine = new SearchEngine();
    SearchParticipant[] particpant = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    try {
        searchEngine.search(searchPattern, particpant, scope, requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        // TODO
        e.printStackTrace();
    }
    return found;
}

From source file:com.arcbees.gwtp.plugin.core.presenter.CreatePresenterPage.java

License:Apache License

private void selectContentSlot(Text contentSlot) {
    final List<ResolvedSourceField> contentSlots = new ArrayList<ResolvedSourceField>();

    String stringPattern = "ContentSlot";
    int searchFor = IJavaSearchConstants.ANNOTATION_TYPE;
    int limitTo = IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE;
    int matchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern searchPattern = SearchPattern.createPattern(stringPattern, searchFor, limitTo, matchRule);

    IJavaProject project = getJavaProject();
    IJavaElement[] elements = new IJavaElement[] { project };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    SearchRequestor requestor = new SearchRequestor() {
        @Override//from  www  .  j  a  v a 2 s  .  c o m
        public void acceptSearchMatch(SearchMatch match) {
            // TODO
            System.out.println(match);

            ResolvedSourceField element = (ResolvedSourceField) match.getElement();
            contentSlots.add(element);
        }
    };

    SearchEngine searchEngine = new SearchEngine();
    SearchParticipant[] particpant = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
    try {
        searchEngine.search(searchPattern, particpant, scope, requestor, new NullProgressMonitor());
    } catch (CoreException e) {
        // TODO
        e.printStackTrace();
    }

    ResolvedSourceField[] contentListArray = new ResolvedSourceField[contentSlots.size()];
    contentSlots.toArray(contentListArray);

    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new ILabelProvider() {
        @Override
        public void addListener(ILabelProviderListener listener) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            ResolvedSourceField rsf = (ResolvedSourceField) element;
            String name = rsf.getElementName();
            IType type = rsf.getDeclaringType();
            return type.getElementName() + "." + name;
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void removeListener(ILabelProviderListener listener) {
        }
    });

    dialog.setElements(contentListArray);
    dialog.setTitle("Choose A Content Slot");

    // User pressed cancel
    if (dialog.open() != Window.OK) {
        contentSlot.setText("");
        return;
    }

    Object[] result = dialog.getResult();
    if (result == null || result.length < 1) {
        contentSlot.setText("");
    } else {
        ResolvedSourceField rsf = (ResolvedSourceField) result[0];
        contentSlot.setText(rsf.readableName());
        stringMap.put("contentSlotImport", "import " + rsf.getDeclaringType().getFullyQualifiedName() + ";");
    }
}