本文整理汇总了Java中org.checkerframework.framework.source.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于org.checkerframework.framework.source包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitVariable
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitVariable(VariableTree node, Void p) {
// is this a field (and not a local variable)?
if (TreeUtils.elementFromDeclaration(node).getKind().isField()) {
Set<AnnotationMirror> annotationMirrors = atypeFactory.getAnnotatedType(
node).getExplicitAnnotations();
// Fields cannot have commitment annotations.
for (Class<? extends Annotation> c : atypeFactory.getInitializationAnnotations()) {
for (AnnotationMirror a : annotationMirrors) {
if (atypeFactory.isUnclassified(a)) continue; // unclassified is allowed
if (AnnotationUtils.areSameByClass(a, c)) {
checker.report(Result.failure(
COMMITMENT_INVALID_FIELD_ANNOTATION, node),
node);
break;
}
}
}
}
return super.visitVariable(node, p);
}
示例2: visitMethod
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitMethod(MethodTree node, Void p) {
if (TreeUtils.isConstructor(node)) {
Collection<? extends AnnotationMirror> returnTypeAnnotations = getExplicitReturnTypeAnnotations(node);
// check for invalid constructor return type
for (Class<? extends Annotation> c : atypeFactory.getInvalidConstructorReturnTypeAnnotations()) {
for (AnnotationMirror a : returnTypeAnnotations) {
if (AnnotationUtils.areSameByClass(a, c)) {
checker.report(Result.failure(
COMMITMENT_INVALID_CONSTRUCTOR_RETURN_TYPE,
node), node);
break;
}
}
}
// Check that all fields have been initialized at the end of the
// constructor.
boolean isStatic = false;
Store store = atypeFactory.getRegularExitStore(node);
List<? extends AnnotationMirror> receiverAnnotations = getAllReceiverAnnotations(node);
checkFieldsInitialized(node, isStatic, store, receiverAnnotations);
}
return super.visitMethod(node, p);
}
示例3: visitNewArray
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitNewArray(NewArrayTree node, Void p) {
AnnotatedArrayType type = atypeFactory.getAnnotatedType(node);
AnnotatedTypeMirror componentType = type.getComponentType();
if (componentType.hasEffectiveAnnotation(NONNULL)
&& !isNewArrayAllZeroDims(node)
&& !isNewArrayInToArray(node)
&& !TypesUtils.isPrimitive(componentType.getUnderlyingType())
&& checker.getLintOption("arrays:forbidnonnullcomponents",
false)) {
checker.report(
Result.failure("new.array.type.invalid",
componentType.getAnnotations(), type.toString()),
node);
}
return super.visitNewArray(node, p);
}
示例4: checkOverride
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
protected boolean checkOverride(MethodTree overriderTree,
AnnotatedDeclaredType enclosingType,
AnnotatedExecutableType overridden,
AnnotatedDeclaredType overriddenType,
Void p) {
List<String> overriderLocks = methodHolding(TreeUtils.elementFromDeclaration(overriderTree));
List<String> overriddenLocks = methodHolding(overridden.getElement());
boolean isValid = overriddenLocks.containsAll(overriderLocks);
if (!isValid) {
checker.report(Result.failure("override.holding.invalid",
TreeUtils.elementFromDeclaration(overriderTree),
overridden.getElement(),
overriderLocks, overriddenLocks), overriderTree);
}
return super.checkOverride(overriderTree, enclosingType, overridden, overriddenType, p) && isValid;
}
示例5: visitCompoundAssignment
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
ExpressionTree var = node.getVariable();
ExpressionTree expr = node.getExpression();
AnnotatedTypeMirror varType = atypeFactory.getAnnotatedType(var);
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);
Kind kind = node.getKind();
if ( (kind == Kind.PLUS_ASSIGNMENT || kind == Kind.MINUS_ASSIGNMENT)) {
if (!atypeFactory.getTypeHierarchy().isSubtype(exprType, varType)) {
checker.report(Result.failure("compound.assignment.type.incompatible",
varType, exprType), node);
}
} else if (exprType.getAnnotation(UnknownUnits.class) == null) {
// Only allow mul/div with unqualified units
checker.report(Result.failure("compound.assignment.type.incompatible",
varType, exprType), node);
}
return null; // super.visitCompoundAssignment(node, p);
}
示例6: checkContractsSubset
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
/**
* Checks that {@code mustSubset} is a subset of {@code set} in the
* following sense: For every expression in {@code mustSubset} there must be the
* same expression in {@code set}, with the same (or a stronger) annotation.
*/
private void checkContractsSubset(String subCl, String superCl, Set<Pair<Receiver, AnnotationMirror>> mustSubset,
Set<Pair<Receiver, AnnotationMirror>> set, /*@CompilerMessageKey*/ String messageKey) {
for (Pair<Receiver, AnnotationMirror> a : mustSubset) {
boolean found = false;
for (Pair<Receiver, AnnotationMirror> b : set) {
// are we looking at a contract of the same receiver?
if (a.first.equals(b.first)) {
// check subtyping relationship of annotations
QualifierHierarchy qualifierHierarchy = atypeFactory.getQualifierHierarchy();
if (qualifierHierarchy.isSubtype(a.second, b.second)) {
found = true;
break;
}
}
}
if (!found) {
MethodTree method = visitorState.getMethodTree();
checker.report(Result.failure(messageKey, a.first, method
.getName().toString(), subCl, superCl), method);
}
}
}
示例7: checkAccess
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
protected void checkAccess(IdentifierTree node, Void p) {
MemberSelectTree memberSel = enclosingMemberSelect();
ExpressionTree tree;
Element elem;
if (memberSel == null) {
tree = node;
elem = TreeUtils.elementFromUse(node);
} else {
tree = memberSel;
elem = TreeUtils.elementFromUse(memberSel);
}
if (elem == null || !elem.getKind().isField())
return;
AnnotatedTypeMirror receiver = atypeFactory.getReceiverType(tree);
if (!isAccessAllowed(elem, receiver, tree)) {
checker.report(Result.failure("unallowed.access", elem, receiver), node);
}
}
示例8: evaluateUnaryOperator
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
private AnnotationMirror evaluateUnaryOperator(
AnnotationMirror argAnno, String operation, Class<?> argClass,
UnaryTree tree) {
try {
Class<?>[] argClasses = new Class<?>[] { argClass };
Method m = Operators.class.getMethod(operation, argClasses);
List<?> annoValues = AnnotationUtils.getElementValueArray(
argAnno, "value", argClass, true);
ArrayList<Object> results = new ArrayList<Object>(
annoValues.size());
for (Object val : annoValues) {
results.add(m.invoke(null, new Object[] { val }));
}
return resultAnnotationHandler(m.getReturnType(), results);
} catch (ReflectiveOperationException e) {
checker.report(Result
.warning("operator.unary.evaluation.failed", operation,
argClass), tree);
return null;
}
}
示例9: checkReportUse
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
/**
* Check for uses of the {@link ReportUse} annotation.
* This method has to be called for every explicit or implicit use of a type,
* most cases are simply covered by the type validator.
*
* @param node The tree for error reporting only.
* @param member The element from which to start looking.
*/
private void checkReportUse(Tree node, Element member) {
Element loop = member;
while (loop != null) {
boolean report = this.atypeFactory.getDeclAnnotation(loop, ReportUse.class) != null;
if (report) {
checker.report(Result.failure("usage", node,
ElementUtils.getVerboseName(loop), loop.getKind(),
ElementUtils.getVerboseName(member), member.getKind()), node);
break;
} else {
if (loop.getKind() == ElementKind.PACKAGE) {
loop = ElementUtils.parentPackage(elements, (PackageElement)loop);
continue;
}
}
// Package will always be the last iteration.
loop = loop.getEnclosingElement();
}
}
示例10: visitClass
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitClass(ClassTree node, Void p) {
TypeElement member = TreeUtils.elementFromDeclaration(node);
boolean report = false;
// No need to check on the declaring class itself
// this.atypeFactory.getDeclAnnotation(member, ReportInherit.class) != null;
// Check whether any superclass/interface had the ReportInherit annotation.
List<TypeElement> suptypes = ElementUtils.getSuperTypes(member);
for (TypeElement sup : suptypes) {
report = this.atypeFactory.getDeclAnnotation(sup, ReportInherit.class) != null;
if (report) {
checker.report(Result.failure("inherit", node, ElementUtils.getVerboseName(sup)), node);
}
}
return super.visitClass(node, p);
}
示例11: visitMethod
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void visitMethod(MethodTree node, Void p) {
ExecutableElement method = TreeUtils.elementFromDeclaration(node);
boolean report = false;
// Check all overridden methods.
Map<AnnotatedDeclaredType, ExecutableElement> overriddenMethods =
AnnotatedTypes.overriddenMethods(elements, atypeFactory, method);
for (Map.Entry<AnnotatedDeclaredType, ExecutableElement> pair: overriddenMethods.entrySet()) {
// AnnotatedDeclaredType overriddenType = pair.getKey();
ExecutableElement exe = pair.getValue();
report = this.atypeFactory.getDeclAnnotation(exe, ReportOverride.class) != null;
if (report) {
// Set method to report the right method, if found.
method = exe;
break;
}
}
if (report) {
checker.report(Result.failure("override", node,
ElementUtils.getVerboseName(method)), node);
}
return super.visitMethod(node, p);
}
示例12: scan
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public Void scan(Tree tree, Void p) {
if (TreeUtils.isExpressionTree(tree)) {
ExpressionTree expTree = (ExpressionTree) tree;
TreeSpec treeSpec =
new TreeSpec(expTree.toString().trim(),
root.getLineMap().getLineNumber(((JCTree)expTree).pos));
if (expected.containsKey(treeSpec)) {
String actualType = canonizeTypeString(atypeFactory.getAnnotatedType(expTree).toString());
String expectedType = expected.get(treeSpec);
if (!actualType.equals(expectedType)) {
/*>>>
// The key is added above using a setProperty call, which is not supported by the CompilerMessageChecker
@SuppressWarnings("compilermessages")
*/
Result res = Result.failure("type.unexpected", tree.toString(), actualType, expectedType);
FactoryTestChecker.this.report(res, tree);
}
}
}
return super.scan(tree, p);
}
示例13: visitMethodInvocation
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
@Override
public TransferResult<AffinePointerValue, AffinePointerStore>
visitMethodInvocation(MethodInvocationNode n, TransferInput<AffinePointerValue, AffinePointerStore> in) {
TransferResult<AffinePointerValue, AffinePointerStore> result = super.visitMethodInvocation(n, in);
int i = 0;
List<? extends VariableElement> argumentTypes = n.getTarget().getMethod().getParameters();
for (Node operand : n.getArguments()) {
//We should invalidate the variable if it and the argument both have type @Affine.
//If the argument has type @Shared or @Borrowed, doing nothing whatsoever correctly models
//borrowing.
if (argumentHasAnnotation(argumentTypes.get(i), AFFINE)
&& hasAnnotation(result, operand, AFFINE)) {
if (borrowTracker.isBorrowed(elementOf(operand))) {
checker.report(Result.failure("use.of.borrowed.variable", operand), operand.getTree());
} else {
changeAnnotation(result, operand, UNUSABLE);
}
} else if (argumentHasAnnotation(argumentTypes.get(i), BORROWED)) {
if (!borrowTracker.canMutablyBorrow(elementOf(operand))) {
checker.report(Result.failure("cannot.borrow.borrowed", operand), operand.getTree());
}
} else if (argumentHasAnnotation(argumentTypes.get(i), SHARED)) {
if (!borrowTracker.canImmutablyBorrow(elementOf(operand))) {
checker.report(Result.failure("cannot.share.borrowed", operand), operand.getTree());
}
}
i++;
}
return result;
}
示例14: checkFieldIsImmutable
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
private void checkFieldIsImmutable(ClassTree deepestClassTree, Tree containingTree, TypeElement immediateContainingElement, Element element, boolean alsoCheckFinal) {
AnnotatedTypeMirror fieldType = atypeFactory.getAnnotatedType(element);
if (!typeIsImmutable(fieldType)) {
if (alsoCheckFinal) {
checker.report(Result.failure("glacier.mutablemember", deepestClassTree.getSimpleName(), immediateContainingElement, element), deepestClassTree);
} else {
if (fieldType.getUnderlyingType().getKind() == TypeKind.ARRAY) {
AnnotatedArrayType arrayType = (AnnotatedArrayType)fieldType;
if (!arrayType.hasAnnotation(Immutable.class)) {
checker.report(Result.failure("glacier.mutable.wholearray.invalid"), element);
}
else {
checker.report(Result.failure("glacier.mutable.array.invalid"), element);
}
}
else {
checker.report(Result.failure("glacier.mutable.invalid"), element);
}
}
}
if (alsoCheckFinal) {
if (!ElementUtils.isFinal(element)) {
checker.report(Result.failure("glacier.nonfinalmember", deepestClassTree.getSimpleName(), immediateContainingElement, element), deepestClassTree);
}
}
}
示例15: checkTypeArguments
import org.checkerframework.framework.source.Result; //导入依赖的package包/类
protected void checkTypeArguments(Tree toptree, List<? extends AnnotatedTypeParameterBounds> paramBounds, List<? extends AnnotatedTypeMirror> typeargs, List<? extends Tree> typeargTrees) {
super.checkTypeArguments(toptree, paramBounds, typeargs, typeargTrees);
AnnotatedTypeMirror toptreeType = atypeFactory.getAnnotatedType(toptree);
if (toptreeType.hasAnnotation(Immutable.class) && (toptree.getKind() == Kind.CLASS || toptree.getKind() == Kind.PARAMETERIZED_TYPE)) {
// Cases for toptree: ParameterizedTypeTree; MethodInvocationTree; NewClassTree.
// Make sure all the type arguments have the @Immutable annotation.
for (AnnotatedTypeMirror typearg : typeargs) {
// Ignore type variables because we only want to check concrete types.
if (typearg.getKind() != TypeKind.TYPEVAR && !typearg.hasAnnotation(Immutable.class)) {
// One last-ditch check: maybe typearg is a wildcard. If so, it suffices if the upper bound is immutable or a type variable.
boolean reportError = false;
if (typearg.getKind() == TypeKind.WILDCARD) {
AnnotatedTypeMirror.AnnotatedWildcardType annotatedWildcardType = (AnnotatedTypeMirror.AnnotatedWildcardType) typearg;
AnnotatedTypeMirror extendsBound = annotatedWildcardType.getExtendsBound();
if (extendsBound.getKind() != TypeKind.TYPEVAR && !extendsBound.hasAnnotation(Immutable.class)) {
reportError = true;
}
}
else {
reportError = true;
}
if (reportError) {
checker.report(Result.failure("glacier.typeparameter.mutable", toptree, typearg), toptree);
}
}
}
}
}