1 11 package org.eclipse.jdt.internal.corext.util; 12 13 import org.eclipse.jdt.core.ICompilationUnit; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.JavaCore; 16 import org.eclipse.jdt.core.search.SearchEngine; 17 import org.eclipse.jdt.core.search.SearchMatch; 18 import org.eclipse.jdt.core.search.SearchParticipant; 19 import org.eclipse.jdt.core.search.SearchPattern; 20 21 public class SearchUtils { 22 23 27 public static IJavaElement getEnclosingJavaElement(SearchMatch match) { 28 Object element = match.getElement(); 29 if (element instanceof IJavaElement) 30 return (IJavaElement) element; 31 else 32 return null; 33 } 34 35 39 public static ICompilationUnit getCompilationUnit(SearchMatch match) { 40 IJavaElement enclosingElement = getEnclosingJavaElement(match); 41 if (enclosingElement != null){ 42 if (enclosingElement instanceof ICompilationUnit) 43 return (ICompilationUnit) enclosingElement; 44 ICompilationUnit cu= (ICompilationUnit) enclosingElement.getAncestor(IJavaElement.COMPILATION_UNIT); 45 if (cu != null) 46 return cu; 47 } 48 49 IJavaElement jElement= JavaCore.create(match.getResource()); 50 if (jElement != null && jElement.exists() && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) 51 return (ICompilationUnit) jElement; 52 return null; 53 } 54 55 public static SearchParticipant[] getDefaultSearchParticipants() { 56 return new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; 57 } 58 59 63 public final static int GENERICS_AGNOSTIC_MATCH_RULE= SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH; 64 65 71 public static boolean isCamelCasePattern(String pattern) { 72 return SearchPattern.validateMatchRule( 73 pattern, 74 SearchPattern.R_CAMELCASE_MATCH) == SearchPattern.R_CAMELCASE_MATCH; 75 } 76 } | Popular Tags |