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.eclipselabs.collage.model.resourceid.JavaClassFileIdentifier.java
License:Open Source License
@Override public IEditorPart openInEditor() throws CoreException { synchronized (foundElementLock) { if (foundElement == null) { SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); ClassFileSearchRequestor requestor = new ClassFileSearchRequestor(); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requestor, new NullProgressMonitor()); foundElement = requestor.getElement(); }/* w ww. j av a 2s . c o m*/ if (foundElement != null) { return JavaUI.openInEditor(foundElement); } } CollageUtilities.showError(CollageActivator.PLUGIN_NAME, "Unable to open an editor for " + shortName + "."); return null; }
From source file:org.eclipselabs.stlipse.cache.BeanClassCache.java
License:Open Source License
private static synchronized List<BeanClassInfo> getBeanClassCache(IJavaProject javaProject) { final IProject project = javaProject.getProject(); if (beanCache.containsKey(project)) return beanCache.get(project); final List<BeanClassInfo> beanClassList = new CopyOnWriteArrayList<BeanClassInfo>(); beanCache.put(project, beanClassList); try {/*ww w .j a va 2s.c om*/ IType actionBeanInterface = TypeCache.getActionBean(javaProject); if (actionBeanInterface == null) { // It wouldn't be a Stripes project. return beanClassList; } final List<String> packageList = getActionResolverPackages(project); IJavaSearchScope scope = SearchEngine.createHierarchyScope(actionBeanInterface); TypeNameRequestor requestor = new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Ignore abstract classes. if (Flags.isAbstract(modifiers)) return; // Should be in action resolver packages if specified. if (!packageList.isEmpty() && !isInTargetPackage(packageList, String.valueOf(packageName))) return; BeanClassInfo beanClass = new BeanClassInfo(packageName, simpleTypeName); beanClassList.add(beanClass); } private boolean isInTargetPackage(List<String> targetPackages, String packageToTest) { if (targetPackages == null || packageToTest == null) return false; for (String targetPackage : targetPackages) { if (packageToTest.startsWith(targetPackage)) return true; } return false; } }; SearchEngine searchEngine = new SearchEngine(); searchEngine.searchAllTypeNames(null, SearchPattern.R_EXACT_MATCH, null, SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IMPLEMENTORS, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); } catch (CoreException e) { Activator.log(Status.ERROR, "Error occurred while creating proposals.", e); } return beanClassList; }
From source file:org.fusesource.ide.camel.editor.globalconfiguration.beans.BeanConfigUtil.java
License:Open Source License
public boolean hasMethod(String methodName, IType type) { if (type == null) { return false; }//from w ww . j a v a2 s . c om SearchPattern pattern = SearchPattern.createPattern(methodName, IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { type }); CountingSearchRequestor matchCounter = new CountingSearchRequestor(); SearchEngine search = new SearchEngine(); try { search.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, matchCounter, null); } catch (CoreException ce) { CamelEditorUIActivator.pluginLog() .logError(UIMessages.beanConfigUtilMethodSelectionErrorNoTypeFound + ce.getMessage(), ce); } return matchCounter.getNumMatch() > 0; }
From source file:org.fusesource.ide.jvmmonitor.internal.ui.actions.OpenDeclarationAction.java
License:Open Source License
/** * Searches the source for the given class name. * //from ww w . j a va 2s. c o m * @param name * The class name * @return The source * @throws CoreException */ IType doSearchSource(String name) throws CoreException { final List<IType> results = new ArrayList<IType>(); // create requester SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IType) { results.add((IType) element); } } }; String baseName = name.replace('$', '.'); // create search engine and pattern SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(baseName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); // search the source for the given name engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(), requestor, null); if (results.size() > 0) { // at most one source should be found return results.get(0); } return null; }
From source file:org.gemoc.execution.sequential.javaengine.PlainK3ExecutionEngine.java
License:Open Source License
/** * search the bundle that contains the Main class. The search is done in the workspace scope (ie. if it is defined * in the current workspace it will find it * // w w w . j a va 2 s . c o m * @return the name of the bundle containing the Main class or null if not found */ private IType getITypeMainByWorkspaceScope(String className) { SearchPattern pattern = SearchPattern.createPattern(className, IJavaSearchConstants.CLASS, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); final List<IType> binaryType = new ArrayList<IType>(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { binaryType.add((IType) match.getElement()); } }; SearchEngine engine = new SearchEngine(); try { engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); } catch (CoreException e1) { throw new RuntimeException("Error while searching the bundle: " + e1.getMessage()); // return new Status(IStatus.ERROR, Activator.PLUGIN_ID, ); } return binaryType.isEmpty() ? null : binaryType.get(0); }
From source file:org.grails.ide.eclipse.core.junit.Grails20AwareTestFinder.java
License:Open Source License
private void searchForTests(IJavaElement element, final Set result, IProgressMonitor pm) throws CoreException { //Loosely based on a copy of org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder.findTestsInContainer(IJavaElement, Set, IProgressMonitor) //Modifed to search just for Grails test classes marked by @TestFor annotations try {/*from w w w .jav a 2 s . com*/ pm.beginTask(JUnitMessages.JUnit4TestFinder_searching_description, 4); IRegion region = CoreTestSearchEngine.getRegion(element); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(region.getElements(), IJavaSearchScope.SOURCES); int matchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern testForPattern = SearchPattern.createPattern(TEST_FOR_ANNOT_NAME, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, matchRule); SearchPattern testPattern = SearchPattern.createPattern("*Tests", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, matchRule); SearchPattern theSearchPattern = SearchPattern.createOrPattern(testForPattern, testPattern); SearchParticipant[] searchParticipants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { if (match.getAccuracy() == SearchMatch.A_ACCURATE && !match.isInsideDocComment()) { Object element = match.getElement(); if (element instanceof IType && isGrail20Test((IType) element)) { result.add(element); } } } }; new SearchEngine().search(theSearchPattern, searchParticipants, scope, requestor, new SubProgressMonitor(pm, 2)); } finally { pm.done(); } }
From source file:org.grails.ide.eclipse.editor.gsp.search.GSPUISearchRequestor.java
License:Open Source License
private List<IFile> initializeGspsToSearch() { if (spec.getScope() instanceof HierarchyScope) { return Collections.emptyList(); }// w w w . j ava2 s . c om if (spec.getLimitTo() == IJavaSearchConstants.DECLARATIONS) { // assume no declarations are in gsps return Collections.emptyList(); } List<IProject> allGrailsProjects = findAllGrailsProjects(); List<IFile> results = new ArrayList<IFile>(); for (IProject grailsProject : allGrailsProjects) { IFolder viewsFolder = grailsProject.getFolder("grails-app/views"); // urrrgh...I don't know how to check to see if the gsps should be included // we will assume that if the controller folder is included, then gsps will be searched if (viewsFolder.exists() && spec.getScope() .encloses(grailsProject.getFolder("grails-app/controllers").getFullPath().toPortableString())) { List<IFile> foundGsps = findGspsInContainer(viewsFolder, spec.getScope()); if (foundGsps != null) { results.addAll(foundGsps); } } } return results; }
From source file:org.jboss.byteman.eclipse.validation.BytemanJavaValidator.java
License:Open Source License
@Check(CheckType.FAST) public void checkMethodClause(EventMethod eventMethod) { // delete any previous cache of possible trigger methods getContext().remove(RULE_METHOD_KEY); String methodName = eventMethod.getName(); // we can only check the method if we already know the possible classes List<TypeSearchResult> types = (List<TypeSearchResult>) getContext().get(RULE_CLASS_KEY); if (types == null) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else if (methodName.equals("<clinit>")) { // cannot verify presence of <clinit> via search // just check it has no arguments ParameterTypes parameterTypes = eventMethod.getParameterTypes(); if (parameterTypes != null) { EList<String> paramTypeNames = parameterTypes.getParamTypeNames(); int paramTypeCount = paramTypeNames.size(); if (paramTypeCount != 0) { error("invalid parameter types for class initializer" + methodName, BytemanPackage.eINSTANCE.getEventMethod_ParameterTypes()); }/* ww w .j a va 2 s. c om*/ } } else { boolean isConstructor = methodName.equals("<init>"); // look for methods on each of the possible types ParameterTypes parameterTypes = eventMethod.getParameterTypes(); EList<String> paramTypeNames; int paramTypeCount; if (parameterTypes != null) { paramTypeNames = parameterTypes.getParamTypeNames(); paramTypeCount = paramTypeNames.size(); } else { paramTypeNames = null; // -1 indicates any method with the relevant signature will do // whereas 0 indicates an empty parameter list () paramTypeCount = -1; } final List<MethodSearchResult> methods = new ArrayList<MethodSearchResult>(); // accumulate matching methods SearchEngine searchEngine = new SearchEngine(); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; for (TypeSearchResult result : types) { String typeName = result.name.replace('$', '.'); // now build type qualified method name StringBuilder builder = new StringBuilder(); builder.append(typeName); // append method name to type name except when it is a constructor or class initializer if (!isConstructor) { builder.append('.'); builder.append(methodName); } if (paramTypeCount >= 0) { String separator = ""; builder.append("("); for (int i = 0; i < paramTypeCount; i++) { builder.append(separator); String paramTypeName = paramTypeNames.get(i); // ho hum eclipse doesn't like $ to separate embedded types if (paramTypeName.indexOf('$') > 0) { paramTypeName = paramTypeName.replace('$', '.'); } builder.append(paramTypeName); separator = ","; } builder.append(")"); } final String stringPattern = builder.toString(); int searchFor = (isConstructor ? IJavaSearchConstants.CONSTRUCTOR : IJavaSearchConstants.METHOD); int limitTo = IJavaSearchConstants.DECLARATIONS; int matchType = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern pattern = SearchPattern.createPattern(stringPattern, searchFor, limitTo, matchType); final TypeSearchResult typeResult = result; SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // only accept if we have an accurate match if (match.getAccuracy() == SearchMatch.A_ACCURATE) { MethodSearchResult methodResult = new MethodSearchResult(stringPattern, typeResult, match); methods.add(methodResult); } } }; try { searchEngine.search(pattern, participants, scope, requestor, null); } catch (CoreException e) { // TODO : ho hum not sure if this will happen when we have // no such method or because something is wrong with paths etc // but just ignore for now } } // if we have no matches then plant an error if (methods.isEmpty()) { error("unknown trigger method " + methodName, BytemanPackage.eINSTANCE.getEventMethod_Name()); } else { // cache details of potential trigger methods for current rule getContext().put(RULE_METHOD_KEY, methods); } } }
From source file:org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher.java
License:Open Source License
public ArrayList getPackageProposals() { IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern packagePattern = SearchPattern.createPattern(fullString, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PREFIX_MATCH); if (packagePattern == null) return new ArrayList(); SearchEngine searchEngine = new SearchEngine(); LocalTextfieldSearchRequestor requestor = new LocalTextfieldSearchRequestor(); try {//from ww w . jav a2 s.co m searchEngine.search(packagePattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); ArrayList results = requestor.getResults(); Collections.sort(results, new Comparator() { public int compare(Object o1, Object o2) { if (!(o1 instanceof IPackageFragment)) return 0; if (!(o2 instanceof IPackageFragment)) return 0; IPackageFragment o1a = (IPackageFragment) o1; IPackageFragment o2a = (IPackageFragment) o2; return o1a.getElementName().compareTo(o2a.getElementName()); } }); return results; } catch (CoreException ce) { } return new ArrayList(); }
From source file:org.jboss.ide.eclipse.as.ui.util.PackageTypeSearcher.java
License:Open Source License
public IPackageFragment getPackage() { IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchPattern packagePattern = SearchPattern.createPattern(packageName, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH); if (packagePattern == null) return null; SearchEngine searchEngine = new SearchEngine(); LocalTextfieldSearchRequestor requestor = new LocalTextfieldSearchRequestor(); try {//from w ww . jav a 2 s . co m searchEngine.search(packagePattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, new NullProgressMonitor()); ArrayList results = requestor.getResults(); if (results.size() != 1) // TODO: there can be multiple packagefragments for the same name in a workspace return null; return (IPackageFragment) results.get(0); } catch (CoreException ce) { } return null; }