Search in sources :

Example 1 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project core-java by SpineEventEngine.

the class SpineAnnotationProcessorShould method print_warning_message.

@Test
public void print_warning_message() {
    final ProcessingEnvironment environment = mock(ProcessingEnvironment.class);
    final Messager messager = mock(Messager.class);
    when(environment.getMessager()).thenReturn(messager);
    processor.init(environment);
    final String message = "custom warning";
    processor.warn(message);
    verify(messager).printMessage(eq(WARNING), eq(message));
}
Also used : Messager(javax.annotation.processing.Messager) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Test(org.junit.Test)

Example 2 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.

the class CFAbstractValue method upperBound.

private V upperBound(@Nullable V other, boolean shouldWiden) {
    if (other == null) {
        @SuppressWarnings("unchecked") V v = (V) this;
        return v;
    }
    ProcessingEnvironment processingEnv = analysis.getTypeFactory().getProcessingEnv();
    Set<AnnotationMirror> lub = AnnotationUtils.createAnnotationSet();
    TypeMirror lubTypeMirror = TypesUtils.leastUpperBound(this.getUnderlyingType(), other.getUnderlyingType(), processingEnv);
    LubVisitor lubVisitor = new LubVisitor(lubTypeMirror, this.getUnderlyingType(), other.getUnderlyingType(), this.getAnnotations(), other.getAnnotations(), lub, shouldWiden);
    lubVisitor.visit();
    return analysis.createAbstractValue(lub, lubTypeMirror);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Example 3 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.

the class FlowExpressionParseUtil method parseHelper.

private static FlowExpressions.Receiver parseHelper(String expression, FlowExpressionContext context, TreePath path) throws FlowExpressionParseException {
    expression = expression.trim();
    ProcessingEnvironment env = context.checkerContext.getProcessingEnvironment();
    Types types = env.getTypeUtils();
    if (isNullLiteral(expression, context)) {
        return parseNullLiteral(expression, types);
    } else if (isIntLiteral(expression, context)) {
        return parseIntLiteral(expression, types);
    } else if (isLongLiteral(expression, context)) {
        return parseLongLiteral(expression, types);
    } else if (isStringLiteral(expression, context)) {
        return parseStringLiteral(expression, types, env.getElementUtils());
    } else if (isThisLiteral(expression, context)) {
        return parseThis(expression, context);
    } else if (isSuperLiteral(expression, context)) {
        return parseSuper(expression, types, context);
    } else if (isIdentifier(expression, context)) {
        return parseIdentifier(expression, env, path, context);
    } else if (isParameter(expression, context)) {
        return parseParameter(expression, context);
    } else if (isArray(expression, context)) {
        return parseArray(expression, context, path);
    } else if (isMethod(expression, context)) {
        return parseMethod(expression, context, path, env);
    } else if (isMemberSelect(expression, context)) {
        return parseMemberSelect(expression, env, context, path);
    } else if (isParentheses(expression, context)) {
        return parseParentheses(expression, context, path);
    } else {
        throw constructParserException(expression);
    }
}
Also used : Types(javax.lang.model.util.Types) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Example 4 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.

the class LockVisitor method ensureReceiverOfExplicitUnlockCallIsEffectivelyFinal.

/**
 * Issues an error if the receiver of an unlock() call is not effectively final.
 *
 * @param node the MethodInvocationTree for any method call
 * @param methodElement the ExecutableElement for the method call referred to by {@code node}
 * @param lockExpression the receiver tree of {@code node}. Can be null.
 */
private void ensureReceiverOfExplicitUnlockCallIsEffectivelyFinal(MethodInvocationTree node, ExecutableElement methodElement, ExpressionTree lockExpression) {
    if (lockExpression == null) {
        // to be checked for them.
        return;
    }
    if (!methodElement.getSimpleName().contentEquals("unlock")) {
        return;
    }
    TypeMirror lockExpressionType = TreeUtils.typeOf(lockExpression);
    ProcessingEnvironment processingEnvironment = checker.getProcessingEnvironment();
    javax.lang.model.util.Types types = processingEnvironment.getTypeUtils();
    // TODO: make a type declaration annotation for this rather than looking for the
    // Lock.unlock() method explicitly.
    TypeMirror lockInterfaceTypeMirror = TypesUtils.typeFromClass(Lock.class, types, processingEnvironment.getElementUtils());
    if (types.isSubtype(types.erasure(lockExpressionType), lockInterfaceTypeMirror)) {
        ensureExpressionIsEffectivelyFinal(lockExpression);
    }
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Example 5 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project checker-framework by typetools.

the class LockVisitor method visitSynchronized.

/**
 * When visiting a synchronized block, issue an error if the expression has a type that
 * implements the java.util.concurrent.locks.Lock interface. This prevents explicit locks from
 * being accidentally used as built-in (monitor) locks. This is important because the Lock
 * Checker does not have a mechanism to separately keep track of the explicit lock and the
 * monitor lock of an expression that implements the Lock interface (i.e. there is a @LockHeld
 * annotation used in dataflow, but there are not distinct @MonitorLockHeld
 * and @ExplicitLockHeld annotations). It is assumed that both kinds of locks will never be held
 * for any expression that implements Lock.
 *
 * <p>Additionally, a synchronized block may not be present in a method that has a @LockingFree
 * guarantee or stronger. An error is issued in this case.
 *
 * @param node the SynchronizedTree for the synchronized block being visited
 */
@Override
public Void visitSynchronized(SynchronizedTree node, Void p) {
    ProcessingEnvironment processingEnvironment = checker.getProcessingEnvironment();
    javax.lang.model.util.Types types = processingEnvironment.getTypeUtils();
    // TODO: make a type declaration annotation for this rather than looking for Lock.class
    // explicitly.
    TypeMirror lockInterfaceTypeMirror = TypesUtils.typeFromClass(Lock.class, types, processingEnvironment.getElementUtils());
    ExpressionTree synchronizedExpression = node.getExpression();
    ensureExpressionIsEffectivelyFinal(synchronizedExpression);
    TypeMirror expressionType = types.erasure(atypeFactory.getAnnotatedType(synchronizedExpression).getUnderlyingType());
    if (types.isSubtype(expressionType, lockInterfaceTypeMirror)) {
        checker.report(Result.failure("explicit.lock.synchronized"), node);
    }
    MethodTree enclosingMethod = TreeUtils.enclosingMethod(atypeFactory.getPath(node));
    ExecutableElement methodElement = null;
    if (enclosingMethod != null) {
        methodElement = TreeUtils.elementFromDeclaration(enclosingMethod);
        SideEffectAnnotation seaOfContainingMethod = atypeFactory.methodSideEffectAnnotation(methodElement, false);
        if (!seaOfContainingMethod.isWeakerThan(SideEffectAnnotation.LOCKINGFREE)) {
            checker.report(Result.failure("synchronized.block.in.lockingfree.method", seaOfContainingMethod), node);
        }
    }
    return super.visitSynchronized(node, p);
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) MethodTree(com.sun.source.tree.MethodTree) ExecutableElement(javax.lang.model.element.ExecutableElement) ExpressionTree(com.sun.source.tree.ExpressionTree) SideEffectAnnotation(org.checkerframework.checker.lock.LockAnnotatedTypeFactory.SideEffectAnnotation) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Aggregations

ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)20 TypeElement (javax.lang.model.element.TypeElement)7 TypeMirror (javax.lang.model.type.TypeMirror)5 Set (java.util.Set)4 ExpressionTree (com.sun.source.tree.ExpressionTree)3 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)3 Annotation (java.lang.annotation.Annotation)3 List (java.util.List)3 Optional (java.util.Optional)3 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)3 LiteralTree (com.sun.source.tree.LiteralTree)2 MemberSelectTree (com.sun.source.tree.MemberSelectTree)2 Context (com.sun.tools.javac.util.Context)2 Embedded (io.requery.Embedded)2 PropertyNameStyle (io.requery.PropertyNameStyle)2 ReadOnly (io.requery.ReadOnly)2 Transient (io.requery.Transient)2 LinkedHashSet (java.util.LinkedHashSet)2