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

The following examples show how to use org.eclipse.jdt.core.search.IJavaSearchConstants#TYPE . 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: FocusOnTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Shell parent= fViewPart.getSite().getShell();
	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(parent, false,
		PlatformUI.getWorkbench().getProgressService(),
		SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE);

	dialog.setTitle(TypeHierarchyMessages.FocusOnTypeAction_dialog_title);
	dialog.setMessage(TypeHierarchyMessages.FocusOnTypeAction_dialog_message);
	if (dialog.open() != IDialogConstants.OK_ID) {
		return;
	}

	Object[] types= dialog.getResult();
	if (types != null && types.length > 0) {
		IType type= (IType)types[0];
		fViewPart.setInputElement(type);
	}
}
 
Example 2
Source File: ScriptExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("restriction")
private void openClassSelectionDialog() {
    final JavaSearchScope scope = new JavaSearchScope(true);
    try {
        scope.add(RepositoryManager.getInstance().getCurrentRepository().getJavaProject());
    } catch (final Exception ex) {
        BonitaStudioLog.error(ex);
    }
    final FilteredTypesSelectionDialog searchDialog = new FilteredTypesSelectionDialog(
            Display.getDefault().getActiveShell(), false, null, scope,
            IJavaSearchConstants.TYPE);
    if (searchDialog.open() == Dialog.OK) {
        final String selectedTypeName = ((IType) searchDialog.getFirstResult()).getFullyQualifiedName();
        typeCombo.setInput(selectedTypeName);
        inputExpression.setReturnType(selectedTypeName);
    }
}
 
Example 3
Source File: AddImportsOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int getSearchForConstant(int typeKinds) {
	final int CLASSES= SimilarElementsRequestor.CLASSES;
	final int INTERFACES= SimilarElementsRequestor.INTERFACES;
	final int ENUMS= SimilarElementsRequestor.ENUMS;
	final int ANNOTATIONS= SimilarElementsRequestor.ANNOTATIONS;

	switch (typeKinds & (CLASSES | INTERFACES | ENUMS | ANNOTATIONS)) {
		case CLASSES: return IJavaSearchConstants.CLASS;
		case INTERFACES: return IJavaSearchConstants.INTERFACE;
		case ENUMS: return IJavaSearchConstants.ENUM;
		case ANNOTATIONS: return IJavaSearchConstants.ANNOTATION_TYPE;
		case CLASSES | INTERFACES: return IJavaSearchConstants.CLASS_AND_INTERFACE;
		case CLASSES | ENUMS: return IJavaSearchConstants.CLASS_AND_ENUM;
		default: return IJavaSearchConstants.TYPE;
	}
}
 
Example 4
Source File: TypeInfoFilter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean matchesModifiers(TypeNameMatch type) {
	if (fElementKind == IJavaSearchConstants.TYPE)
		return true;
	int modifiers= type.getModifiers() & TYPE_MODIFIERS;
	switch (fElementKind) {
		case IJavaSearchConstants.CLASS:
			return modifiers == 0;
		case IJavaSearchConstants.ANNOTATION_TYPE:
			return Flags.isAnnotation(modifiers);
		case IJavaSearchConstants.INTERFACE:
			return modifiers == Flags.AccInterface;
		case IJavaSearchConstants.ENUM:
			return Flags.isEnum(modifiers);
		case IJavaSearchConstants.CLASS_AND_INTERFACE:
			return modifiers == 0 || modifiers == Flags.AccInterface;
		case IJavaSearchConstants.CLASS_AND_ENUM:
			return modifiers == 0 || Flags.isEnum(modifiers);
		case IJavaSearchConstants.INTERFACE_AND_ANNOTATION:
			return Flags.isInterface(modifiers);
	}
	return false;
}
 
Example 5
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 6
Source File: MoveMembersWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void openTypeSelectionDialog(){
	int elementKinds= IJavaSearchConstants.TYPE;
	final IJavaSearchScope scope= createWorkspaceSourceScope();
	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(getShell(), false,
		getWizard().getContainer(), scope, elementKinds);
	dialog.setTitle(RefactoringMessages.MoveMembersInputPage_choose_Type);
	dialog.setMessage(RefactoringMessages.MoveMembersInputPage_dialogMessage);
	dialog.setValidator(new ISelectionStatusValidator(){
		public IStatus validate(Object[] selection) {
			Assert.isTrue(selection.length <= 1);
			if (selection.length == 0)
				return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null);
			Object element= selection[0];
			if (! (element instanceof IType))
				return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, RefactoringMessages.MoveMembersInputPage_Invalid_selection, null);
			IType type= (IType)element;
			return validateDestinationType(type, type.getElementName());
		}
	});
	dialog.setInitialPattern(createInitialFilter());
	if (dialog.open() == Window.CANCEL)
		return;
	IType firstResult= (IType)dialog.getFirstResult();
	fDestinationField.setText(firstResult.getFullyQualifiedName('.'));
}
 
Example 7
Source File: JavaContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private int getSearchForConstant(int typeKinds) {
	final int CLASSES= SimilarElementsRequestor.CLASSES;
	final int INTERFACES= SimilarElementsRequestor.INTERFACES;
	final int ENUMS= SimilarElementsRequestor.ENUMS;
	final int ANNOTATIONS= SimilarElementsRequestor.ANNOTATIONS;

	switch (typeKinds & (CLASSES | INTERFACES | ENUMS | ANNOTATIONS)) {
		case CLASSES: return IJavaSearchConstants.CLASS;
		case INTERFACES: return IJavaSearchConstants.INTERFACE;
		case ENUMS: return IJavaSearchConstants.ENUM;
		case ANNOTATIONS: return IJavaSearchConstants.ANNOTATION_TYPE;
		case CLASSES | INTERFACES: return IJavaSearchConstants.CLASS_AND_INTERFACE;
		case CLASSES | ENUMS: return IJavaSearchConstants.CLASS_AND_ENUM;
		default: return IJavaSearchConstants.TYPE;
	}
}
 
Example 8
Source File: InputTypeEditingSupport.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
protected void openClassSelectionDialog() {
    JavaSearchScope scope = new JavaSearchScope(true);
    try {
        scope.add(RepositoryManager.getInstance().getCurrentRepository().getJavaProject());
    } catch (Exception ex) {
        BonitaStudioLog.error(ex);
    }
    FilteredTypesSelectionDialog searchDialog = new FilteredTypesSelectionDialog(Display.getDefault().getActiveShell(), false, null, scope, IJavaSearchConstants.TYPE);
    if (searchDialog.open() == Dialog.OK) {
        input.setType(((IType) searchDialog.getFirstResult()).getFullyQualifiedName()) ;
        getViewer().refresh() ;
    }
}
 
Example 9
Source File: DataWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
protected void openClassSelectionDialog(final Text classText) {
    final IJavaSearchScope searchScope = SearchEngine
            .createJavaSearchScope(new IJavaElement[] { RepositoryManager.getInstance().getCurrentRepository()
                    .getJavaProject() });
    final OpenTypeSelectionDialog searchDialog = new OpenTypeSelectionDialog(getShell(), false, null, searchScope,
            IJavaSearchConstants.TYPE);
    if (searchDialog.open() == Dialog.OK) {
        classText.setText(((IType) searchDialog.getFirstResult()).getFullyQualifiedName());
    }
}
 
Example 10
Source File: OutputTypeEditingSupport.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
protected void openClassSelectionDialog() {
    JavaSearchScope scope = new JavaSearchScope(true);
    try {
        scope.add(RepositoryManager.getInstance().getCurrentRepository().getJavaProject());
    } catch (Exception ex) {
        BonitaStudioLog.error(ex);
    }
    FilteredTypesSelectionDialog searchDialog = new FilteredTypesSelectionDialog(Display.getDefault().getActiveShell(), false, null, scope, IJavaSearchConstants.TYPE);
    if (searchDialog.open() == Dialog.OK) {
        output.setType(((IType) searchDialog.getFirstResult()).getFullyQualifiedName()) ;
        getViewer().refresh() ;
    }
}
 
Example 11
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 12
Source File: JavaQueryParticipant.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isTypeSearch(QuerySpecification query) {
  if (query instanceof ElementQuerySpecification) {
    return (((ElementQuerySpecification) query).getElement().getElementType() == IJavaElement.TYPE);
  }

  return (((PatternQuerySpecification) query).getSearchFor() == IJavaSearchConstants.TYPE);
}
 
Example 13
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 14
Source File: CheckProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public int getSearchFor() {
  return IJavaSearchConstants.TYPE;
}
 
Example 15
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public AcceptableByPreference() {
	this(IJavaSearchConstants.TYPE);
}
 
Example 16
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.0
 */
@Override
public int getSearchFor() {
	return IJavaSearchConstants.TYPE;
}
 
Example 17
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.0
 */
@Override
public int getSearchFor() {
	return IJavaSearchConstants.TYPE;
}
 
Example 18
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public All() {
	this(IJavaSearchConstants.TYPE);
}
 
Example 19
Source File: TypeMatchFilters.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public AbstractFilter() {
	this(IJavaSearchConstants.TYPE);
}
 
Example 20
Source File: JavaUI.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a selection dialog that lists all types in the given scope.
 * The caller is responsible for opening the dialog with <code>Window.open</code>,
 * and subsequently extracting the selected type(s) (of type
 * <code>IType</code>) via <code>SelectionDialog.getResult</code>.
 *
 * @param parent the parent shell of the dialog to be created
 * @param context the runnable context used to show progress when the dialog
 *   is being populated
 * @param scope the scope that limits which types are included
 * @param style flags defining the style of the dialog; the only valid values are
 *   {@link IJavaElementSearchConstants#CONSIDER_CLASSES},
 *   {@link IJavaElementSearchConstants#CONSIDER_INTERFACES},
 *   {@link IJavaElementSearchConstants#CONSIDER_ANNOTATION_TYPES},
 *   {@link IJavaElementSearchConstants#CONSIDER_ENUMS},
 *   {@link IJavaElementSearchConstants#CONSIDER_ALL_TYPES},
 *   {@link IJavaElementSearchConstants#CONSIDER_CLASSES_AND_INTERFACES},
 *   {@link IJavaElementSearchConstants#CONSIDER_CLASSES_AND_ENUMS}, and
 *   {@link IJavaElementSearchConstants#CONSIDER_INTERFACES_AND_ANNOTATIONS}. Please note that
 *   the bitwise OR combination of the elementary constants is not supported.
 * @param multipleSelection <code>true</code> if multiple selection is allowed
 * @param filter the initial pattern to filter the set of types. For example "Abstract" shows
 *  all types starting with "abstract". The meta character '?' representing any character and
 *  '*' representing any string are supported. Clients can pass an empty string if no filtering
 *  is required.
 * @param extension a user interface extension to the type selection dialog or <code>null</code>
 *  if no extension is desired
 *
 * @return a new selection dialog
 *
 * @exception JavaModelException if the selection dialog could not be opened
 *
 * @since 3.2
 */
public static SelectionDialog createTypeDialog(Shell parent, IRunnableContext context, IJavaSearchScope scope, int style,
		boolean multipleSelection, String filter, TypeSelectionExtension extension) throws JavaModelException {
	int elementKinds= 0;
	if (style == IJavaElementSearchConstants.CONSIDER_ALL_TYPES) {
		elementKinds= IJavaSearchConstants.TYPE;
	} else if (style == IJavaElementSearchConstants.CONSIDER_INTERFACES) {
		elementKinds= IJavaSearchConstants.INTERFACE;
	} else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES) {
		elementKinds= IJavaSearchConstants.CLASS;
	} else if (style == IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES) {
		elementKinds= IJavaSearchConstants.ANNOTATION_TYPE;
	} else if (style == IJavaElementSearchConstants.CONSIDER_ENUMS) {
		elementKinds= IJavaSearchConstants.ENUM;
	} else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES) {
		elementKinds= IJavaSearchConstants.CLASS_AND_INTERFACE;
	} else if (style == IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS) {
		elementKinds= IJavaSearchConstants.CLASS_AND_ENUM;
	} else if (style == DEPRECATED_CONSIDER_TYPES) {
		elementKinds= IJavaSearchConstants.CLASS_AND_INTERFACE;
	} else if (style == IJavaElementSearchConstants.CONSIDER_INTERFACES_AND_ANNOTATIONS) {
		elementKinds= IJavaSearchConstants.INTERFACE_AND_ANNOTATION;
	} else {
		throw new IllegalArgumentException("Invalid style constant."); //$NON-NLS-1$
	}
	FilteredTypesSelectionDialog dialog= new FilteredTypesSelectionDialog(parent, multipleSelection,
		context, scope, elementKinds, extension);
	dialog.setMessage(JavaUIMessages.JavaUI_defaultDialogMessage);
	dialog.setInitialPattern(filter);
	return dialog;
}