List of usage examples for org.eclipse.jdt.core Flags isInterface
public static boolean isInterface(int flags)
interface
modifier. From source file:bndtools.editor.components.SvcInterfaceProposalProvider.java
License:Open Source License
@Override protected List<IContentProposal> doGenerateProposals(String contents, int position) { final String prefix = contents.substring(0, position); final IJavaSearchScope scope = SearchEngine .createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() }); final ArrayList<IContentProposal> result = new ArrayList<IContentProposal>(100); final TypeNameRequestor typeNameRequestor = new TypeNameRequestor() { @Override/*from w w w . ja v a 2 s. c o m*/ public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { boolean isInterface = Flags.isInterface(modifiers); result.add( new JavaContentProposal(new String(packageName), new String(simpleTypeName), isInterface)); } }; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(), SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope, typeNameRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }; try { if (searchContext.getRunContext() == null) { runnable.run(new NullProgressMonitor()); } else { searchContext.getRunContext().run(false, false, runnable); } } catch (InvocationTargetException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for Java types.", e.getTargetException())); return Collections.emptyList(); } catch (InterruptedException e) { // Reset interrupted status and return empty Thread.currentThread().interrupt(); return Collections.emptyList(); } return result; }
From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaSequenceLabelProvider.java
License:Open Source License
public Color getBackground(Object element) { if (element instanceof IAdaptable) { IJavaElement javaElement = (IJavaElement) ((IAdaptable) element).getAdapter(IJavaElement.class); if (javaElement instanceof IMember) { try { int flags = ((IMember) javaElement).getFlags(); if (Flags.isAbstract(flags) || Flags.isInterface(flags)) { return Display.getCurrent().getSystemColor(SWT.COLOR_GRAY); }//w w w. j a v a2 s .c o m if (javaElement instanceof IMethod) { if (Flags.isPrivate(flags)) { return ISketchColorConstants.PRIVATE_BG; } else if (Flags.isProtected(flags)) { return ISketchColorConstants.PROTECTED_BG; } else if (Flags.isPackageDefault(flags)) { return ISketchColorConstants.LIGHT_BLUE; } else if (Flags.isPublic(flags)) { return ISketchColorConstants.PUBLIC_BG; } } } catch (JavaModelException e) { //just return null } } else if (javaElement instanceof IPackageFragment) { return ISketchColorConstants.PRIVATE_BG; } } return null; }
From source file:com.amashchenko.eclipse.strutsclipse.java.SimpleJavaProposalCollector.java
License:Apache License
@Override protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) { if (collectMethods) { if (CompletionProposal.METHOD_REF == proposal.getKind() && Flags.isPublic(proposal.getFlags())) { char[] sig = proposal.getSignature(); char[] declSig = proposal.getDeclarationSignature(); // collect methods suitable for action methods ignoring Object // methods if (sig != null && declSig != null && ACTION_METHOD_SIGNATURE.equals(String.valueOf(sig)) && !OBJECT_SIGNATURE.equals(String.valueOf(declSig))) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); }/*from w w w .j a va 2 s . c om*/ } } else { // collect packages and classes suitable for actions if ((CompletionProposal.PACKAGE_REF == proposal.getKind() || CompletionProposal.TYPE_REF == proposal.getKind()) && !Flags.isAbstract(proposal.getFlags()) && !Flags.isInterface(proposal.getFlags()) && !Flags.isEnum(proposal.getFlags())) { return new SimpleJavaCompletionProposal(proposal, getInvocationContext(), getImage(getLabelProvider().createImageDescriptor(proposal))); } } return null; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {//w w w . j ava2s . c o m // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayCustomViewClassInput() { try {// w w w .j a v a 2 s . c o m IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] viewTypes = new IType[0]; IType fragmentType = javaProject.findType(CLASS_VIEW); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); viewTypes = hierarchy.getAllSubtypes(fragmentType); } scope = SearchEngine.createJavaSearchScope(viewTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewCustomViewClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Custom View Class"); dialog.setMessage("Select a Custom View class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {/*from w ww. j ava2s.c o m*/ // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mValues.project; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType activityType = null; if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); } if (activityType == null) { IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null); for (IJavaProject p : projects) { activityType = p.findType(CLASS_ACTIVITY); if (activityType != null) { break; } } } if (activityType != null) { NullProgressMonitor monitor = new NullProgressMonitor(); ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor); IType[] classes = hierarchy.getAllSubtypes(activityType); scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getShell(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialog.setTitle("Choose Activity Class"); dialog.setMessage("Select an Activity class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {/*from w ww . java2 s .co m*/ // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mRulesEngine.getProject(); final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); if (javaProject != null) { IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT); // First check to make sure fragments are available, and if not, // warn the user. IAndroidTarget target = Sdk.getCurrent().getTarget(project); // No, this should be using the min SDK instead! if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) { // Compatibility library must be present MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Fragment Warning", null, "Fragments require API level 11 or higher, or a compatibility " + "library for older versions.\n\n" + " Do you want to install the compatibility library?", MessageDialog.QUESTION, new String[] { "Install", "Cancel" }, 1 /* default button: Cancel */); int answer = dialog.open(); if (answer == 0) { if (!AddSupportJarAction.install(project)) { return null; } } else { return null; } } // Look up sub-types of each (new fragment class and compatibility fragment // class, if any) and merge the two arrays - then create a scope from these // elements. IType[] fragmentTypes = new IType[0]; IType[] oldFragmentTypes = new IType[0]; if (oldFragmentType != null) { ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor()); oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType); } IType fragmentType = javaProject.findType(CLASS_FRAGMENT); if (fragmentType != null) { ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor()); fragmentTypes = hierarchy.getAllSubtypes(fragmentType); } IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length]; System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length); System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length); scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getDisplay().getActiveShell(); final AtomicReference<String> returnValue = new AtomicReference<String>(); final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public Control createContentArea(Composite parentComposite) { Composite composite = new Composite(parentComposite, SWT.NONE); composite.setLayout(new GridLayout(1, false)); Button button = new Button(composite, SWT.PUSH); button.setText("Create New..."); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String fqcn = createNewFragmentClass(javaProject); if (fqcn != null) { returnValue.set(fqcn); dialogHolder.get().close(); } } }); return composite; } @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialogHolder.set(dialog); dialog.setTitle("Choose Fragment Class"); dialog.setMessage("Select a Fragment class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } if (returnValue.get() != null) { return returnValue.get(); } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.android.ide.eclipse.auidt.internal.wizards.templates.NewTemplatePage.java
License:Open Source License
private String chooseActivity() { try {/* w ww . j a v a2 s .c o m*/ // Compute a search scope: We need to merge all the subclasses // android.app.Fragment and android.support.v4.app.Fragment IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); IProject project = mValues.project; IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType activityType = null; if (javaProject != null) { activityType = javaProject.findType(CLASS_ACTIVITY); } if (activityType == null) { IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null); for (IJavaProject p : projects) { activityType = p.findType(CLASS_ACTIVITY); if (activityType != null) { break; } } } if (activityType != null) { NullProgressMonitor monitor = new NullProgressMonitor(); ITypeHierarchy hierarchy = activityType.newTypeHierarchy(monitor); IType[] classes = hierarchy.getAllSubtypes(activityType); scope = SearchEngine.createJavaSearchScope(classes, IJavaSearchScope.SOURCES); } Shell parent = AdtPlugin.getDisplay().getActiveShell(); final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, // Use ? as a default filter to fill dialog with matches "?", //$NON-NLS-1$ new TypeSelectionExtension() { @Override public ITypeInfoFilterExtension getFilterExtension() { return new ITypeInfoFilterExtension() { @Override public boolean select(ITypeInfoRequestor typeInfoRequestor) { int modifiers = typeInfoRequestor.getModifiers(); if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers) || Flags.isEnum(modifiers)) { return false; } return true; } }; } }); dialog.setTitle("Choose Activity Class"); dialog.setMessage("Select an Activity class (? = any character, * = any string):"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } Object[] types = dialog.getResult(); if (types != null && types.length > 0) { return ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { AdtPlugin.log(e, null); } catch (CoreException e) { AdtPlugin.log(e, null); } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnitStructureRequestor.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor *//* w ww. j a va 2s . c o m*/ public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) { JavaElement handle = (JavaElement) this.handleStack.peek(); FieldInfo fieldInfo = (FieldInfo) this.infoStack.peek(); IJavaElement[] elements = getChildren(fieldInfo); SourceFieldElementInfo info = elements.length == 0 ? new SourceFieldElementInfo() : new SourceFieldWithChildrenInfo(elements); info.setNameSourceStart(fieldInfo.nameSourceStart); info.setNameSourceEnd(fieldInfo.nameSourceEnd); info.setSourceRangeStart(fieldInfo.declarationStart); info.setFlags(fieldInfo.modifiers); char[] typeName = manager.intern(fieldInfo.type); info.setTypeName(typeName); this.newElements.put(handle, info); if (fieldInfo.annotations != null) { int length = fieldInfo.annotations.length; this.unitInfo.annotationNumber += length; for (int i = 0; i < length; i++) { org.eclipse.jdt.internal.compiler.ast.Annotation annotation = fieldInfo.annotations[i]; acceptAnnotation(annotation, info, handle); } } info.setSourceRangeEnd(declarationSourceEnd); this.handleStack.pop(); this.infoStack.pop(); // remember initializer source if field is a constant if (initializationStart != -1) { int flags = info.flags; Object typeInfo; if (Flags.isFinal(flags) || ((typeInfo = this.infoStack.peek()) instanceof TypeInfo && (Flags.isInterface(((TypeInfo) typeInfo).modifiers)))) { int length = declarationEnd - initializationStart; if (length > 0) { char[] initializer = new char[length]; System.arraycopy(this.parser.scanner.source, initializationStart, initializer, 0, length); info.initializationSource = initializer; } } } if (fieldInfo.typeAnnotated) { this.unitInfo.annotationNumber = CompilationUnitElementInfo.ANNOTATION_THRESHOLD_FOR_DIET_PARSE; } }
From source file:com.codenvy.ide.ext.java.server.SourcesFromBytecodeGenerator.java
License:Open Source License
private String getModifiers(int flags, int typeFlags) { StringBuilder modifiers = new StringBuilder(); //package private modifier has no string representation if (Flags.isPublic(flags)) { modifiers.append("public "); }/*from www. j ava 2 s.co m*/ if (Flags.isProtected(flags)) { modifiers.append("protected "); } if (Flags.isPrivate(flags)) { modifiers.append("private "); } if (Flags.isStatic(flags)) { modifiers.append("static "); } if (Flags.isAbstract(flags) && !Flags.isInterface(typeFlags)) { modifiers.append("abstract "); } if (Flags.isFinal(flags)) { modifiers.append("final "); } if (Flags.isNative(flags)) { modifiers.append("native "); } if (Flags.isSynchronized(flags)) { modifiers.append("synchronized "); } if (Flags.isVolatile(flags)) { modifiers.append("volatile "); } int len = modifiers.length(); if (len == 0) return ""; modifiers.setLength(len - 1); return modifiers.toString(); }