List of usage examples for org.eclipse.jdt.core Flags isAbstract
public static boolean isAbstract(int flags)
abstract
modifier. From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isAbstract(IMember member) throws JavaModelException { int flags = member.getFlags(); if (!member.isBinary() && isInterfaceOrAnnotationMethod(member)) { return !Flags.isStatic(flags) && !Flags.isDefaultMethod(flags); }// www . j a v a 2s . c o m return Flags.isAbstract(flags); }
From source file:bndtools.editor.components.ComponentNameProposalProvider.java
License:Open Source License
@Override protected List<IContentProposal> doGenerateProposals(String contents, int position) { final String prefix = contents.substring(0, position); IJavaProject javaProject = searchContext.getJavaProject(); final List<IContentProposal> result = new ArrayList<IContentProposal>(100); // Resource matches IProject project = javaProject.getProject(); try {//from ww w. ja va2 s. co m project.accept(new IResourceProxyVisitor() { public boolean visit(IResourceProxy proxy) throws CoreException { if (proxy.getType() == IResource.FILE) { if (proxy.getName().toLowerCase().startsWith(prefix) && proxy.getName().toLowerCase().endsWith(XML_SUFFIX)) { result.add(new ResourceProposal(proxy.requestResource())); } return false; } // Recurse into everything else return true; } }, 0); } catch (CoreException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for resources.", e)); } // Class matches final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); final TypeNameRequestor requestor = new TypeNameRequestor() { @Override public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { if (!Flags.isAbstract(modifiers) && (Flags.isPublic(modifiers) || Flags.isProtected(modifiers))) { result.add(new JavaContentProposal(new String(packageName), new String(simpleTypeName), false)); } }; }; final 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, scope, requestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }; IRunnableContext runContext = searchContext.getRunContext(); try { if (runContext != null) { runContext.run(false, false, runnable); } else { runnable.run(new NullProgressMonitor()); } } catch (InvocationTargetException e) { Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for classes.", e.getTargetException())); } catch (InterruptedException e) { // Reset the interruption status and continue Thread.currentThread().interrupt(); } return result; }
From source file:bndtools.internal.testcaseselection.JavaSearchScopeTestCaseLister.java
License:Open Source License
@Override public String[] getTestCases(boolean includeNonSource, ITestCaseFilter filter) throws TestCaseListException { final List<IJavaElement> testCaseList = new LinkedList<IJavaElement>(); search(Arrays.asList("junit.framework.TestCase", "junit.framework.TestSuite"), testCaseList); //$NON-NLS-1$ //$NON-NLS-2$ // Remove non-source and excludes Set<String> testCaseNames = new LinkedHashSet<String>(); for (Iterator<IJavaElement> iter = testCaseList.iterator(); iter.hasNext();) { boolean omit = false; IJavaElement element = iter.next(); try {//w w w . ja v a2s .c om IType type = (IType) element.getAncestor(IJavaElement.TYPE); if (Flags.isAbstract(type.getFlags())) { omit = true; } if (!includeNonSource) { IPackageFragment pkgFragment = (IPackageFragment) element .getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (pkgFragment.getCompilationUnits().length == 0) { omit = true; } } } catch (JavaModelException e) { throw new TestCaseListException(e); } String className = getClassName(element); if (filter != null && !filter.select(className)) { omit = true; } if (!omit) { testCaseNames.add(className); } } return testCaseNames.toArray(new String[0]); }
From source file:ca.uvic.chisel.diver.sequencediagrams.sc.java.editors.JavaSequenceLabelProvider.java
License:Open Source License
/** * This is the only method that is additional to the standard JFace label providers. * In this implementation, classes are /*from w w w . j a v a 2 s . c om*/ */ public String getStereoType(Object element) { if (!(element instanceof IAdaptable)) { return null; } IJavaElement javaElement = (IJavaElement) ((IAdaptable) element).getAdapter(IJavaElement.class); if (javaElement instanceof IType) { try { if (((IType) javaElement).isInterface()) { return "interface"; } else if (Flags.isAbstract(((IType) javaElement).getFlags())) { return "abstract"; } } catch (JavaModelException e) { } } return null; }
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); }//from w ww . jav a2 s.c om 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 . ja va 2s . 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.gle2.CustomViewFinder.java
License:Open Source License
/** * Determines whether the given member is a valid android.view.View to be added to the * list of custom views or third party views. It checks that the view is public and * not abstract for example.//w w w . j a v a2s . c om */ private static boolean isValidView(IType type, boolean layoutsOnly) throws JavaModelException { // Skip anonymous classes if (type.isAnonymous()) { return false; } int flags = type.getFlags(); if (Flags.isAbstract(flags) || !Flags.isPublic(flags)) { return false; } // TODO: if (layoutsOnly) perhaps try to filter out AdapterViews and other ViewGroups // not willing to accept children via XML // See if the class has one of the acceptable constructors // needed for XML instantiation: // View(Context context) // View(Context context, AttributeSet attrs) // View(Context context, AttributeSet attrs, int defStyle) // We don't simply do three direct checks via type.getMethod() because the types // are not resolved, so we don't know for each parameter if we will get the // fully qualified or the unqualified class names. // Instead, iterate over the methods and look for a match. String typeName = type.getElementName(); for (IMethod method : type.getMethods()) { // Only care about constructors if (!method.getElementName().equals(typeName)) { continue; } String[] parameterTypes = method.getParameterTypes(); if (parameterTypes == null || parameterTypes.length < 1 || parameterTypes.length > 3) { continue; } String first = parameterTypes[0]; // Look for the parameter type signatures -- produced by // JDT's Signature.createTypeSignature("Context", false /*isResolved*/);. // This is not a typo; they were copy/pasted from the actual parameter names // observed in the debugger examining these data structures. if (first.equals("QContext;") //$NON-NLS-1$ || first.equals("Qandroid.content.Context;")) { //$NON-NLS-1$ if (parameterTypes.length == 1) { return true; } String second = parameterTypes[1]; if (second.equals("QAttributeSet;") //$NON-NLS-1$ || second.equals("Qandroid.util.AttributeSet;")) { //$NON-NLS-1$ if (parameterTypes.length == 2) { return true; } String third = parameterTypes[2]; if (third.equals("I")) { //$NON-NLS-1$ if (parameterTypes.length == 3) { return true; } } } } } return false; }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java
License:Open Source License
@Override public String displayFragmentSourceInput() { try {//from www. j a va 2 s. c om // 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 {//ww w.jav 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.editors.manifest.model.UiClassAttributeNode.java
License:Open Source License
@Override public String[] getPossibleValues(String prefix) { // Compute a list of existing classes for content assist completion IProject project = getProject();/*from w w w . j a va 2 s .c o m*/ if (project == null || mReferenceClass == null) { return null; } try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(project); IType type = javaProject.findType(mReferenceClass); // Use sets because query sometimes repeats the same class Set<String> libraryTypes = new HashSet<String>(80); Set<String> localTypes = new HashSet<String>(30); if (type != null) { ITypeHierarchy hierarchy = type.newTypeHierarchy(new NullProgressMonitor()); IType[] allSubtypes = hierarchy.getAllSubtypes(type); for (IType subType : allSubtypes) { int flags = subType.getFlags(); if (Flags.isPublic(flags) && !Flags.isAbstract(flags)) { String fqcn = subType.getFullyQualifiedName(); if (subType.getResource() != null) { localTypes.add(fqcn); } else { libraryTypes.add(fqcn); } } } } List<String> local = new ArrayList<String>(localTypes); List<String> library = new ArrayList<String>(libraryTypes); Collections.sort(local); Collections.sort(library); List<String> combined = new ArrayList<String>(local.size() + library.size()); combined.addAll(local); combined.addAll(library); return combined.toArray(new String[combined.size()]); } catch (Exception e) { AdtPlugin.log(e, null); } return null; }