List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS
int DECLARATIONS
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants DECLARATIONS.
Click Source Link
From source file:org.jboss.tools.common.text.ext.hyperlink.ClassHyperlink.java
License:Open Source License
private IJavaElement searchForClass(IJavaProject javaProject, String className) throws JavaModelException { // Get the search pattern SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // Get the search scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final List<SearchMatch> matches = new ArrayList<SearchMatch>(); // Get the search requestor SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { matches.add(match);/* ww w . j a v a2 s . c om*/ } }; // Search SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException ex) { // Ignore // ExtensionsPlugin.log(ex); } for (Iterator i = matches.iterator(); i != null && i.hasNext();) { IJavaElement element = (IJavaElement) ((SearchMatch) i.next()).getElement(); String classQualifiedName = getQualifiedClassName(element); if (className.equals(classQualifiedName)) return element; } return javaProject.findType(className, new NullProgressMonitor()); }
From source file:org.jboss.tools.common.text.ext.hyperlink.ClassMethodHyperlink.java
License:Open Source License
protected IJavaElement searchForClassMethod(IJavaProject javaProject, String className, String methodName) { // Get the search pattern SearchPattern pattern = SearchPattern.createPattern(className + "." + methodName, //$NON-NLS-1$ IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // Get the search scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final List<SearchMatch> matches = new ArrayList<SearchMatch>(); // Get the search requestor SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { matches.add(match);// w ww.j ava2s . c o m } }; // Search SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException ex) { // ignore } for (Iterator i = matches.iterator(); i != null && i.hasNext();) { return (IJavaElement) ((SearchMatch) i.next()).getElement(); } return null; }
From source file:org.jboss.tools.jst.jsp.util.FileUtil.java
License:Open Source License
public static IJavaElement searchForClass(IJavaProject javaProject, String className) throws JavaModelException { // Get the search pattern SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // Get the search scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final List<SearchMatch> matches = new ArrayList<SearchMatch>(INITIAL_CAPACITY); // Get the search requestor SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { matches.add(match);// w ww . j a va 2 s . co m } }; // Search SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException ex) { JspEditorPlugin.getPluginLog().logError(ex); } for (SearchMatch match : matches) { IJavaElement element = (IJavaElement) match.getElement(); if (element instanceof IType && className.equals(((IType) element).getFullyQualifiedName('.'))) { return element; } } return javaProject.findType(className, new NullProgressMonitor()); }
From source file:org.jboss.tools.jst.web.ui.internal.editor.util.FileUtil.java
License:Open Source License
public static IJavaElement searchForClass(IJavaProject javaProject, String className) throws JavaModelException { // Get the search pattern SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // Get the search scope IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final List<SearchMatch> matches = new ArrayList<SearchMatch>(INITIAL_CAPACITY); // Get the search requestor SearchRequestor requestor = new SearchRequestor() { public void acceptSearchMatch(SearchMatch match) throws CoreException { matches.add(match);//from w w w. j a v a2 s . c o m } }; // Search SearchEngine searchEngine = new SearchEngine(); try { searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException ex) { WebUiPlugin.getPluginLog().logError(ex); } for (SearchMatch match : matches) { IJavaElement element = (IJavaElement) match.getElement(); if (element instanceof IType && className.equals(((IType) element).getFullyQualifiedName('.'))) { return element; } } return javaProject.findType(className, new NullProgressMonitor()); }
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 w w . j a v a 2s .c o m * @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.SeamSearchVisitor.java
License:Open Source License
public boolean processSeamDeclarationsInProject(ISeamProject project) { if (fJavaMatchers != null && fJavaMatchers.length > 0) { JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance(); IJavaSearchScope scope = factory.createWorkspaceScope(true); String description = factory.getWorkspaceScopeDescription(true); for (int i = 0; i < fJavaMatchers.length; i++) { ElementQuerySpecification elementQuerySpecification = new ElementQuerySpecification( fJavaMatchers[i].getElement(), IJavaSearchConstants.DECLARATIONS, scope, description); JavaSearchQuery query = new JavaSearchQuery(elementQuerySpecification); query.run(fProgressMonitor); JavaSearchResult result = (JavaSearchResult) query.getSearchResult(); Object[] elements = result.getElements(); for (int j = 0; elements != null && j < elements.length; j++) { Match[] matches = result.getMatches(elements[j]); for (int k = 0; matches != null && k < matches.length; k++) { fCollector.reportMatch(matches[k]); }// www. ja v a2 s .c o m } } } if (fVariableMatchers != null && fVariableMatchers.length > 0) { try { for (int i = 0; i < fVariableMatchers.length; i++) { if (fVariableMatchers[i] == null) continue; ISeamContextVariable variable = fVariableMatchers[i].getElement(); if (variable instanceof ISeamContextShortVariable) { variable = ((ISeamContextShortVariable) variable).getOriginal(); } boolean continueWithFactories = true; if (variable instanceof SeamComponent) { SeamComponent comp = (SeamComponent) variable; Set<ISeamComponentDeclaration> declarations = comp.getAllDeclarations(); for (ISeamComponentDeclaration decl : declarations) { if (decl instanceof IJavaSourceReference) { IJavaSourceReference sourceRef = (IJavaSourceReference) decl; IResource resource = sourceRef.getSourceMember().getResource(); IJavaElement sourceMember = sourceRef.getSourceMember(); String name = sourceRef.getSourceMember().getElementName(); int offset = sourceRef.getStartPosition(); int length = sourceRef.getLength(); //fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name); boolean res = fCollector.acceptSeamDeclarationSourceReferenceMatch(sourceRef); if (!res) { return true; // no further reporting requested } continueWithFactories = false; } else if (decl instanceof IOpenableElement) { IResource resource = decl.getResource(); String name = decl.getName(); ITextSourceReference textSourceReference = decl .getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME); if (textSourceReference != null) { int offset = textSourceReference.getStartPosition(); int length = textSourceReference.getLength(); boolean res = fCollector.acceptSeamDeclarationMatch(decl); if (!res) { return true; // no further reporting requested } continueWithFactories = false; } else { int offset = decl.getStartPosition(); int length = decl.getLength(); fMatchAccess.initialize((IFile) resource, offset, length, (CharSequence) name); boolean res = fCollector.acceptPatternMatch(fMatchAccess); if (!res) { return true; // no further reporting requested } continueWithFactories = false; } } } } else if (variable instanceof IRole) { // add the declaration ISeamDeclaration decl = (ISeamDeclaration) variable; IResource resource = decl.getResource(); String name = decl.getName(); ITextSourceReference textSourceReference = decl .getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME); if (textSourceReference != null) { int offset = textSourceReference.getStartPosition(); int length = textSourceReference.getLength(); fMatchAccess.initialize((IFile) resource, offset, length, (CharSequence) name); boolean res = fCollector.acceptPatternMatch(fMatchAccess); if (!res) { return true; // no further reporting requested } continueWithFactories = false; } } else if (variable instanceof IBijectedAttribute) { IBijectedAttribute ba = (IBijectedAttribute) variable; BijectedAttributeType[] types = ba.getTypes(); boolean hasDeclarationType = false; for (int j = 0; !hasDeclarationType && types != null && j < types.length; j++) { if (types[j] == BijectedAttributeType.OUT || types[j] == BijectedAttributeType.DATA_BINDER || types[j] == BijectedAttributeType.DATA_MODEL_SELECTION) { hasDeclarationType = true; } } if (hasDeclarationType) { // add the declaration ISeamDeclaration decl = (ISeamDeclaration) variable; IResource resource = decl.getResource(); String name = decl.getName(); ITextSourceReference textSourceReference = decl .getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME); if (textSourceReference != null) { int offset = textSourceReference.getStartPosition(); int length = textSourceReference.getLength(); fMatchAccess.initialize((IFile) resource, offset, length, (CharSequence) name); boolean res = fCollector.acceptPatternMatch(fMatchAccess); if (!res) { return true; // no further reporting requested } continueWithFactories = false; } } } // Search for Seam factories if (continueWithFactories && variable instanceof ISeamDeclaration) { ISeamDeclaration decl = (ISeamDeclaration) variable; IResource resource = decl.getResource(); String name = decl.getName(); ITextSourceReference textSourceReference = decl .getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME); if (textSourceReference != null) { int offset = textSourceReference.getStartPosition(); int length = textSourceReference.getLength(); boolean res = fCollector.acceptSeamDeclarationMatch(decl); if (!res) { return true; // no further reporting requested } } } } } catch (CoreException ce) { String[] args = { getExceptionMessage(ce), project.getResource().getFullPath().makeRelative().toString() }; String message = Messages.format(SearchMessages.TextSearchVisitor_error, args); fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, ce)); } } if (fProgressMonitor.isCanceled()) throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled); return true; }
From source file:org.key_project.sed.key.ui.jdt.AllOperationsSearchEngine.java
License:Open Source License
/** * Searches all methods and constructors. * @param pm The {@link IProgressMonitor} to use. * @param scope The {@link IJavaSearchScope} to search in. * @return The found {@link IMethod}s./* w ww.ja va 2s .co m*/ */ public IMethod[] searchOperations(IProgressMonitor pm, IJavaSearchScope scope) { pm.beginTask("Searching for methods...", 100); int searchTicks = 100; SearchPattern constructorPattern = SearchPattern.createPattern("*", IJavaSearchConstants.CONSTRUCTOR, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchPattern methodPattern = SearchPattern.createPattern("*", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchPattern pattern = SearchPattern.createOrPattern(constructorPattern, methodPattern); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; MethodCollector collector = new MethodCollector(); IProgressMonitor searchMonitor = new SubProgressMonitor(pm, searchTicks); try { new SearchEngine().search(pattern, participants, scope, collector, searchMonitor); } catch (CoreException ce) { LogUtil.getLogger().logError(ce); } List<IMethod> result = collector.getResult(); return result.toArray(new IMethod[result.size()]); }
From source file:org.limy.eclipse.code.di.LimyDIUtils.java
License:Open Source License
/** * JavaNXC^?[tFCX\?[X?B/* w w w . jav a 2 s. c o m*/ * @param type JavaNX * @return C^?[tFCX\?[X * @throws IOException I/OO * @throws CoreException RAO */ public static IResource getInterfaceResource(IType type) throws IOException, CoreException { IPath path = type.getPath(); String fileName = path.removeFileExtension().lastSegment(); IResource targetResource = null; if (fileName.endsWith("Impl")) { // NX?Impl?A?O\?[XT path = path.removeLastSegments(1); path = path.append(fileName.substring(0, fileName.length() - 4) + ".java"); targetResource = LimyResourceUtils.newFile(path); } if (targetResource == null || !targetResource.exists()) { // implements?\?[XT String[] names = type.getSuperInterfaceNames(); if (names.length > 0) { SearchPattern pattern = SearchPattern.createPattern("*" + names[0], IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); IJavaSearchScope scope = SearchEngine.createHierarchyScope(type); SearchEngine searchEngine = new SearchEngine(); LimySearchRequestor requestor = new LimySearchRequestor(); searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); if (requestor.getMatch() != null) { targetResource = requestor.getMatch().getResource(); } } } return targetResource.exists() ? targetResource : null; }
From source file:org.oobium.build.console.Eclipse.java
License:Open Source License
public static void openType(String type, final int line) { if (type.contains("$")) { // handles inner classes type = type.substring(0, type.indexOf('$')); }// ww w. ja va2s . com SearchPattern pattern = SearchPattern.createPattern(type, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchRequestor sr = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { IResource resource = match.getResource(); if (resource instanceof IFile) { final IFile file = (IFile) match.getResource(); logger.debug(String.valueOf(match)); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { open(file, null, line); } }); } else { Object element = match.getElement(); if (element instanceof IType) { final IType itype = (IType) element; Display.getDefault().asyncExec(new Runnable() { @Override public void run() { Object parent = itype.getParent(); if (parent instanceof IFile) { open(parent, null, line); } if (parent instanceof IClassFile) { // TODO is there a better way to do this? IEditorInput input = EditorUtility.getEditorInput(itype.getParent()); open(input, "org.eclipse.jdt.ui.ClassFileEditor", line); } } }); } } } }; SearchEngine engine = new SearchEngine(); try { engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, sr, null); } catch (CoreException e) { e.printStackTrace(); } }
From source file:org.spoofax.interpreter.library.ecj.ECJ_search_for_type.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; final String className = Tools.asJavaString(tvars[1]); SearchPattern sp = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); IJavaSearchScope ss = SearchEngine//from ww w . jav a 2 s . c o m .createJavaSearchScope(new IJavaElement[] { ECJTools.asIJavaElement(tvars[0]) }); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // TODO Auto-generated method stub throw new NotImplementedException(); } }; SearchEngine se = new SearchEngine(); try { se.search(sp, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, ss, requestor, null); } catch (CoreException e) { e.printStackTrace(); return false; } return true; }