List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants IGNORE_DECLARING_TYPE
int IGNORE_DECLARING_TYPE
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants IGNORE_DECLARING_TYPE.
Click Source Link
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void handleFindAll(String proj, String file, int start, int end, boolean defs, boolean refs, boolean impls, boolean equiv, boolean exact, boolean system, boolean typeof, boolean ronly, boolean wonly, IvyXmlWriter xw) throws BedrockException { IJavaProject ijp = getJavaProject(proj); IPath fp = new Path(file); int limit = 0; if (defs && refs) limit = IJavaSearchConstants.ALL_OCCURRENCES; else if (defs) limit = IJavaSearchConstants.DECLARATIONS; else if (refs) limit = IJavaSearchConstants.REFERENCES; int flimit = limit; if (ronly)//w w w . j ava2 s .c o m flimit = IJavaSearchConstants.READ_ACCESSES; else if (wonly) flimit = IJavaSearchConstants.WRITE_ACCESSES; int mrule = -1; if (equiv) mrule = SearchPattern.R_EQUIVALENT_MATCH; else if (exact) mrule = SearchPattern.R_EXACT_MATCH; SearchPattern pat = null; IJavaSearchScope scp = null; ICompilationUnit icu = our_plugin.getProjectManager().getCompilationUnit(proj, file); if (icu == null) throw new BedrockException("Compilation unit not found for " + fp); icu = getCompilationElement(icu); ICompilationUnit[] working = null; FindFilter filter = null; IJavaElement cls = null; char[] packagename = null; char[] typename = null; try { BedrockPlugin.logD("Getting search scopes"); IJavaElement[] pelt; if (ijp != null) pelt = new IJavaElement[] { ijp }; else pelt = getAllProjects(); working = getWorkingElements(pelt); int fg = IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; if (system) fg |= IJavaSearchScope.SYSTEM_LIBRARIES | IJavaSearchScope.APPLICATION_LIBRARIES; scp = SearchEngine.createJavaSearchScope(pelt, fg); BedrockPlugin.logD("Locating item to search for"); IJavaElement[] elts = icu.codeSelect(start, end - start); if (typeof) { Set<IJavaElement> nelt = new LinkedHashSet<IJavaElement>(); for (int i = 0; i < elts.length; ++i) { IType typ = null; String tnm = null; switch (elts[i].getElementType()) { case IJavaElement.FIELD: tnm = ((IField) elts[i]).getTypeSignature(); break; case IJavaElement.LOCAL_VARIABLE: tnm = ((ILocalVariable) elts[i]).getTypeSignature(); break; case IJavaElement.METHOD: typ = ((IMethod) elts[i]).getDeclaringType(); break; default: nelt.add(elts[i]); break; } if (typ != null) nelt.add(typ); else if (tnm != null && ijp != null) { IJavaElement elt = ijp.findElement(tnm, null); if (elt != null) { nelt.add(elt); typ = null; } else { while (tnm.startsWith("[")) { String xtnm = tnm.substring(1); if (xtnm == null) break; tnm = xtnm; } int ln = tnm.length(); String xtnm = tnm; if (tnm.startsWith("L") && tnm.endsWith(";")) { xtnm = tnm.substring(1, ln - 1); } else if (tnm.startsWith("Q") && tnm.endsWith(";")) { xtnm = tnm.substring(1, ln - 1); } if (xtnm != null) tnm = xtnm; int idx1 = tnm.lastIndexOf("."); if (idx1 > 0) { String pkgnm = tnm.substring(0, idx1); xtnm = tnm.substring(idx1 + 1); if (xtnm != null) tnm = xtnm; pkgnm = pkgnm.replace('$', '.'); packagename = pkgnm.toCharArray(); } tnm = tnm.replace('$', '.'); typename = tnm.toCharArray(); } if (typename != null) { BedrockPlugin.logD("Handling type names"); FindTypeHandler fth = new FindTypeHandler(ijp); SearchEngine se = new SearchEngine(working); se.searchAllTypeNames(packagename, SearchPattern.R_EXACT_MATCH, typename, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, scp, fth, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); nelt.addAll(fth.getFoundItems()); } } } IJavaElement[] nelts = new IJavaElement[nelt.size()]; elts = nelt.toArray(nelts); } if (elts.length == 1 && !typeof) { xw.begin("SEARCHFOR"); switch (elts[0].getElementType()) { case IJavaElement.FIELD: xw.field("TYPE", "Field"); break; case IJavaElement.LOCAL_VARIABLE: xw.field("TYPE", "Local"); break; case IJavaElement.METHOD: xw.field("TYPE", "Function"); break; case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: xw.field("TYPE", "Class"); cls = elts[0]; break; } xw.text(elts[0].getElementName()); xw.end("SEARCHFOR"); } int etyp = -1; for (int i = 0; i < elts.length; ++i) { SearchPattern sp; int xlimit = limit; switch (elts[i].getElementType()) { case IJavaElement.FIELD: case IJavaElement.LOCAL_VARIABLE: xlimit = flimit; break; case IJavaElement.TYPE: if (impls) xlimit = IJavaSearchConstants.IMPLEMENTORS; break; case IJavaElement.METHOD: if (impls) xlimit |= IJavaSearchConstants.IGNORE_DECLARING_TYPE; break; } if (mrule < 0) sp = SearchPattern.createPattern(elts[i], xlimit); else sp = SearchPattern.createPattern(elts[i], xlimit, mrule); if (pat == null) pat = sp; else pat = SearchPattern.createOrPattern(pat, sp); if (etyp < 0) etyp = elts[i].getElementType(); } if (etyp == IJavaElement.METHOD) { if (impls) { if (defs) filter = new ImplementFilter(elts); } else if (defs && !refs) filter = new ClassFilter(elts); } } catch (JavaModelException e) { BedrockPlugin.logE("SEARCH PROBLEM: " + e); e.printStackTrace(); throw new BedrockException("Can't find anything to search for", e); } if (pat == null) { BedrockPlugin.logW("Nothing to search for"); return; } BedrockPlugin.logD("Setting up search"); SearchEngine se = new SearchEngine(working); SearchParticipant[] parts = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; FindHandler fh = new FindHandler(xw, filter, false); BedrockPlugin.logD( "BEGIN SEARCH " + pat + " " + parts.length + " " + " " + scp + " :: COPIES: " + working.length); try { se.search(pat, parts, scp, fh, null); } catch (Throwable e) { throw new BedrockException("Problem doing find all search for " + pat + ": " + e, e); } if (cls != null && defs) { // need to add the actual class definition BedrockUtil.outputJavaElement(cls, false, xw); } }
From source file:net.harawata.mybatipse.mybatis.TypeAliasCache.java
License:Open Source License
/** * <p>/*from ww w . j a v a2 s .c o m*/ * Trying to find calls registering type aliases.<br> * But only simple calls can be supported. * </p> */ private void scanJavaConfig(IJavaProject project, final TypeAliasMap aliasMap, final Set<String> packages, IReporter reporter) { try { IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { project }, IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS | IJavaSearchScope.APPLICATION_LIBRARIES); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; SearchEngine searchEngine = new SearchEngine(); final Set<ITypeRoot> typeRoots = new HashSet<ITypeRoot>(); // Collect classes that contain mybatis-guice calls. IType mybatisModuleType = project.findType(GUICE_MODULE_FQN); if (mybatisModuleType == null || !mybatisModuleType.exists()) return; IMethod addSimpleAliasMethod = mybatisModuleType.getMethod("addSimpleAlias", new String[] { "Ljava.lang.Class;" }); SearchPattern pattern = SearchPattern.createPattern(addSimpleAliasMethod, IJavaSearchConstants.REFERENCES | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IMPLEMENTORS); searchEngine.search(pattern, participants, scope, new MethodSearchRequestor(typeRoots), null); IMethod addSimpleAliasesMethodWithPackage = mybatisModuleType.getMethod("addSimpleAliases", new String[] { "Ljava.lang.String;" }); pattern = SearchPattern.createPattern(addSimpleAliasesMethodWithPackage, IJavaSearchConstants.REFERENCES | IJavaSearchConstants.IGNORE_DECLARING_TYPE); searchEngine.search(pattern, participants, scope, new MethodSearchRequestor(typeRoots), null); // IMethod addSimpleAliasesMethodWithPackageAndTest = mybatisModuleType.getMethod( // "addSimpleAliases", new String[]{ // "Ljava.util.Collection<Ljava.lang.Class<*>;>;" // }); // pattern = SearchPattern.createPattern(addSimpleAliasesMethodWithPackageAndTest, // IJavaSearchConstants.REFERENCES | IJavaSearchConstants.IGNORE_DECLARING_TYPE); // searchEngine.search(pattern, participants, scope, new MethodSearchRequestor(typeRoots), // null); // Searches Spring java config if necessary. // if (typeRoots.isEmpty()) // { // IType sqlSessionFactoryBeanType = project.findType(SPRING_BEAN_FQN); // if (sqlSessionFactoryBeanType == null || !sqlSessionFactoryBeanType.exists()) // return; // // IMethod setTypeAliasesPackageMethod = sqlSessionFactoryBeanType.getMethod( // "setTypeAliasesPackage", new String[]{ // "Ljava.lang.String;" // }); // pattern = SearchPattern.createPattern(setTypeAliasesPackageMethod, // IJavaSearchConstants.REFERENCES | IJavaSearchConstants.IGNORE_DECLARING_TYPE // | IJavaSearchConstants.IMPLEMENTORS); // searchEngine.search(pattern, participants, scope, new MethodSearchRequestor(typeRoots), // null); // } for (ITypeRoot typeRoot : typeRoots) { ASTParser parser = ASTParser.newParser(AST.JLS4); parser.setSource(typeRoot); parser.setResolveBindings(true); CompilationUnit astUnit = (CompilationUnit) parser.createAST(null); astUnit.accept(new JavaConfigVisitor(aliasMap, packages)); } } catch (JavaModelException e) { Activator.log(Status.ERROR, e.getMessage(), e); } catch (CoreException e) { Activator.log(Status.ERROR, e.getMessage(), e); } }
From source file:org.eclipse.ajdt.internal.ui.refactoring.RippleMethodFinder2.java
License:Open Source License
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException { fDeclarations = new ArrayList(); class MethodRequestor extends SearchRequestor { public void acceptSearchMatch(SearchMatch match) throws CoreException { IMethod method = (IMethod) match.getElement(); boolean isBinary = method.isBinary(); if (fBinaryRefs != null || !(fExcludeBinaries && isBinary)) { fDeclarations.add(method); }/*from www.jav a2s . c o m*/ if (isBinary && fBinaryRefs != null) { fDeclarationToMatch.put(method, match); } } } int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE; int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule); SearchParticipant[] participants = SearchUtils.getDefaultSearchParticipants(); IJavaSearchScope scope = RefactoringScopeFactory.createRelatedProjectsScope(fMethod.getJavaProject(), IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES); MethodRequestor requestor = new MethodRequestor(); SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine(); searchEngine.search(pattern, participants, scope, requestor, monitor); }
From source file:org.eclipse.xtext.xbase.ui.navigation.JvmImplementationOpener.java
License:Open Source License
/** * Main parts of the logic is taken from {@link org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink} * * @param element - Element to show implementations for * @param textviewer - Viewer to show hierarchy view on * @param region - Region where to show hierarchy view *///from w ww . java 2 s .c o m public void openImplementations(final IJavaElement element, ITextViewer textviewer, IRegion region) { if (element instanceof IMethod) { ITypeRoot typeRoot = ((IMethod) element).getTypeRoot(); CompilationUnit ast = SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null); if (ast == null) { openQuickHierarchy(textviewer, element, region); return; } try { ISourceRange nameRange = ((IMethod) element).getNameRange(); ASTNode node = NodeFinder.perform(ast, nameRange); ITypeBinding parentTypeBinding = null; if (node instanceof SimpleName) { ASTNode parent = node.getParent(); if (parent instanceof MethodInvocation) { Expression expression = ((MethodInvocation) parent).getExpression(); if (expression == null) { parentTypeBinding = Bindings.getBindingOfParentType(node); } else { parentTypeBinding = expression.resolveTypeBinding(); } } else if (parent instanceof SuperMethodInvocation) { // Directly go to the super method definition openEditor(element); return; } else if (parent instanceof MethodDeclaration) { parentTypeBinding = Bindings.getBindingOfParentType(node); } } final IType type = parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null; if (type == null) { openQuickHierarchy(textviewer, element, region); return; } final String earlyExitIndicator = "EarlyExitIndicator"; final ArrayList<IJavaElement> links = Lists.newArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor == null) { monitor = new NullProgressMonitor(); } try { String methodLabel = JavaElementLabels.getElementLabel(element, JavaElementLabels.DEFAULT_QUALIFIED); monitor.beginTask( Messages.format("Searching for implementors of ''{0}''", methodLabel), 100); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE) { IJavaElement element = (IJavaElement) match.getElement(); if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod) element)) { links.add(element); if (links.size() > 1) { throw new OperationCanceledException(earlyExitIndicator); } } } } }; int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE; SearchPattern pattern = SearchPattern.createPattern(element, limitTo); Assert.isNotNull(pattern); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; SearchEngine engine = new SearchEngine(); engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, new SubProgressMonitor(monitor, 100)); if (monitor.isCanceled()) { throw new InterruptedException(); } } catch (OperationCanceledException e) { throw new InterruptedException(e.getMessage()); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, Messages.format( "An error occurred while searching for implementations of method ''{0}''. See error log for details.", element.getElementName()), e.getCause()); JavaPlugin.log(status); ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Implementation", "Problems finding implementations.", status); } catch (InterruptedException e) { if (e.getMessage() != earlyExitIndicator) { return; } } if (links.size() == 1) { openEditor(links.get(0)); } else { openQuickHierarchy(textviewer, element, region); } } catch (JavaModelException e) { log.error("An error occurred while searching for implementations", e.getCause()); } catch (PartInitException e) { log.error("An error occurred while searching for implementations", e.getCause()); } } }
From source file:org.jboss.tools.batch.ui.participants.BatchArtifactSearchParticipant.java
License:Open Source License
public boolean isSearchForReferences(int limitTo) { int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); if (maskedLimitTo == IJavaSearchConstants.REFERENCES || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) { return true; }/* w ww .j a v a2 s. c o m*/ return false; }
From source file:org.jboss.tools.jst.web.kb.refactoring.ELReferencesQueryParticipant.java
License:Open Source License
public boolean isSearchForReferences(int limitTo) { int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); return maskedLimitTo == IJavaSearchConstants.REFERENCES || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES; }
From source file:org.jboss.tools.seam.ui.search.SeamSearchEngine.java
License:Open Source License
/** * Checks if the given limitTo flag is limited to declarations * /*from w ww . j av a 2 s . c om*/ * @param limitTo * @return */ public static boolean isSearchForDeclarations(int limitTo) { int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); if (maskedLimitTo == IJavaSearchConstants.DECLARATIONS || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) { return true; } return false; }
From source file:org.jboss.tools.seam.ui.search.SeamSearchEngine.java
License:Open Source License
/** * Checks if the given limitTo flag is limited to references * //from w ww . j a v a2s . co m * @param limitTo * @return */ public static boolean isSearchForReferences(int limitTo) { int maskedLimitTo = limitTo & ~(IJavaSearchConstants.IGNORE_DECLARING_TYPE + IJavaSearchConstants.IGNORE_RETURN_TYPE); if (maskedLimitTo == IJavaSearchConstants.REFERENCES || maskedLimitTo == IJavaSearchConstants.ALL_OCCURRENCES) { return true; } return false; }