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));
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations