List of usage examples for org.eclipse.jdt.core Flags isPrivate
public static boolean isPrivate(int flags)
private
modifier. From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java
License:Open Source License
/** * Evaluates if a member in the focus' element hierarchy is visible from * elements in a package./* ww w .j av a 2s . c o m*/ * @param member The member to test the visibility for * @param pack The package of the focus element focus * @return returns <code>true</code> if the member is visible from the package * @throws JavaModelException thrown when the member can not be accessed */ public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack) throws JavaModelException { int type = member.getElementType(); if (type == IJavaElement.INITIALIZER || (type == IJavaElement.METHOD && member.getElementName().startsWith("<"))) { //$NON-NLS-1$ return false; } int otherflags = member.getFlags(); IType declaringType = member.getDeclaringType(); if (Flags.isPublic(otherflags) || Flags.isProtected(otherflags) || (declaringType != null && isInterfaceOrAnnotation(declaringType))) { return true; } else if (Flags.isPrivate(otherflags)) { return false; } IPackageFragment otherpack = (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT); return (pack != null && pack.equals(otherpack)); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isPrivate(IMember member) throws JavaModelException { return Flags.isPrivate(member.getFlags()); }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
/** * Finds the method that is overridden by the given method. * First the super class is examined and then the implemented interfaces. * @param overriding the overriding method * @param testVisibility If true the result is tested on visibility. Null is returned if the method is not visible. * @return a method that is directly overridden by the given method, or <code>null</code> * @throws JavaModelException if a problem occurs *///from w ww .j a v a 2s .c om public IMethod findOverriddenMethod(IMethod overriding, boolean testVisibility) throws JavaModelException { int flags = overriding.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) { return null; } IType type = overriding.getDeclaringType(); IType superClass = fHierarchy.getSuperclass(type); if (superClass != null) { IMethod res = findOverriddenMethodInHierarchy(superClass, overriding); if (res != null) { if (!testVisibility || JavaModelUtil.isVisibleInHierarchy(res, type.getPackageFragment())) { return res; } } } IType[] interfaces = fHierarchy.getSuperInterfaces(type); for (int i = 0; i < interfaces.length; i++) { IMethod res = findOverriddenMethodInHierarchy(interfaces[i], overriding); if (res != null) { return res; // methods from interfaces are always public and therefore visible } } return null; }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
/** * Finds an overridden method in a type. With generics it is possible that 2 methods in the same type are overridden at the same time. * In that case the first overridden method found is returned. * @param overriddenType The type to find methods in * @param overriding The overriding method * @return The first overridden method or <code>null</code> if no method is overridden * @throws JavaModelException if a problem occurs *//*w ww. j a v a2s .c o m*/ public IMethod findOverriddenMethodInType(IType overriddenType, IMethod overriding) throws JavaModelException { int flags = overriding.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) return null; IMethod[] overriddenMethods = overriddenType.getMethods(); for (int i = 0; i < overriddenMethods.length; i++) { IMethod overridden = overriddenMethods[i]; flags = overridden.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor()) continue; if (isSubsignature(overriding, overridden)) { return overridden; } } return null; }
From source file:at.bestsolution.fxide.jdt.corext.util.MethodOverrideTester.java
License:Open Source License
/** * Finds an overriding method in a type. * @param overridingType The type to find methods in * @param overridden The overridden method * @return The overriding method or <code>null</code> if no method is overriding. * @throws JavaModelException if a problem occurs *///w w w.j a va 2 s . c o m public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden) throws JavaModelException { int flags = overridden.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor()) return null; IMethod[] overridingMethods = overridingType.getMethods(); for (int i = 0; i < overridingMethods.length; i++) { IMethod overriding = overridingMethods[i]; flags = overriding.getFlags(); if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) continue; if (isSubsignature(overriding, overridden)) { return overriding; } } return null; }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private IMethod findActivateMethod(IType implClassType, String name, IProgressMonitor monitor) throws JavaModelException { IMethod candidate = null;/*from w w w . j a v a 2s.c om*/ int priority = Integer.MAX_VALUE; IType type = implClassType; while (type != null) { for (IMethod method : type.getMethods()) { if (!name.equals(method.getElementName())) continue; if (!VOID_SIG.equals(method.getReturnType())) continue; if (type != implClassType && (Flags.isPrivate(method.getFlags()) || (Flags.isPackageDefault(method.getFlags()) && !implClassType.getPackageFragment() .equals(method.getDeclaringType().getPackageFragment())))) continue; String[] paramSigs = resolveParameterTypes(method, Integer.MAX_VALUE); if (paramSigs.length == 1 && COMPONENT_CONTEXT_SIG.equals(paramSigs[0])) { // best match return method; } if (priority > 1 && paramSigs.length == 1 && COMPONENT_CONTEXT_SIG.equals(paramSigs[0])) { candidate = method; priority = 1; continue; } if (priority > 2 && paramSigs.length == 1 && MAP_SIG.equals(paramSigs[0])) { candidate = method; priority = 2; continue; } if (priority > 3 && paramSigs.length >= 2) { boolean valid = true; for (String paramSig : paramSigs) { if (!COMPONENT_CONTEXT_SIG.equals(paramSig) && !BUNDLE_CONTEXT_SIG.equals(paramSig) && !MAP_SIG.equals(paramSig)) { valid = false; break; } } if (valid) { candidate = method; priority = 3; } continue; } if (priority > 4 && paramSigs.length == 0) { candidate = method; priority = 4; continue; } } type = findSuperclassType(type, implClassType.getJavaProject(), monitor); } return candidate; }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private IMethod findDeactivateMethod(IType implClassType, String name, IProgressMonitor monitor) throws JavaModelException { IMethod candidate = null;/*from www . j a v a 2s . c o m*/ int priority = Integer.MAX_VALUE; IType type = implClassType; while (type != null) { for (IMethod method : type.getMethods()) { if (!name.equals(method.getElementName())) continue; if (!VOID_SIG.equals(method.getReturnType())) continue; if (type != implClassType && (Flags.isPrivate(method.getFlags()) || (Flags.isPackageDefault(method.getFlags()) && !implClassType.getPackageFragment() .equals(method.getDeclaringType().getPackageFragment())))) continue; String[] paramSigs = resolveParameterTypes(method, Integer.MAX_VALUE); if (paramSigs.length == 1 && COMPONENT_CONTEXT_SIG.equals(paramSigs[0])) { // best match return method; } if (priority > 1 && paramSigs.length == 1 && COMPONENT_CONTEXT_SIG.equals(paramSigs[0])) { candidate = method; priority = 1; continue; } if (priority > 2 && paramSigs.length == 1 && MAP_SIG.equals(paramSigs[0])) { candidate = method; priority = 2; continue; } if (priority > 3 && paramSigs.length == 1 && INT_SIG.equals(paramSigs[0])) { candidate = method; priority = 3; continue; } if (priority > 4 && paramSigs.length == 1 && INTEGER_SIG.equals(paramSigs[0])) { candidate = method; priority = 4; continue; } if (priority > 5 && paramSigs.length >= 2) { boolean valid = true; for (String paramSig : paramSigs) { if (!COMPONENT_CONTEXT_SIG.equals(paramSig) && !BUNDLE_CONTEXT_SIG.equals(paramSig) && !MAP_SIG.equals(paramSig) && !INT_SIG.equals(paramSig) && !INTEGER_SIG.equals(paramSig)) { valid = false; break; } } if (valid) { candidate = method; priority = 5; } continue; } if (priority > 6 && paramSigs.length == 0) { candidate = method; priority = 6; continue; } } type = findSuperclassType(type, implClassType.getJavaProject(), monitor); } return candidate; }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private IMethod findBindMethod(IType implClassType, String name, String referenceTypeName, IProgressMonitor monitor) throws JavaModelException { IMethod candidate = null;//from w w w. j a v a 2 s . co m int priority = Integer.MAX_VALUE; String referenceTypeSig = Signature.createTypeSignature(referenceTypeName, true); IType referenceType = null; IType arg0Type = null; IType type = implClassType; while (type != null) { for (IMethod method : type.getMethods()) { if (!name.equals(method.getElementName())) continue; if (!VOID_SIG.equals(method.getReturnType())) continue; if (type != implClassType && (Flags.isPrivate(method.getFlags()) || (Flags.isPackageDefault(method.getFlags()) && !implClassType.getPackageFragment() .equals(method.getDeclaringType().getPackageFragment())))) continue; String[] paramSigs = resolveParameterTypes(method, 2); if (paramSigs.length == 1 && SERVICE_REFERENCE_SIG.equals(paramSigs[0])) { // best match return method; } if (priority > 1 && paramSigs.length == 1 && referenceTypeSig.equals(paramSigs[0])) { candidate = method; priority = 1; continue; } if (priority > 2 && paramSigs.length == 1) { if (referenceType == null) referenceType = implClassType.getJavaProject().findType(referenceTypeName, monitor); if (arg0Type == null) arg0Type = implClassType.getJavaProject().findType(Signature.toString(paramSigs[0]), monitor); if (isAssignableFrom(arg0Type, referenceType, monitor)) { candidate = method; priority = 2; } continue; } if (priority > 3 && paramSigs.length == 2 && referenceTypeSig.equals(paramSigs[0]) && MAP_SIG.equals(paramSigs[1])) { candidate = method; priority = 3; continue; } if (priority > 4 && paramSigs.length == 2 && MAP_SIG.equals(paramSigs[1])) { if (referenceType == null) referenceType = implClassType.getJavaProject().findType(referenceTypeName, monitor); if (arg0Type == null) arg0Type = implClassType.getJavaProject().findType(Signature.toString(paramSigs[0]), monitor); if (isAssignableFrom(arg0Type, referenceType, monitor)) { candidate = method; priority = 4; } continue; } } type = findSuperclassType(type, implClassType.getJavaProject(), monitor); } return candidate; }
From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java
License:Open Source License
private IMethod findUpdatedMethod(IType implClassType, String name, IProgressMonitor monitor) throws JavaModelException { IMethod candidate = null;//from w w w .j ava 2 s . c o m IType type = implClassType; while (type != null) { for (IMethod method : type.getMethods()) { if (!name.equals(method.getElementName())) continue; if (!VOID_SIG.equals(method.getReturnType())) continue; if (type != implClassType && (Flags.isPrivate(method.getFlags()) || (Flags.isPackageDefault(method.getFlags()) && !implClassType.getPackageFragment() .equals(method.getDeclaringType().getPackageFragment())))) continue; String[] paramSigs = resolveParameterTypes(method, 1); if (paramSigs.length != 1) continue; if (SERVICE_REFERENCE_SIG.equals(paramSigs[0])) { // best match return method; } if (candidate == null && MAP_SIG.equals(paramSigs[0])) { candidate = method; } } type = findSuperclassType(type, implClassType.getJavaProject(), monitor); } return candidate; }
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 .ja 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; }