Java Code Examples for org.eclipse.jdt.core.search.IJavaSearchConstants#METHOD

The following examples show how to use org.eclipse.jdt.core.search.IJavaSearchConstants#METHOD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaQueryParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) {
  // Translate the IJavaSearchConstant element type constants to IJavaElement
  // type constants.
  int elementType;
  switch (query.getSearchFor()) {
    case IJavaSearchConstants.TYPE:
      elementType = IJavaElement.TYPE;
      break;
    case IJavaSearchConstants.FIELD:
      elementType = IJavaElement.FIELD;
      break;
    case IJavaSearchConstants.METHOD:
    case IJavaSearchConstants.CONSTRUCTOR:
      // IJavaElement.METHOD represents both methods & ctors
      elementType = IJavaElement.METHOD;
      break;
    default:
      // We only support searching for types, fields, methods, and ctors
      return Collections.emptySet();
  }

  return JavaRefIndex.getInstance().findElementReferences(query.getPattern(),
      elementType, query.isCaseSensitive());
}
 
Example 2
Source File: JavaMatchFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isApplicable(JavaSearchQuery query) {
       QuerySpecification spec= query.getSpecification();
       switch (spec.getLimitTo()) {
		case IJavaSearchConstants.REFERENCES:
		case IJavaSearchConstants.ALL_OCCURRENCES:
               if (spec instanceof ElementQuerySpecification) {
                   ElementQuerySpecification elementSpec= (ElementQuerySpecification) spec;
                   return elementSpec.getElement() instanceof IMethod;
               } else if (spec instanceof PatternQuerySpecification) {
                   PatternQuerySpecification patternSpec= (PatternQuerySpecification) spec;
                   return patternSpec.getSearchFor() == IJavaSearchConstants.METHOD;
               }
       }
       return false;
   }
 
Example 3
Source File: MatchLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void createMethodFieldMatchLocationsControls(Composite contents) {

			Composite composite= new Composite(contents, SWT.NONE);
			GridData gd= new GridData(SWT.LEFT, SWT.BEGINNING, true, true, 2, 1);
			gd.minimumWidth= convertHorizontalDLUsToPixels(200);
			composite.setLayoutData(gd);
			GridLayout blayout= new GridLayout(1, false);
			blayout.marginWidth= 0;
			blayout.marginHeight= 0;
			composite.setLayout(blayout);

			if (fSearchFor == IJavaSearchConstants.METHOD || fSearchFor == IJavaSearchConstants.FIELD) {
				createButton(composite, SearchMessages.MatchLocations_this_label, IJavaSearchConstants.THIS_REFERENCE);
				createButton(composite, SearchMessages.MatchLocations_implicit_this_label, IJavaSearchConstants.IMPLICIT_THIS_REFERENCE);
	
				createButton(composite, SearchMessages.MatchLocations_super_label, IJavaSearchConstants.SUPER_REFERENCE);
				createButton(composite, SearchMessages.MatchLocations_qualified_label, IJavaSearchConstants.QUALIFIED_REFERENCE);
			}
			
			if (fSearchFor == IJavaSearchConstants.METHOD || fSearchFor == IJavaSearchConstants.CONSTRUCTOR) {
				createButton(composite, SearchMessages.MatchLocations_method_reference_label, IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION);
			}
		}
 
Example 4
Source File: CallerFinder.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
public static Collection/*<MethodDeclarationUnitPair>*/ 
		findCallees(IProgressMonitor progressMonitor, String methodName, IJavaProject project, boolean isConstructor) 
{
	try {
           MethodSearchRequestor.MethodDeclarationsSearchRequestor searchRequestor = 
           	new MethodSearchRequestor.MethodDeclarationsSearchRequestor();
           SearchEngine searchEngine = new SearchEngine();

           IProgressMonitor monitor = new SubProgressMonitor(
           		progressMonitor, 5, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
           monitor.beginTask("Searching for declaration of " + methodName +
           		(project != null ? " in " + project.getProject().getName() : ""), 100);
           IJavaSearchScope searchScope = getSearchScope(project);
           int matchType = !isConstructor ? IJavaSearchConstants.METHOD : IJavaSearchConstants.CONSTRUCTOR;
           SearchPattern pattern = SearchPattern.createPattern(
           		methodName, 
				matchType,
				IJavaSearchConstants.DECLARATIONS, 
				SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE );
           
           searchEngine.search(
           		pattern, 
				new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                   searchScope, 
				searchRequestor, 
				monitor
				);
           monitor.done();

           return searchRequestor.getMethodUnitPairs();
       } catch (CoreException e) {
           JavaPlugin.log(e);

           return new LinkedList();
       }
}
 
Example 5
Source File: CallerFinder.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
public static Collection/*<MethodUnitPair>*/ findDeclarations(IProgressMonitor progressMonitor, String methodName, IJavaProject project, boolean isConstructor) {
    try {
        SearchRequestor searchRequestor = new MethodSearchRequestor.MethodDeclarationsSearchRequestor(); 
        SearchEngine searchEngine = new SearchEngine();

        IProgressMonitor monitor = new SubProgressMonitor(
                progressMonitor, 5, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
        monitor.beginTask("Searching for calls to " + 
                methodName + (project != null ? " in " + project.getProject().getName() : ""), 100);            
        IJavaSearchScope searchScope = getSearchScope(project);
        // This is kind of hacky: we need to make up a string name for the search to work right
        log("Looking for " + methodName);
        int matchType = !isConstructor ? IJavaSearchConstants.METHOD : IJavaSearchConstants.CONSTRUCTOR;
        SearchPattern pattern = SearchPattern.createPattern(
                methodName, 
                matchType,
                IJavaSearchConstants.DECLARATIONS,
                SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE );
        
        searchEngine.search(
                pattern, 
                new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                searchScope, 
                searchRequestor, 
                monitor
                );

        if(searchRequestor instanceof MethodSearchRequestor.MethodDeclarationsSearchRequestor){                
            return ((MethodSearchRequestor.MethodDeclarationsSearchRequestor)searchRequestor).getMethodUnitPairs();
        }else{
            return ((MethodSearchRequestor.MethodReferencesSearchRequestor)searchRequestor).getMethodUnitPairs();
        }
    } catch (CoreException e) {
        JavaPlugin.log(e);

        return new LinkedList();
    }
}
 
Example 6
Source File: MatchLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static int getTotalNumberOfSettings(int searchFor) {
	if (searchFor == IJavaSearchConstants.TYPE) {
		return 15;
	} else if (searchFor == IJavaSearchConstants.CONSTRUCTOR) {
		return 1;
	} else if (searchFor == IJavaSearchConstants.METHOD) {
		return 5;
	} else if (searchFor == IJavaSearchConstants.FIELD) {
		return 4;
	}
	return 0;
}
 
Example 7
Source File: CallerFinder.java    From lapse-plus with GNU General Public License v3.0 4 votes vote down vote up
public static Collection/*<MethodUnitPair>*/ findCallers(IProgressMonitor progressMonitor, String methodName, IJavaProject project, boolean isConstructor) {
      
try {
	
	MethodSearchRequestor.initializeParserMap();
	
      	SearchRequestor searchRequestor =  (SearchRequestor)new MethodSearchRequestor.MethodReferencesSearchRequestor();
	
          SearchEngine searchEngine = new SearchEngine();

          IProgressMonitor monitor = new SubProgressMonitor(progressMonitor, 5, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
          
          monitor.beginTask("Searching for calls to " + methodName + (project != null ? " in " + project.getProject().getName() : ""), 100);
          
          IJavaSearchScope searchScope = getSearchScope(project);
          
          // This is kind of hacky: we need to make up a string name for the search to work right
          
          log("Looking for calls to " + methodName);
          
          int matchType = !isConstructor ? IJavaSearchConstants.METHOD : IJavaSearchConstants.CONSTRUCTOR;
          
          SearchPattern pattern = SearchPattern.createPattern(
          		methodName, 
			matchType,
			IJavaSearchConstants.REFERENCES,
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
          
          searchEngine.search(
          		pattern, 
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
                  searchScope, 
			searchRequestor, 
			monitor
	);

          if(searchRequestor instanceof MethodSearchRequestor.MethodDeclarationsSearchRequestor){                
              return ((MethodSearchRequestor.MethodDeclarationsSearchRequestor)searchRequestor).getMethodUnitPairs();
          }else{
              return ((MethodSearchRequestor.MethodReferencesSearchRequestor)searchRequestor).getMethodUnitPairs();
          }
          
      } catch (CoreException e) {
          JavaPlugin.log(e);

          return new LinkedList();
      }
  }
 
Example 8
Source File: MatchLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static int getNumberOfSelectedSettings(int locations, int searchFor) {
	int count= 0;
	if (searchFor == IJavaSearchConstants.TYPE) {

		if (isSet(locations, IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.FIELD_DECLARATION_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.LOCAL_VARIABLE_DECLARATION_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.RETURN_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.PARAMETER_DECLARATION_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.THROWS_CLAUSE_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.TYPE_VARIABLE_BOUND_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.WILDCARD_BOUND_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.INSTANCEOF_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.TYPE_ARGUMENT_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.CAST_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.CATCH_TYPE_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.CLASS_INSTANCE_CREATION_TYPE_REFERENCE)) {
			count++;
		}
	} else if (searchFor == IJavaSearchConstants.METHOD || searchFor == IJavaSearchConstants.FIELD) {
		if (isSet(locations, IJavaSearchConstants.SUPER_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.QUALIFIED_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.THIS_REFERENCE)) {
			count++;
		}
		if (isSet(locations, IJavaSearchConstants.IMPLICIT_THIS_REFERENCE)) {
			count++;
		}
	}
	if (searchFor == IJavaSearchConstants.METHOD || searchFor == IJavaSearchConstants.CONSTRUCTOR) {
		if (isSet(locations, IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION)) {
			count++;
		}
	}
	return count;
}