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

The following examples show how to use org.eclipse.jdt.core.search.IJavaSearchConstants#REFERENCES . 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: SelectFieldModeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public SelectFieldModeAction(CallHierarchyViewPart v, int mode) {
        super(null, AS_RADIO_BUTTON);
        if (mode == IJavaSearchConstants.REFERENCES) {
            setText(CallHierarchyMessages.SelectFieldModeAction_all_references_label);
            setDescription(CallHierarchyMessages.SelectFieldModeAction_all_references_description);
        } else if (mode == IJavaSearchConstants.READ_ACCESSES) {
            setText(CallHierarchyMessages.SelectFieldModeAction_read_accesses_label);
            setDescription(CallHierarchyMessages.SelectFieldModeAction_read_accesses_description);
        } else if (mode == IJavaSearchConstants.WRITE_ACCESSES) {
            setText(CallHierarchyMessages.SelectFieldModeAction_write_accesses_label);
            setDescription(CallHierarchyMessages.SelectFieldModeAction_write_accesses_description);
        } else {
            Assert.isTrue(false);
        }
        fView= v;
        fMode= mode;
        // FIXME(stephan) adjust/create new help context
//        PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CALL_HIERARCHY_TOGGLE_CALL_MODE_ACTION);
    }
 
Example 2
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initFieldMode() {
    int mode;

    try {
        mode = fDialogSettings.getInt(DIALOGSTORE_FIELD_MODE);

        switch (mode) {
        	case IJavaSearchConstants.REFERENCES:
        	case IJavaSearchConstants.READ_ACCESSES:
        	case IJavaSearchConstants.WRITE_ACCESSES:
        		break; // OK
        default:
        	mode = IJavaSearchConstants.REFERENCES;
        }
    } catch (NumberFormatException e) {
        mode = IJavaSearchConstants.REFERENCES;
    }

    // force the update
    fCurrentFieldMode = -1;

    // will fill the main tool bar
    setFieldMode(mode);
}
 
Example 3
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 4
Source File: QueryParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isHandled(QuerySpecification query) {
	switch (query.getLimitTo()) {
		case IJavaSearchConstants.REFERENCES:
		case IJavaSearchConstants.ALL_OCCURRENCES: {
			break;
		}
		default: {
			return false;
		}
	}
	if (query instanceof ElementQuerySpecification) {
		IJavaElement element = ((ElementQuerySpecification) query).getElement();
		return element.getElementType() == IJavaElement.TYPE || element.getElementType() == IJavaElement.FIELD
				|| element.getElementType() == IJavaElement.METHOD;
	}
	//		if (query instanceof PatternQuerySpecification) {
	//			PatternQuerySpecification patternQuery = (PatternQuerySpecification) query;
	//			switch (patternQuery.getSearchFor()) {
	//				case IJavaSearchConstants.UNKNOWN:
	//				case IJavaSearchConstants.TYPE:
	//				case IJavaSearchConstants.CLASS:
	//				case IJavaSearchConstants.CLASS_AND_INTERFACE:
	//				case IJavaSearchConstants.CLASS_AND_ENUM: {
	//					return true;
	//				}
	//			}
	//		}
	return false;
}
 
Example 5
Source File: JdtReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("all")
protected QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException {
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
	boolean isInsideJRE= factory.isInsideJRE(element);

	IJavaSearchScope scope= factory.createWorkspaceScope(isInsideJRE);
	String description= factory.getWorkspaceScopeDescription(isInsideJRE);
	return new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, scope, description);
}
 
Example 6
Source File: VariablePattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public VariablePattern(int patternKind, char[] name, int limitTo, int matchRule) {
	super(patternKind, matchRule);

    this.fineGrain = limitTo & FINE_GRAIN_MASK;
    if (this.fineGrain == 0) {
		switch (limitTo & 0xF) {
			case IJavaSearchConstants.DECLARATIONS :
				this.findDeclarations = true;
				break;
			case IJavaSearchConstants.REFERENCES :
				this.readAccess = true;
				this.writeAccess = true;
				break;
			case IJavaSearchConstants.READ_ACCESSES :
				this.readAccess = true;
				break;
			case IJavaSearchConstants.WRITE_ACCESSES :
				this.writeAccess = true;
				break;
			case IJavaSearchConstants.ALL_OCCURRENCES :
				this.findDeclarations = true;
				this.readAccess = true;
				this.writeAccess = true;
				break;
		}
		this.findReferences = this.readAccess || this.writeAccess;
    }

	this.name = (this.isCaseSensitive || this.isCamelCase) ? name : CharOperation.toLowerCase(name);
}
 
Example 7
Source File: DeclarationOfReferencedMethodsPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public DeclarationOfReferencedMethodsPattern(IJavaElement enclosingElement) {
	super(null, null, null, null, null, null, null, null, IJavaSearchConstants.REFERENCES, R_PATTERN_MATCH);

	this.enclosingElement = enclosingElement;
	this.knownMethods = new SimpleSet();
	this.mustResolve = true;
}
 
Example 8
Source File: JavaQueryParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static Set<IIndexedJavaRef> findWorkspaceReferences(
    IJavaElement element, boolean resolveMatches) {
  JavaQueryParticipant searchEngine = new JavaQueryParticipant();
  ElementQuerySpecification query = new ElementQuerySpecification(element,
      IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");

  return searchEngine.findMatches(query, resolveMatches);
}
 
Example 9
Source File: DeclarationOfAccessedFieldsPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public DeclarationOfAccessedFieldsPattern(IJavaElement enclosingElement) {
	super(null, null, null, null, null, IJavaSearchConstants.REFERENCES, R_PATTERN_MATCH);

	this.enclosingElement = enclosingElement;
	this.knownFields = new SimpleSet();
	this.mustResolve = true;
}
 
Example 10
Source File: CallerMethodWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean canHaveChildren() {
	IMember member= getMember();
	if (member instanceof IField) {
		if (getLevel() == 1)
			return true;
		int mode= getFieldSearchMode();
		return mode == IJavaSearchConstants.REFERENCES || mode == IJavaSearchConstants.READ_ACCESSES;
	}
	return member instanceof IMethod || member instanceof IType;
}
 
Example 11
Source File: MethodWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int getFieldSearchMode() {
   	if (fFieldSearchMode != 0)
   		return fFieldSearchMode;
   	MethodWrapper parent= getParent();
   	while (parent != null) {
		if (parent.fFieldSearchMode != 0)
			return parent.fFieldSearchMode;
		else
			parent= parent.getParent();
	}
   	return IJavaSearchConstants.REFERENCES;
}
 
Example 12
Source File: ConstructorPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ConstructorPattern(
	char[] declaringSimpleName,
	char[] declaringQualification,
	char[][] parameterQualifications,
	char[][] parameterSimpleNames,
	int limitTo,
	int matchRule) {

	this(matchRule);

	this.fineGrain = limitTo & FINE_GRAIN_MASK;
    if (this.fineGrain == 0) {
		switch (limitTo) {
			case IJavaSearchConstants.DECLARATIONS :
				this.findReferences = false;
				break;
			case IJavaSearchConstants.REFERENCES :
				this.findDeclarations = false;
				break;
			case IJavaSearchConstants.ALL_OCCURRENCES :
				break;
		}
    } else {
		this.findDeclarations = false;
    }

	this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification);
	this.declaringSimpleName = (this.isCaseSensitive || this.isCamelCase) ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName);
	if (parameterSimpleNames != null) {
		this.parameterCount = parameterSimpleNames.length;
		boolean synthetic = this.parameterCount>0 && declaringQualification != null && CharOperation.equals(CharOperation.concat(parameterQualifications[0], parameterSimpleNames[0], '.'), declaringQualification);
		int offset = 0;
		if (synthetic) {
			// skip first synthetic parameter
			this.parameterCount--;
			offset++;
		}
		this.parameterQualifications = new char[this.parameterCount][];
		this.parameterSimpleNames = new char[this.parameterCount][];
		for (int i = 0; i < this.parameterCount; i++) {
			this.parameterQualifications[i] = this.isCaseSensitive ? parameterQualifications[i+offset] : CharOperation.toLowerCase(parameterQualifications[i+offset]);
			this.parameterSimpleNames[i] = this.isCaseSensitive ? parameterSimpleNames[i+offset] : CharOperation.toLowerCase(parameterSimpleNames[i+offset]);
		}
	} else {
		this.parameterCount = -1;
	}
	this.mustResolve = mustResolve();
}
 
Example 13
Source File: MethodPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public MethodPattern(
	char[] selector,
	char[] declaringQualification,
	char[] declaringSimpleName,
	char[] returnQualification,
	char[] returnSimpleName,
	char[][] parameterQualifications,
	char[][] parameterSimpleNames,
	IType declaringType,
	int limitTo,
	int matchRule) {

	this(matchRule);

	this.fineGrain = limitTo & FINE_GRAIN_MASK;
    if (this.fineGrain == 0) {
		switch (limitTo & 0xF) {
			case IJavaSearchConstants.DECLARATIONS :
				this.findReferences = false;
				break;
			case IJavaSearchConstants.REFERENCES :
				this.findDeclarations = false;
				break;
			case IJavaSearchConstants.ALL_OCCURRENCES :
				break;
		}
    } else {
		this.findDeclarations = false;
    }

	this.selector = (this.isCaseSensitive || this.isCamelCase) ? selector : CharOperation.toLowerCase(selector);
	this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification);
	this.declaringSimpleName = this.isCaseSensitive ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName);
	this.returnQualification = this.isCaseSensitive ? returnQualification : CharOperation.toLowerCase(returnQualification);
	this.returnSimpleName = this.isCaseSensitive ? returnSimpleName : CharOperation.toLowerCase(returnSimpleName);
	if (parameterSimpleNames != null) {
		this.parameterCount = parameterSimpleNames.length;
		this.parameterQualifications = new char[this.parameterCount][];
		this.parameterSimpleNames = new char[this.parameterCount][];
		for (int i = 0; i < this.parameterCount; i++) {
			this.parameterQualifications[i] = this.isCaseSensitive ? parameterQualifications[i] : CharOperation.toLowerCase(parameterQualifications[i]);
			this.parameterSimpleNames[i] = this.isCaseSensitive ? parameterSimpleNames[i] : CharOperation.toLowerCase(parameterSimpleNames[i]);
		}
	} else {
		this.parameterCount = -1;
	}
	this.declaringType = declaringType;
	if (this.declaringType !=  null) {
		this.declaringPackageName = this.declaringType.getPackageFragment().getElementName().toCharArray();
	}
	this.mustResolve = mustResolve();
}
 
Example 14
Source File: CallHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void makeActions() {
      fRefreshViewAction = new RefreshViewAction(this);
      fRefreshSingleElementAction= new RefreshElementAction(fCallHierarchyViewer);

new CallHierarchyOpenEditorHelper(fLocationViewer);
new CallHierarchyOpenEditorHelper(fCallHierarchyViewer);

fOpenLocationAction= new OpenLocationAction(this, getSite());
fLocationCopyAction= fLocationViewer.initCopyAction(getViewSite(), fClipboard);
      fFocusOnSelectionAction = new FocusOnSelectionAction(this);
      fCopyAction= new CopyCallHierarchyAction(this, fClipboard, fCallHierarchyViewer);
      fSearchScopeActions = new SearchScopeActionGroup(this, fDialogSettings);
      fShowSearchInDialogAction= new ShowSearchInDialogAction(this, fCallHierarchyViewer);
      fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
              fCallHierarchyViewer);
      fHistoryDropDownAction = new HistoryDropDownAction(this);
      fHistoryDropDownAction.setEnabled(false);
      fCancelSearchAction = new CancelSearchAction(this);
      setCancelEnabled(false);
      fExpandWithConstructorsAction= new ExpandWithConstructorsAction(this, fCallHierarchyViewer);
      fRemoveFromViewAction= new RemoveFromViewAction(this, fCallHierarchyViewer);
      fPinViewAction= new PinCallHierarchyViewAction(this);
      fToggleOrientationActions = new ToggleOrientationAction[] {
              new ToggleOrientationAction(this, VIEW_ORIENTATION_VERTICAL),
              new ToggleOrientationAction(this, VIEW_ORIENTATION_HORIZONTAL),
              new ToggleOrientationAction(this, VIEW_ORIENTATION_AUTOMATIC),
              new ToggleOrientationAction(this, VIEW_ORIENTATION_SINGLE)
          };
fRemoveFromViewAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_DELETE);
      fToggleCallModeActions = new ToggleCallModeAction[] {
              new ToggleCallModeAction(this, CALL_MODE_CALLERS),
              new ToggleCallModeAction(this, CALL_MODE_CALLEES)
          };
      fToggleFieldModeActions = new SelectFieldModeAction[] {
              new SelectFieldModeAction(this, IJavaSearchConstants.REFERENCES),
              new SelectFieldModeAction(this, IJavaSearchConstants.READ_ACCESSES),
              new SelectFieldModeAction(this, IJavaSearchConstants.WRITE_ACCESSES)
          };
      fActionGroups = new CompositeActionGroup(new ActionGroup[] {
                  new OpenEditorActionGroup(this),
                  new OpenViewActionGroup(this),
			new CCPActionGroup(this, true),
                  new GenerateActionGroup(this),
                  new RefactorActionGroup(this),
                  new JavaSearchActionGroup(this),
                  fSearchScopeActions, fFiltersActionGroup
              });
  }
 
Example 15
Source File: FindReferencesAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
int getLimitTo() {
	return IJavaSearchConstants.REFERENCES;
}
 
Example 16
Source File: JavaQueryParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public void search(ISearchRequestor requestor, QuerySpecification query,
    IProgressMonitor monitor) throws CoreException {
  try {
    monitor.subTask("Locating GWT matches...");

    // Make sure we're searching for Java references
    switch (query.getLimitTo()) {
      case IJavaSearchConstants.REFERENCES:
      case IJavaSearchConstants.ALL_OCCURRENCES:
        // These we handle as expected
        break;
      case IJavaSearchConstants.READ_ACCESSES:
      case IJavaSearchConstants.WRITE_ACCESSES:
        // We don't actually check field references to see if they're read or
        // write accesses; we just treat this as a generic references search
        break;
      default:
        // Anything else (e.g., Declarations), we don't support
        return;
    }

    Set<IIndexedJavaRef> matchingJavaRefs = null;

    // Find all matching Java references in the index. The search algorithm
    // differs depending on whether we're doing an element query
    // (Ctrl-Shift-G) or a pattern query (Java Search dialog box)
    if (query instanceof ElementQuerySpecification) {
      ElementQuerySpecification elementQuery = (ElementQuerySpecification) query;
      matchingJavaRefs = findMatches(elementQuery, true);
    } else {
      assert (query instanceof PatternQuerySpecification);
      PatternQuerySpecification patternQuery = (PatternQuerySpecification) query;
      matchingJavaRefs = findMatches(patternQuery);
    }

    for (IIndexedJavaRef javaRef : matchingJavaRefs) {
      Match match = createMatch(javaRef, query);
      if (match != null) {
        // Report the match location to the Java Search engine
        requestor.reportMatch(match);
      }
    }
  } catch (Exception e) {
    // If we allow any exceptions to escape, the JDT will disable us
    GWTPluginLog.logError("Error finding Java Search matches", e);
  }
}
 
Example 17
Source File: JavaQueryParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public void testPatternSearch() throws CoreException {
  Match[] expected;

  // Search for type references by simple name
  expected = new Match[] {
      createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
      createWindowsTestMatch(1419, 50)};
  assertSearchMatches(expected, createQuery("InnerSub",
      IJavaSearchConstants.TYPE));

  // Search for type with different casing
  expected = new Match[] {
      createWindowsTestMatch(840, 50), createWindowsTestMatch(1207, 50),
      createWindowsTestMatch(1419, 50)};
  assertSearchMatches(expected, createQuery("innersub",
      IJavaSearchConstants.TYPE));

  // Search for type with different casing with case-sensitive enabled
  QuerySpecification query = new PatternQuerySpecification("innersub",
      IJavaSearchConstants.TYPE, true, IJavaSearchConstants.REFERENCES,
      WORKSPACE_SCOPE, "");
  assertSearchMatches(NO_MATCHES, query);

  // Search for field references
  assertSearchMatch(createWindowsTestMatch(990, 5), createQuery("keith",
      IJavaSearchConstants.FIELD));

  // Search for method references using * wildcard
  expected = new Match[] {
      createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5),
      createWindowsTestMatch(1340, 8)};
  assertSearchMatches(expected, createQuery("sayH*",
      IJavaSearchConstants.METHOD));

  // Search for method references using ? wildcard
  expected = new Match[] {
      createWindowsTestMatch(1174, 5), createWindowsTestMatch(1259, 5)};
  assertSearchMatches(expected, createQuery("sayH?",
      IJavaSearchConstants.METHOD));

  // Search for constructor references with qualified type name and parameters
  assertSearchMatch(createWindowsTestMatch(892, 3), createQuery(
      "com.hello.client.JavaQueryParticipantTest.InnerSub.InnerSub(String)",
      IJavaSearchConstants.CONSTRUCTOR));
}
 
Example 18
Source File: JavaQueryParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static QuerySpecification createQuery(String pattern, int searchFor) {
  return new PatternQuerySpecification(pattern, searchFor, false,
      IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
}
 
Example 19
Source File: JavaQueryParticipantTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private static QuerySpecification createQuery(IJavaElement element) {
  return new ElementQuerySpecification(element,
      IJavaSearchConstants.REFERENCES, WORKSPACE_SCOPE, "");
}