本文整理汇总了Java中org.checkerframework.javacutil.AnnotationUtils.fromName方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtils.fromName方法的具体用法?Java AnnotationUtils.fromName怎么用?Java AnnotationUtils.fromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.checkerframework.javacutil.AnnotationUtils
的用法示例。
在下文中一共展示了AnnotationUtils.fromName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPostconditionsConsistency
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Checks all (non-conditional) postcondition on the method {@code node}
* with element {@code methodElement} for consistency.
*/
protected void checkPostconditionsConsistency(MethodTree node,
ExecutableElement methodElement) {
FlowExpressionContext flowExprContext = null;
Set<Pair<String, String>> postconditions = contractsUtils
.getPostconditions(methodElement);
for (Pair<String, String> p : postconditions) {
String expression = p.first;
AnnotationMirror annotation = AnnotationUtils.fromName(elements,
p.second);
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(node,
getCurrentPath(), atypeFactory);
}
// Only check if the postcondition concerns this checker
if (!atypeFactory.isSupportedQualifier(annotation)) {
continue;
}
try {
FlowExpressionParseUtil.parse(expression,
flowExprContext, getCurrentPath());
} catch (FlowExpressionParseException e) {
// ignore expressions that do not parse
continue;
}
checkFlowExprParameters(methodElement, expression);
}
}
示例2: checkConditionalPostconditionsConsistency
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Checks all conditional postcondition on the method with element
* {@code methodElement} for consistency.
*/
protected void checkConditionalPostconditionsConsistency(MethodTree node,
ExecutableElement methodElement) {
FlowExpressionContext flowExprContext = null;
Set<Pair<String, Pair<Boolean, String>>> conditionalPostconditions = contractsUtils
.getConditionalPostconditions(methodElement);
for (Pair<String, Pair<Boolean, String>> p : conditionalPostconditions) {
String expression = p.first;
AnnotationMirror annotation = AnnotationUtils.fromName(elements,
p.second.second);
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(node,
getCurrentPath(), atypeFactory);
}
// Only check if the postcondition concerns this checker
if (!atypeFactory.isSupportedQualifier(annotation)) {
continue;
}
try {
FlowExpressionParseUtil.parse(expression,
flowExprContext, getCurrentPath());
} catch (FlowExpressionParseException e) {
// ignore expressions that do not parse
continue;
}
checkFlowExprParameters(methodElement, expression);
}
}
示例3: checkPreconditionsConsistency
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Checks all the preconditions of the method with element
* {@code methodElement} for consistency.
*/
protected void checkPreconditionsConsistency(MethodTree node,
ExecutableElement methodElement) {
FlowExpressionContext flowExprContext = null;
Set<Pair<String, String>> preconditions = contractsUtils
.getPreconditions(methodElement);
for (Pair<String, String> p : preconditions) {
String expression = p.first;
AnnotationMirror anno = AnnotationUtils
.fromName(elements, p.second);
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(node,
getCurrentPath(), atypeFactory);
}
// Only check if the precondition concerns this checker
if (!atypeFactory.isSupportedQualifier(anno)) {
return;
}
try {
FlowExpressionParseUtil.parse(expression, flowExprContext,
getCurrentPath());
} catch (FlowExpressionParseException e) {
// ignore expressions that do not parse
continue;
}
checkFlowExprParameters(methodElement, expression);
}
}
示例4: resolveContracts
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Takes a set of contracts identified by their expression and annotation
* strings and resolves them to the correct {@link Receiver} and
* {@link AnnotationMirror}.
* @param method
*/
private Set<Pair<Receiver, AnnotationMirror>> resolveContracts(
Set<Pair<String, String>> contractSet, AnnotatedExecutableType method) {
Set<Pair<Receiver, AnnotationMirror>> result = new HashSet<>();
MethodTree methodTree = visitorState.getMethodTree();
TreePath path = atypeFactory.getPath(methodTree);
FlowExpressionContext flowExprContext = null;
for (Pair<String, String> p : contractSet) {
String expression = p.first;
AnnotationMirror annotation = AnnotationUtils.fromName(
atypeFactory.getElementUtils(), p.second);
// Only check if the postcondition concerns this checker
if (!atypeFactory.isSupportedQualifier(annotation)) {
continue;
}
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(methodTree, method
.getReceiverType().getUnderlyingType(),
atypeFactory);
}
try {
// TODO: currently, these expressions are parsed many times.
// this could
// be optimized to store the result the first time.
// (same for other annotations)
FlowExpressions.Receiver expr = FlowExpressionParseUtil.parse(
expression, flowExprContext, path);
result.add(Pair.of(expr, annotation));
} catch (FlowExpressionParseException e) {
// errors are reported elsewhere + ignore this contract
}
}
return result;
}
示例5: addInformationFromPreconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Add the information from all the preconditions of the method
* {@code method} with corresponding tree {@code methodTree} to the store
* {@code info}.
*/
protected void addInformationFromPreconditions(S info,
AnnotatedTypeFactory factory, CFGMethod method,
MethodTree methodTree, ExecutableElement methodElement) {
ContractsUtils contracts = ContractsUtils.getInstance(analysis.atypeFactory);
FlowExpressionContext flowExprContext = null;
Set<Pair<String, String>> preconditions = contracts
.getPreconditions(methodElement);
for (Pair<String, String> p : preconditions) {
String expression = p.first;
AnnotationMirror annotation = AnnotationUtils.fromName(analysis
.getTypeFactory().getElementUtils(), p.second);
// Only check if the postcondition concerns this checker
if (!analysis.getTypeFactory().isSupportedQualifier(annotation)) {
continue;
}
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(methodTree,
method.getClassTree(), analysis.getTypeFactory());
}
FlowExpressions.Receiver expr = null;
try {
// TODO: currently, these expressions are parsed at the
// declaration (i.e. here) and for every use. this could
// be optimized to store the result the first time.
// (same for other annotations)
expr = FlowExpressionParseUtil.parse(expression,
flowExprContext,
analysis.atypeFactory.getPath(methodTree));
info.insertValue(expr, annotation);
} catch (FlowExpressionParseException e) {
// report errors here
analysis.checker.report(e.getResult(), methodTree);
}
}
}
示例6: processPostconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Add information based on all postconditions of method {@code n} with tree
* {@code tree} and element {@code method} to the store {@code store}.
*/
protected void processPostconditions(MethodInvocationNode n, S store,
ExecutableElement methodElement, Tree tree) {
ContractsUtils contracts = ContractsUtils
.getInstance(analysis.atypeFactory);
Set<Pair<String, String>> postconditions = contracts
.getPostconditions(methodElement);
FlowExpressionContext flowExprContext = null;
for (Pair<String, String> p : postconditions) {
String expression = p.first;
AnnotationMirror anno = AnnotationUtils.fromName(analysis
.getTypeFactory().getElementUtils(), p.second);
// Only check if the postcondition concerns this checker
if (!analysis.getTypeFactory().isSupportedQualifier(anno)) {
continue;
}
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForUse(n, analysis.getTypeFactory());
}
try {
FlowExpressions.Receiver r = FlowExpressionParseUtil.parse(
expression, flowExprContext,
analysis.atypeFactory.getPath(tree));
store.insertValue(r, anno);
} catch (FlowExpressionParseException e) {
// these errors are reported at the declaration, ignore here
}
}
}
示例7: processConditionalPostconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Add information based on all conditional postconditions of method
* {@code n} with tree {@code tree} and element {@code method} to the
* appropriate store.
*/
protected void processConditionalPostconditions(MethodInvocationNode n,
ExecutableElement methodElement, Tree tree, S thenStore, S elseStore) {
ContractsUtils contracts = ContractsUtils
.getInstance(analysis.atypeFactory);
Set<Pair<String, Pair<Boolean, String>>> conditionalPostconditions = contracts
.getConditionalPostconditions(methodElement);
FlowExpressionContext flowExprContext = null;
for (Pair<String, Pair<Boolean, String>> p : conditionalPostconditions) {
String expression = p.first;
AnnotationMirror anno = AnnotationUtils.fromName(analysis
.getTypeFactory().getElementUtils(), p.second.second);
boolean result = p.second.first;
// Only check if the postcondition concerns this checker
if (!analysis.getTypeFactory().isSupportedQualifier(anno)) {
continue;
}
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForUse(n, analysis.getTypeFactory());
}
try {
FlowExpressions.Receiver r = FlowExpressionParseUtil.parse(
expression, flowExprContext,
analysis.atypeFactory.getPath(tree));
if (result) {
thenStore.insertValue(r, anno);
} else {
elseStore.insertValue(r, anno);
}
} catch (FlowExpressionParseException e) {
// these errors are reported at the declaration, ignore here
}
}
}
示例8: createImportedAnnotationsMap
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private Map<String, AnnotationMirror> createImportedAnnotationsMap(List<TypeElement> typeElements) {
Map<String, AnnotationMirror> r = new HashMap<String, AnnotationMirror>();
for (TypeElement typeElm : typeElements) {
if (typeElm.getKind() == ElementKind.ANNOTATION_TYPE) {
AnnotationMirror anno = AnnotationUtils.fromName(elements, typeElm.getQualifiedName());
putNew(r, typeElm.getSimpleName().toString(), anno);
}
}
return r;
}
示例9: stripValues
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private AnnotationMirror stripValues(AnnotationMirror anno) {
return AnnotationUtils.fromName(elements, anno.getAnnotationType().toString());
}
示例10: checkPostconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Checks all (non-conditional) postcondition on the method {@code node}
* with element {@code methodElement}.
*/
protected void checkPostconditions(MethodTree node,
ExecutableElement methodElement) {
FlowExpressionContext flowExprContext = null;
Set<Pair<String, String>> postconditions = contractsUtils
.getPostconditions(methodElement);
for (Pair<String, String> p : postconditions) {
String expression = p.first;
AnnotationMirror annotation = AnnotationUtils.fromName(elements,
p.second);
// Only check if the postcondition concerns this checker
if (!atypeFactory.isSupportedQualifier(annotation)) {
continue;
}
if (flowExprContext == null) {
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForDeclaration(node,
getCurrentPath(), atypeFactory);
}
FlowExpressions.Receiver expr = null;
try {
// TODO: currently, these expressions are parsed at the
// declaration (i.e. here) and for every use. this could be
// optimized to store the result the first time. (same for
// other annotations)
expr = FlowExpressionParseUtil.parse(expression,
flowExprContext, getCurrentPath());
CFAbstractStore<?, ?> exitStore = atypeFactory
.getRegularExitStore(node);
if (exitStore == null) {
// if there is no regular exitStore, then the method
// cannot reach the regular exit and there is no need to
// check anything
} else {
CFAbstractValue<?> value = exitStore.getValue(expr);
AnnotationMirror inferredAnno = value == null ? null
: value.getType().getAnnotationInHierarchy(
annotation);
if (!checkContract(expr, annotation, inferredAnno, exitStore)) {
checker.report(
Result.failure("contracts.postcondition.not.satisfied", expr.toString()),
node);
}
}
} catch (FlowExpressionParseException e) {
// report errors here
checker.report(e.getResult(), node);
}
}
}
示例11: checkPreconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Checks all the preconditions of the method invocation {@code tree} with
* element {@code invokedMethodElement}.
*/
protected void checkPreconditions(MethodInvocationTree tree,
ExecutableElement invokedMethodElement) {
Set<Pair<String, String>> preconditions = contractsUtils
.getPreconditions(invokedMethodElement);
FlowExpressionContext flowExprContext = null;
for (Pair<String, String> p : preconditions) {
String expression = p.first;
AnnotationMirror anno = AnnotationUtils
.fromName(elements, p.second);
// Only check if the precondition concerns this checker
if (!atypeFactory.isSupportedQualifier(anno)) {
return;
}
if (flowExprContext == null) {
Node nodeNode = atypeFactory.getNodeForTree(tree);
flowExprContext = FlowExpressionParseUtil
.buildFlowExprContextForUse(
(MethodInvocationNode) nodeNode, atypeFactory);
}
FlowExpressions.Receiver expr = null;
try {
expr = FlowExpressionParseUtil.parse(expression,
flowExprContext, getCurrentPath());
CFAbstractStore<?, ?> store = atypeFactory.getStoreBefore(tree);
CFAbstractValue<?> value = store.getValue(expr);
AnnotationMirror inferredAnno = value == null ? null : value
.getType().getAnnotationInHierarchy(anno);
if (!checkContract(expr, anno, inferredAnno, store)) {
checker.report(Result.failure(
"contracts.precondition.not.satisfied",
expr.toString()), tree);
}
} catch (FlowExpressionParseException e) {
// errors are reported at declaration site
}
}
}
示例12: getResult
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private AnnotationMirror getResult(AnnotationMirror anno) {
Name valName = AnnotationUtils.getElementValueClassName(anno, "result", false);
return AnnotationUtils.fromName(elements, valName);
}
示例13: getWhen
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private AnnotationMirror getWhen(AnnotationMirror anno) {
Name valName = AnnotationUtils.getElementValueClassName(anno, "when", false);
return AnnotationUtils.fromName(elements, valName);
}
示例14: QualifierPolymorphism
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Creates a {@link QualifierPolymorphism} instance that uses the given
* checker for querying type qualifiers and the given factory for getting
* annotated types.
*
* @param env the processing environment
* @param factory the factory for the current checker
*/
public QualifierPolymorphism(ProcessingEnvironment env, AnnotatedTypeFactory factory) {
this.atypeFactory = factory;
this.types = env.getTypeUtils();
Elements elements = env.getElementUtils();
POLYALL = AnnotationUtils.fromClass(elements, PolyAll.class);
this.qualhierarchy = factory.getQualifierHierarchy();
Map<AnnotationMirror, AnnotationMirror> polys = new HashMap<AnnotationMirror, AnnotationMirror>();
for (AnnotationMirror aam : qualhierarchy.getTypeQualifiers()) {
if (isPolyAll(aam)) {
polys.put(null, aam);
continue;
}
for (AnnotationMirror aa : aam.getAnnotationType().asElement().getAnnotationMirrors() ) {
if (aa.getAnnotationType().toString().equals(PolymorphicQualifier.class.getCanonicalName())) {
Name plval = AnnotationUtils.getElementValueClassName(aa, "value", true);
AnnotationMirror ttreetop;
if (PolymorphicQualifier.class.getCanonicalName().contentEquals(plval)) {
Set<? extends AnnotationMirror> tops = qualhierarchy.getTopAnnotations();
if (tops.size() != 1) {
ErrorReporter.errorAbort(
"QualifierPolymorphism: PolymorphicQualifier has to specify type hierarchy, if more than one exist; top types: " +
tops);
}
ttreetop = tops.iterator().next();
} else {
AnnotationMirror ttree = AnnotationUtils.fromName(elements, plval);
ttreetop = qualhierarchy.getTopAnnotation(ttree);
}
if (polys.containsKey(ttreetop)) {
ErrorReporter.errorAbort(
"QualifierPolymorphism: checker has multiple polymorphic qualifiers: " +
polys.get(ttreetop) + " and " + aam);
}
polys.put(ttreetop, aam);
}
}
}
this.polyQuals = polys;
this.topQuals = qualhierarchy.getTopAnnotations();
this.collector = new PolyCollector();
this.completer = new Completer();
}