Search in sources :

Example 16 with AMethod

use of scenelib.annotations.el.AMethod in project checker-framework by typetools.

the class WholeProgramInferenceScenesStorage method getPostconditionsForExpression.

/**
 * Returns the postcondition annotations for a Java expression.
 *
 * @param methodElement the method
 * @param expression the expression
 * @param declaredType the declared type of the expression
 * @return the postcondition annotations for a Java expression
 */
private ATypeElement getPostconditionsForExpression(ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType) {
    AMethod methodAnnos = getMethodAnnos(methodElement);
    postconditionsToDeclaredTypes.put(methodAnnos.methodSignature + expression, declaredType);
    return methodAnnos.vivifyAndAddTypeMirrorToPostcondition(expression, declaredType.getUnderlyingType()).type;
}
Also used : AMethod(scenelib.annotations.el.AMethod)

Example 17 with AMethod

use of scenelib.annotations.el.AMethod in project checker-framework by typetools.

the class WholeProgramInferenceScenesStorage method getParameterAnnotations.

@Override
public ATypeElement getParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory) {
    AMethod methodAnnos = getMethodAnnos(methodElt);
    AField param = methodAnnos.vivifyAndAddTypeMirrorToParameter(i, paramATM.getUnderlyingType(), ve.getSimpleName());
    return param.type;
}
Also used : AMethod(scenelib.annotations.el.AMethod) AField(scenelib.annotations.el.AField)

Example 18 with AMethod

use of scenelib.annotations.el.AMethod in project checker-framework by typetools.

the class SceneToStubWriter method printClass.

/**
 * Print the class body, or nothing if this is an anonymous inner class. Call {@link
 * #isPrintable(String, AClass)} and check that it returns true before calling this method.
 *
 * @param classname the class name
 * @param aClass the representation of the class
 * @param checker the checker, for computing preconditions
 * @param printWriter the writer on which to print
 */
private static void printClass(@BinaryName String classname, AClass aClass, BaseTypeChecker checker, PrintWriter printWriter) {
    String basename = basenamePart(classname);
    String innermostClassname = basename.contains("$") ? basename.substring(basename.lastIndexOf('$') + 1) : basename;
    String pkg = packagePart(classname);
    if (pkg != null) {
        printWriter.println("package " + pkg + ";");
    }
    int curlyCount = printClassDefinitions(basename, aClass, printWriter, checker);
    String indentLevel = indents(curlyCount);
    List<VariableElement> enumConstants = aClass.getEnumConstants();
    if (enumConstants != null) {
        StringJoiner sj = new StringJoiner(", ");
        for (VariableElement enumConstant : enumConstants) {
            sj.add(enumConstant.getSimpleName());
        }
        printWriter.println(indentLevel + "// enum constants:");
        printWriter.println();
        printWriter.println(indentLevel + sj.toString() + ";");
        printWriter.println();
    }
    printFields(aClass, printWriter, indentLevel);
    if (!aClass.getMethods().isEmpty()) {
        // print method signatures
        printWriter.println(indentLevel + "// methods:");
        printWriter.println();
        for (Map.Entry<String, AMethod> methodEntry : aClass.getMethods().entrySet()) {
            printMethodDeclaration(methodEntry.getValue(), innermostClassname, printWriter, indentLevel, checker.getTypeFactory());
        }
    }
    for (int i = 0; i < curlyCount; i++) {
        printWriter.println(indents(curlyCount - i - 1) + "}");
    }
}
Also used : VariableElement(javax.lang.model.element.VariableElement) Map(java.util.Map) AMethod(scenelib.annotations.el.AMethod) StringJoiner(java.util.StringJoiner)

Example 19 with AMethod

use of scenelib.annotations.el.AMethod in project checker-framework by typetools.

the class ToIndexFileConverter method visit.

@Override
public Void visit(ConstructorDeclaration decl, AElement elem) {
    List<Parameter> params = decl.getParameters();
    List<AnnotationExpr> rcvrAnnos = decl.getAnnotations();
    BlockStmt body = decl.getBody();
    StringBuilder sb = new StringBuilder("<init>(");
    AClass clazz = (AClass) elem;
    AMethod method;
    // Some of the methods in the generated parser use null to represent an empty list.
    if (params != null) {
        for (Parameter param : params) {
            Type ptype = param.getType();
            sb.append(getJVML(ptype));
        }
    }
    sb.append(")V");
    method = clazz.methods.getVivify(sb.toString());
    visitDecl(decl, method);
    if (params != null) {
        for (int i = 0; i < params.size(); i++) {
            Parameter param = params.get(i);
            AField field = method.parameters.getVivify(i);
            visitType(param.getType(), field.type);
        }
    }
    if (rcvrAnnos != null) {
        for (AnnotationExpr expr : rcvrAnnos) {
            Annotation anno = extractAnnotation(expr);
            method.receiver.tlAnnotationsHere.add(anno);
        }
    }
    return body == null ? null : body.accept(this, method);
// return super.visit(decl, elem);
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) ReferenceType(com.github.javaparser.ast.type.ReferenceType) VoidType(com.github.javaparser.ast.type.VoidType) ArrayType(com.github.javaparser.ast.type.ArrayType) PrimitiveType(com.github.javaparser.ast.type.PrimitiveType) WildcardType(com.github.javaparser.ast.type.WildcardType) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ReceiverParameter(com.github.javaparser.ast.body.ReceiverParameter) Parameter(com.github.javaparser.ast.body.Parameter) TypeParameter(com.github.javaparser.ast.type.TypeParameter) AClass(scenelib.annotations.el.AClass) AMethod(scenelib.annotations.el.AMethod) Annotation(scenelib.annotations.Annotation) AField(scenelib.annotations.el.AField)

Aggregations

AMethod (scenelib.annotations.el.AMethod)19 AClass (scenelib.annotations.el.AClass)13 AField (scenelib.annotations.el.AField)9 Annotation (scenelib.annotations.Annotation)6 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)5 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)4 AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 ArrayType (com.github.javaparser.ast.type.ArrayType)2 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)2 PrimitiveType (com.github.javaparser.ast.type.PrimitiveType)2 ReferenceType (com.github.javaparser.ast.type.ReferenceType)2 Type (com.github.javaparser.ast.type.Type)2 TypeParameter (com.github.javaparser.ast.type.TypeParameter)2 VoidType (com.github.javaparser.ast.type.VoidType)2 WildcardType (com.github.javaparser.ast.type.WildcardType)2 Map (java.util.Map)2 VariableElement (javax.lang.model.element.VariableElement)2