Example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccPublic

List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccPublic

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccPublic.

Prototype

int AccPublic

To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccPublic.

Click Source Link

Usage

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaASTHelper.java

License:Apache License

private boolean isPublic(int ecjModifier) {
    return (ecjModifier & ClassFileConstants.AccPublic) != 0;
}

From source file:com.android.build.gradle.tasks.annotations.TypedefCollector.java

License:Apache License

private boolean recordTypedefs(TypeDeclaration declaration) {
    SourceTypeBinding binding = declaration.binding;
    if (binding == null) {
        return false;
    }/*from  w ww.j a v  a  2  s. co  m*/
    Annotation[] annotations = declaration.annotations;
    if (annotations != null) {
        if (declaration.binding.isAnnotationType()) {
            for (Annotation annotation : annotations) {
                String typeName = Extractor.getFqn(annotation);
                if (typeName == null) {
                    continue;
                }

                if (Extractor.isNestedAnnotation(typeName)) {
                    String fqn = new String(binding.readableName());

                    List<Annotation> list = mMap.get(fqn);
                    if (list == null) {
                        list = new ArrayList<Annotation>(2);
                        mMap.put(fqn, list);
                    }
                    list.add(annotation);

                    if (mRequireHide) {
                        Javadoc javadoc = declaration.javadoc;
                        if (javadoc != null) {
                            StringBuffer stringBuffer = new StringBuffer(200);
                            javadoc.print(0, stringBuffer);
                            String documentation = stringBuffer.toString();
                            if (!documentation.contains("@hide")) {
                                Extractor.warning(getFileName() + ": The typedef annotation " + fqn
                                        + " should specify @hide in a doc comment");
                            }
                        }
                    }
                    if (mRequireSourceRetention && !Extractor.hasSourceRetention(annotations)) {
                        Extractor.warning(getFileName() + ": The typedef annotation " + fqn
                                + " should have @Retention(RetentionPolicy.SOURCE)");
                    }
                    if (declaration.binding != null
                            && (declaration.modifiers & ClassFileConstants.AccPublic) == 0) {
                        StringBuilder sb = new StringBuilder(100);
                        for (char c : declaration.binding.qualifiedPackageName()) {
                            if (c == '.') {
                                sb.append('/');
                            } else {
                                sb.append(c);
                            }
                        }
                        sb.append(File.separatorChar);
                        for (char c : declaration.binding.qualifiedSourceName()) {
                            if (c == '.') {
                                sb.append('$');
                            } else {
                                sb.append(c);
                            }
                        }
                        mTypedefClasses.add(sb.toString());
                    }
                }
            }
        }
    }
    return true;
}

From source file:com.android.tools.lint.psi.EcjPsiBuilder.java

License:Apache License

private EcjPsiModifierList toModifierList(@NonNull EcjPsiSourceElement parent, int modifiers,
        Annotation[] annotations) {
    int flags = 0;
    if ((modifiers & ClassFileConstants.AccStatic) != 0) {
        flags |= Modifier.STATIC;
    }/*  ww  w .  j  ava2s .c  o m*/
    if ((modifiers & ClassFileConstants.AccFinal) != 0) {
        flags |= Modifier.FINAL;
    }
    if ((modifiers & ClassFileConstants.AccAbstract) != 0) {
        flags |= Modifier.ABSTRACT;
    }
    if ((modifiers & ClassFileConstants.AccPrivate) != 0) {
        flags |= Modifier.PRIVATE;
    }
    if ((modifiers & ClassFileConstants.AccProtected) != 0) {
        flags |= Modifier.PROTECTED;
    }
    if ((modifiers & ClassFileConstants.AccPublic) != 0) {
        flags |= Modifier.PUBLIC;
    }
    if ((modifiers & ClassFileConstants.AccSynchronized) != 0) {
        flags |= Modifier.SYNCHRONIZED;
    }
    if ((modifiers & ClassFileConstants.AccVolatile) != 0) {
        flags |= Modifier.VOLATILE;
    }
    if ((modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0) {
        flags |= EcjPsiModifierList.DEFAULT_MASK;
    }

    EcjPsiModifierList modifierList = new EcjPsiModifierList(mManager, flags);
    parent.adoptChild(modifierList);
    EcjPsiAnnotation[] psiAnnotations = toAnnotations(modifierList, annotations);
    modifierList.setAnnotations(psiAnnotations);
    return modifierList;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ConstructorDeclarationPattern.java

License:Open Source License

public void decodeIndexKey(char[] key) {
    int last = key.length - 1;
    int slash = CharOperation.indexOf(SEPARATOR, key, 0);
    this.declaringSimpleName = CharOperation.subarray(key, 0, slash);

    int start = slash + 1;
    slash = CharOperation.indexOf(SEPARATOR, key, start);
    last = slash - 1;//from   w  ww. j ava  2  s  .  c o m

    boolean isDefaultConstructor = key[last] == '#';
    if (isDefaultConstructor) {
        this.parameterCount = -1;
    } else {
        this.parameterCount = 0;
        int power = 1;
        for (int i = last; i >= start; i--) {
            if (i == last) {
                this.parameterCount = key[i] - '0';
            } else {
                power *= 10;
                this.parameterCount += power * (key[i] - '0');
            }
        }
    }

    slash = slash + 3;
    last = slash - 1;

    int typeModifiersWithExtraFlags = key[last - 1] + (key[last] << 16);
    this.declaringTypeModifiers = decodeModifers(typeModifiersWithExtraFlags);
    this.extraFlags = decodeExtraFlags(typeModifiersWithExtraFlags);

    // initialize optional fields
    this.declaringPackageName = null;
    this.modifiers = 0;
    this.signature = null;
    this.parameterTypes = null;
    this.parameterNames = null;

    boolean isMemberType = (this.extraFlags & ExtraFlags.IsMemberType) != 0;

    if (!isMemberType) {
        start = slash + 1;
        if (this.parameterCount == -1) {
            slash = key.length;
            last = slash - 1;
        } else {
            slash = CharOperation.indexOf(SEPARATOR, key, start);
        }
        last = slash - 1;

        this.declaringPackageName = CharOperation.subarray(key, start, slash);

        start = slash + 1;
        if (this.parameterCount == 0) {
            slash = slash + 3;
            last = slash - 1;

            this.modifiers = key[last - 1] + (key[last] << 16);
        } else if (this.parameterCount > 0) {
            slash = CharOperation.indexOf(SEPARATOR, key, start);
            last = slash - 1;

            boolean hasParameterStoredAsSignature = (this.extraFlags
                    & ExtraFlags.ParameterTypesStoredAsSignature) != 0;
            if (hasParameterStoredAsSignature) {
                this.signature = CharOperation.subarray(key, start, slash);
                CharOperation.replace(this.signature, '\\', SEPARATOR);
            } else {
                this.parameterTypes = CharOperation.splitOn(PARAMETER_SEPARATOR, key, start, slash);
            }
            start = slash + 1;
            slash = CharOperation.indexOf(SEPARATOR, key, start);
            last = slash - 1;

            if (slash != start) {
                this.parameterNames = CharOperation.splitOn(PARAMETER_SEPARATOR, key, start, slash);
            }

            slash = slash + 3;
            last = slash - 1;

            this.modifiers = key[last - 1] + (key[last] << 16);
        } else {
            this.modifiers = ClassFileConstants.AccPublic;
        }
    }

    removeInternalFlags(); // remove internal flags
}

From source file:lombok.eclipse.agent.PatchDelegate.java

License:Open Source License

private static MethodDeclaration createDelegateMethod(char[] name, EclipseNode typeNode, BindingTuple pair,
        CompilationResult compilationResult, EclipseNode annNode, DelegateReceiver delegateReceiver) {
    /* public <T, U, ...> ReturnType methodName(ParamType1 name1, ParamType2 name2, ...) throws T1, T2, ... {
     *      (return) delegate.<T, U>methodName(name1, name2);
     *  }/*  w  w  w .  jav a 2 s .  c  o  m*/
     */

    boolean isVarargs = (pair.base.modifiers & ClassFileConstants.AccVarargs) != 0;

    try {
        checkConflictOfTypeVarNames(pair, typeNode);
    } catch (CantMakeDelegates e) {
        annNode.addError(
                "There's a conflict in the names of type parameters. Fix it by renaming the following type parameters of your class: "
                        + e.conflicted);
        return null;
    }

    ASTNode source = annNode.get();

    int pS = source.sourceStart, pE = source.sourceEnd;

    MethodBinding binding = pair.parameterized;
    MethodDeclaration method = new MethodDeclaration(compilationResult);
    setGeneratedBy(method, source);
    method.sourceStart = pS;
    method.sourceEnd = pE;
    method.modifiers = ClassFileConstants.AccPublic;

    method.returnType = makeType(binding.returnType, source, false);
    boolean isDeprecated = binding.isDeprecated();

    method.selector = binding.selector;

    if (binding.thrownExceptions != null && binding.thrownExceptions.length > 0) {
        method.thrownExceptions = new TypeReference[binding.thrownExceptions.length];
        for (int i = 0; i < method.thrownExceptions.length; i++) {
            method.thrownExceptions[i] = makeType(binding.thrownExceptions[i], source, false);
        }
    }

    MessageSend call = new MessageSend();
    call.sourceStart = pS;
    call.sourceEnd = pE;
    call.nameSourcePosition = pos(source);
    setGeneratedBy(call, source);
    call.receiver = delegateReceiver.get(source, name);
    call.selector = binding.selector;

    if (binding.typeVariables != null && binding.typeVariables.length > 0) {
        method.typeParameters = new TypeParameter[binding.typeVariables.length];
        call.typeArguments = new TypeReference[binding.typeVariables.length];
        for (int i = 0; i < method.typeParameters.length; i++) {
            method.typeParameters[i] = new TypeParameter();
            method.typeParameters[i].sourceStart = pS;
            method.typeParameters[i].sourceEnd = pE;
            setGeneratedBy(method.typeParameters[i], source);
            method.typeParameters[i].name = binding.typeVariables[i].sourceName;
            call.typeArguments[i] = new SingleTypeReference(binding.typeVariables[i].sourceName, pos(source));
            setGeneratedBy(call.typeArguments[i], source);
            ReferenceBinding super1 = binding.typeVariables[i].superclass;
            ReferenceBinding[] super2 = binding.typeVariables[i].superInterfaces;
            if (super2 == null)
                super2 = new ReferenceBinding[0];
            if (super1 != null || super2.length > 0) {
                int offset = super1 == null ? 0 : 1;
                method.typeParameters[i].bounds = new TypeReference[super2.length + offset - 1];
                if (super1 != null)
                    method.typeParameters[i].type = makeType(super1, source, false);
                else
                    method.typeParameters[i].type = makeType(super2[0], source, false);
                int ctr = 0;
                for (int j = (super1 == null) ? 1 : 0; j < super2.length; j++) {
                    method.typeParameters[i].bounds[ctr] = makeType(super2[j], source, false);
                    method.typeParameters[i].bounds[ctr++].bits |= ASTNode.IsSuperType;
                }
            }
        }
    }

    if (isDeprecated) {
        method.annotations = new Annotation[] { generateDeprecatedAnnotation(source) };
    }

    method.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;

    if (binding.parameters != null && binding.parameters.length > 0) {
        method.arguments = new Argument[binding.parameters.length];
        call.arguments = new Expression[method.arguments.length];
        for (int i = 0; i < method.arguments.length; i++) {
            AbstractMethodDeclaration sourceElem;
            try {
                sourceElem = pair.base.sourceMethod();
            } catch (Exception e) {
                sourceElem = null;
            }
            char[] argName;
            if (sourceElem == null)
                argName = ("arg" + i).toCharArray();
            else {
                argName = sourceElem.arguments[i].name;
            }
            method.arguments[i] = new Argument(argName, pos(source),
                    makeType(binding.parameters[i], source, false), ClassFileConstants.AccFinal);
            setGeneratedBy(method.arguments[i], source);
            call.arguments[i] = new SingleNameReference(argName, pos(source));
            setGeneratedBy(call.arguments[i], source);
        }
        if (isVarargs) {
            method.arguments[method.arguments.length - 1].type.bits |= ASTNode.IsVarArgs;
        }
    }

    Statement body;
    if (method.returnType instanceof SingleTypeReference
            && ((SingleTypeReference) method.returnType).token == TypeConstants.VOID) {
        body = call;
    } else {
        body = new ReturnStatement(call, source.sourceStart, source.sourceEnd);
        setGeneratedBy(body, source);
    }

    method.statements = new Statement[] { body };
    return method;
}

From source file:lombok.eclipse.handlers.EclipseHandlerUtil.java

License:Open Source License

/**
 * Turns an {@code AccessLevel} instance into the flag bit used by eclipse.
 *///from w w  w . j a  v a2 s  . c o  m
public static int toEclipseModifier(AccessLevel value) {
    switch (value) {
    case MODULE:
    case PACKAGE:
        return 0;
    default:
    case PUBLIC:
        return ClassFileConstants.AccPublic;
    case PROTECTED:
        return ClassFileConstants.AccProtected;
    case NONE:
    case PRIVATE:
        return ClassFileConstants.AccPrivate;
    }
}

From source file:lombok.eclipse.handlers.HandleBuilder.java

License:Open Source License

private MethodDeclaration generateToBuilderMethod(String methodName, String builderClassName, EclipseNode type,
        TypeParameter[] typeParams, List<BuilderFieldData> builderFields, boolean fluent, ASTNode source) {
    // return new ThingieBuilder<A, B>().setA(this.a).setB(this.b);

    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = methodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);

    Expression receiver = invoke;
    for (BuilderFieldData bfd : builderFields) {
        char[] setterName = fluent ? bfd.name
                : HandlerUtil.buildAccessorName("set", new String(bfd.name)).toCharArray();
        MessageSend ms = new MessageSend();
        if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) {
            char[] fieldName = bfd.obtainVia == null ? bfd.rawName : bfd.obtainVia.field().toCharArray();
            FieldReference fr = new FieldReference(fieldName, 0);
            fr.receiver = new ThisReference(0, 0);
            ms.arguments = new Expression[] { fr };
        } else {/*from   www.j  av  a2 s.  co m*/
            String obtainName = bfd.obtainVia.method();
            boolean obtainIsStatic = bfd.obtainVia.isStatic();
            MessageSend obtainExpr = new MessageSend();
            obtainExpr.receiver = obtainIsStatic ? new SingleNameReference(type.getName().toCharArray(), 0)
                    : new ThisReference(0, 0);
            obtainExpr.selector = obtainName.toCharArray();
            if (obtainIsStatic)
                obtainExpr.arguments = new Expression[] { new ThisReference(0, 0) };
            ms.arguments = new Expression[] { obtainExpr };
        }
        ms.receiver = receiver;
        ms.selector = setterName;
        receiver = ms;
    }

    out.statements = new Statement[] { new ReturnStatement(receiver, pS, pE) };

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;

}

From source file:lombok.eclipse.handlers.HandleBuilder.java

License:Open Source License

public MethodDeclaration generateBuildMethod(String name, char[] staticName, TypeReference returnType,
        List<BuilderFieldData> builderFields, EclipseNode type, TypeReference[] thrownExceptions,
        boolean addCleaning, ASTNode source) {
    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    List<Statement> statements = new ArrayList<Statement>();

    if (addCleaning) {
        FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
        thisUnclean.receiver = new ThisReference(0, 0);
        Expression notClean = new UnaryExpression(thisUnclean, OperatorIds.NOT);
        MessageSend invokeClean = new MessageSend();
        invokeClean.selector = CLEAN_METHOD_NAME;
        statements.add(new IfStatement(notClean, invokeClean, 0, 0));
    }//w w w.j  a  v  a  2s  .  c o m

    for (BuilderFieldData bfd : builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, type, statements, bfd.name);
        }
    }

    List<Expression> args = new ArrayList<Expression>();
    for (BuilderFieldData bfd : builderFields) {
        args.add(new SingleNameReference(bfd.name, 0L));
    }

    if (addCleaning) {
        FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0);
        thisUnclean.receiver = new ThisReference(0, 0);
        statements.add(new Assignment(thisUnclean, new TrueLiteral(0, 0), 0));
    }

    out.modifiers = ClassFileConstants.AccPublic;
    out.selector = name.toCharArray();
    out.thrownExceptions = copyTypes(thrownExceptions);
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = returnType;

    if (staticName == null) {
        AllocationExpression allocationStatement = new AllocationExpression();
        allocationStatement.type = copyType(out.returnType);
        allocationStatement.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]);
        statements.add(new ReturnStatement(allocationStatement, 0, 0));
    } else {
        MessageSend invoke = new MessageSend();
        invoke.selector = staticName;
        invoke.receiver = new SingleNameReference(type.up().getName().toCharArray(), 0);
        TypeParameter[] tps = ((TypeDeclaration) type.get()).typeParameters;
        if (tps != null) {
            TypeReference[] trs = new TypeReference[tps.length];
            for (int i = 0; i < trs.length; i++) {
                trs[i] = new SingleTypeReference(tps[i].name, 0);
            }
            invoke.typeArguments = trs;
        }
        invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]);
        if (returnType instanceof SingleTypeReference
                && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) {
            statements.add(invoke);
        } else {
            statements.add(new ReturnStatement(invoke, 0, 0));
        }
    }
    out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]);
    out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null);
    return out;
}

From source file:lombok.eclipse.handlers.HandleBuilder.java

License:Open Source License

public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName,
        EclipseNode type, TypeParameter[] typeParams, ASTNode source) {
    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;

    MethodDeclaration out = new MethodDeclaration(
            ((CompilationUnitDeclaration) type.top().get()).compilationResult);
    out.selector = builderMethodName.toCharArray();
    out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic;
    out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.typeParameters = copyTypeParams(typeParams, source);
    AllocationExpression invoke = new AllocationExpression();
    invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p);
    out.statements = new Statement[] { new ReturnStatement(invoke, pS, pE) };

    out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope);
    return out;//from www. jav  a2s  .  co m
}

From source file:lombok.eclipse.handlers.HandleBuilder.java

License:Open Source License

private void makeSimpleSetterMethodForBuilder(EclipseNode builderType, EclipseNode fieldNode,
        EclipseNode sourceNode, boolean fluent, boolean chain) {
    TypeDeclaration td = (TypeDeclaration) builderType.get();
    AbstractMethodDeclaration[] existing = td.methods;
    if (existing == null)
        existing = EMPTY;//w w w .  ja v a  2s  . c  o  m
    int len = existing.length;
    FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
    char[] name = fd.name;

    for (int i = 0; i < len; i++) {
        if (!(existing[i] instanceof MethodDeclaration))
            continue;
        char[] existingName = existing[i].selector;
        if (Arrays.equals(name, existingName))
            return;
    }

    String setterName = fluent ? fieldNode.getName()
            : HandlerUtil.buildAccessorName("set", fieldNode.getName());

    MethodDeclaration setter = HandleSetter.createSetter(td, fieldNode, setterName, chain,
            ClassFileConstants.AccPublic, sourceNode, Collections.<Annotation>emptyList(),
            Collections.<Annotation>emptyList());
    injectMethod(builderType, setter);
}