Example usage for org.eclipse.jdt.core.dom Modifier isPublic

List of usage examples for org.eclipse.jdt.core.dom Modifier isPublic

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Modifier isPublic.

Prototype

public static boolean isPublic(int flags) 

Source Link

Document

Returns whether the given flags includes the "public" modifier.

Usage

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static boolean isPublic(IBinding binding) {
    if (isInterfaceOrAnnotationMember(binding))
        return true;
    return Modifier.isPublic(binding.getModifiers());
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static boolean isPublic(BodyDeclaration bodyDeclaration) {
    if (isInterfaceOrAnnotationMember(bodyDeclaration))
        return true;
    return Modifier.isPublic(bodyDeclaration.getModifiers());
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static String getVisibilityString(int visibilityCode) {
    if (Modifier.isPublic(visibilityCode))
        return VISIBILITY_STRING_PUBLIC;
    if (Modifier.isProtected(visibilityCode))
        return VISIBILITY_STRING_PROTECTED;
    if (Modifier.isPrivate(visibilityCode))
        return VISIBILITY_STRING_PRIVATE;
    return VISIBILITY_STRING_PACKAGE;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

@Override
public boolean visit(TypeDeclaration type) {
    if (!Modifier.isPublic(type.getModifiers())) {
        // non-public types cannot be (or have nested) components
        if (errorLevel.isNone())
            return false;

        Annotation annotation = findComponentAnnotation(type);
        if (annotation != null)
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());

        return true;
    }/*from w  ww.j  ava2 s. co  m*/

    Annotation annotation = findComponentAnnotation(type);
    if (annotation != null) {
        if (type.isInterface() || Modifier.isAbstract(type.getModifiers())
                || (!type.isPackageMemberTypeDeclaration() && !isNestedPublicStatic(type))
                || !hasDefaultConstructor(type)) {
            // interfaces, abstract types, non-static/non-public nested types, or types with no default constructor cannot be components
            reportProblem(annotation, null, problems,
                    NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass,
                            type.getName().getIdentifier()),
                    type.getName().getIdentifier());
        } else {
            ITypeBinding typeBinding = type.resolveBinding();
            if (typeBinding == null) {
                if (debug.isDebugging())
                    debug.trace(String.format("Unable to resolve binding for type: %s", type)); //$NON-NLS-1$
            } else {
                IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
                if (annotationBinding == null) {
                    if (debug.isDebugging())
                        debug.trace(String.format("Unable to resolve binding for annotation: %s", annotation)); //$NON-NLS-1$
                } else {
                    IDSModel model = processComponent(type, typeBinding, annotation, annotationBinding,
                            problems);
                    models.add(model);
                }
            }
        }
    }

    return true;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean isNestedPublicStatic(TypeDeclaration type) {
    if (Modifier.isStatic(type.getModifiers())) {
        ASTNode parent = type.getParent();
        if (parent != null && parent.getNodeType() == ASTNode.TYPE_DECLARATION) {
            TypeDeclaration parentType = (TypeDeclaration) parent;
            if (Modifier.isPublic(parentType.getModifiers()))
                return parentType.isPackageMemberTypeDeclaration() || isNestedPublicStatic(parentType);
        }//from w  w  w. j ava2  s.  c  o m
    }

    return false;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean hasDefaultConstructor(TypeDeclaration type) {
    boolean hasConstructor = false;
    for (MethodDeclaration method : type.getMethods()) {
        if (method.isConstructor()) {
            hasConstructor = true;/*from  ww  w.  j  a v a 2  s . c o  m*/
            if (Modifier.isPublic(method.getModifiers()) && method.parameters().isEmpty())
                return true;
        }
    }

    return !hasConstructor;
}

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private IMethodBinding findReferenceMethod(ITypeBinding componentClass, ITypeBinding serviceType, String name) {
    ITypeBinding testedClass = componentClass;

    IMethodBinding candidate = null;/*  ww w .jav a  2s . com*/
    int priority = 0;
    // priority:
    // 0: <assignment-compatible-type>, Map
    // 1: <exact-type>, Map
    // 2: <assignment-compatible-type>
    // 3: <exact-type>
    do {
        for (IMethodBinding declaredMethod : testedClass.getDeclaredMethods()) {
            if (name.equals(declaredMethod.getName())
                    && Void.TYPE.getName().equals(declaredMethod.getReturnType().getName())
                    && (testedClass.isEqualTo(componentClass)
                            || Modifier.isPublic(declaredMethod.getModifiers())
                            || Modifier.isProtected(declaredMethod.getModifiers())
                            || (!Modifier.isPrivate(declaredMethod.getModifiers())
                                    && testedClass.getPackage().isEqualTo(componentClass.getPackage())))) {
                ITypeBinding[] paramTypes = declaredMethod.getParameterTypes();
                if (paramTypes.length == 1) {
                    if (ServiceReference.class.getName().equals(paramTypes[0].getErasure().getQualifiedName()))
                        // we have the winner
                        return declaredMethod;

                    if (priority < 3 && serviceType.isEqualTo(paramTypes[0]))
                        priority = 3;
                    else if (priority < 2 && serviceType.isAssignmentCompatible(paramTypes[0]))
                        priority = 2;
                    else
                        continue;

                    // we have a (better) candidate
                    candidate = declaredMethod;
                } else if (paramTypes.length == 2) {
                    if (priority < 1 && serviceType.isEqualTo(paramTypes[0])
                            && Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName()))
                        priority = 1;
                    else if (candidate != null || !serviceType.isAssignmentCompatible(paramTypes[0])
                            || !Map.class.getName().equals(paramTypes[1].getErasure().getQualifiedName()))
                        continue;

                    // we have a candidate
                    candidate = declaredMethod;
                }
            }
        }
    } while ((testedClass = testedClass.getSuperclass()) != null);

    return candidate;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

/**
 * Appends the text representation of the given modifier flags, followed by
 * a single space. Used for JLS2 modifiers.
 * //from w  w w .  j av  a2 s .  c  om
 * @param modifiers
 *            the modifier flags
 */
void printModifiers(int modifiers) {
    if (Modifier.isPublic(modifiers)) {
        this.buffer.append("public ");//$NON-NLS-1$
    }
    if (Modifier.isProtected(modifiers)) {
        this.buffer.append("protected ");//$NON-NLS-1$
    }
    if (Modifier.isPrivate(modifiers)) {
        this.buffer.append("private ");//$NON-NLS-1$
    }
    if (Modifier.isStatic(modifiers)) {
        this.buffer.append("static ");//$NON-NLS-1$
    }
    if (Modifier.isAbstract(modifiers)) {
        this.buffer.append("abstract ");//$NON-NLS-1$
    }
    if (Modifier.isFinal(modifiers)) {
        this.buffer.append("final ");//$NON-NLS-1$
    }
    if (Modifier.isSynchronized(modifiers)) {
        this.buffer.append("synchronized ");//$NON-NLS-1$
    }
    if (Modifier.isVolatile(modifiers)) {
        this.buffer.append("volatile ");//$NON-NLS-1$
    }
    if (Modifier.isNative(modifiers)) {
        this.buffer.append("native ");//$NON-NLS-1$
    }
    if (Modifier.isStrictfp(modifiers)) {
        this.buffer.append("strictfp ");//$NON-NLS-1$
    }
    if (Modifier.isTransient(modifiers)) {
        this.buffer.append("transient ");//$NON-NLS-1$
    }
}

From source file:com.architexa.diagrams.jdt.extractors.TypeMembersModifierExtractor.java

License:Open Source License

protected void addModifiers(Resource memberDeclRes, int modifiers) {
    if (Modifier.isPublic(modifiers))
        rdfModel.addStatement(memberDeclRes, RJCore.access, RJCore.publicAccess);
    else if (Modifier.isProtected(modifiers))
        rdfModel.addStatement(memberDeclRes, RJCore.access, RJCore.protectedAccess);
    else if (Modifier.isPrivate(modifiers))
        rdfModel.addStatement(memberDeclRes, RJCore.access, RJCore.privateAccess);
    else// www . ja  v a  2 s.c o  m
        rdfModel.addStatement(memberDeclRes, RJCore.access, RJCore.noAccess);

    // should also add static, final, abstract, etc.
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java

License:Open Source License

/**
 * @flowerModelElementId _zVs8ZJiOEd6aNMdNFvR5WQ
 */// w  w w  .j  a va 2 s . c om
public static ModifierKeyword getJavaVisibilityFlagFromJavaClass(BodyDeclaration bd) {
    if (Modifier.isPrivate(bd.getModifiers()))
        return ModifierKeyword.PRIVATE_KEYWORD;
    else if (Modifier.isProtected(bd.getModifiers()))
        return ModifierKeyword.PROTECTED_KEYWORD;
    else if (Modifier.isPublic(bd.getModifiers()))
        return ModifierKeyword.PUBLIC_KEYWORD;
    return null;
}