use of org.checkerframework.checker.nullness.qual.Nullable in project aws-xray-sdk-java by aws.
the class AWSXRayRecorder method currentFormattedId.
/**
* @throws SegmentNotFoundException
* if {@code contextMissingStrategy} throws exceptions and no segment or subsegment is currently in progress
* @return the trace ID of the {@code Segment} currently in progress and the ID of the {@code Segment} or {@code Subsegment}
* in progress, joined with {@code @}, or {@code null} if {@code contextMissingStrategy} suppresses exceptions and no segment
* or subsegment is currently in progress
*/
@Nullable
public String currentFormattedId() {
SegmentContext context = getSegmentContext();
if (context == null) {
return null;
}
Entity current = context.getTraceEntity();
if (current != null) {
TraceID traceId = current.getParentSegment().getTraceId();
String entityId = current.getId();
return traceId.toString() + "@" + entityId;
} else {
contextMissingStrategy.contextMissing("Failed to get current formatted ID: segment cannot be found.", SegmentNotFoundException.class);
return null;
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class CalledMethodsAnnotatedTypeFactory method getDummyAssignedTo.
/**
* Returns the annotation type mirror for the type of {@code expressionTree} with default
* annotations applied. As types relevant to Called Methods checking are rarely used inside
* generics, this is typically the best choice for type inference.
*/
@Override
@Nullable
public AnnotatedTypeMirror getDummyAssignedTo(ExpressionTree expressionTree) {
TypeMirror type = TreeUtils.typeOf(expressionTree);
if (type.getKind() != TypeKind.VOID) {
AnnotatedTypeMirror atm = type(expressionTree);
addDefaultAnnotations(atm);
return atm;
}
return null;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class CalledMethodsTransfer method getUpdatedCalledMethodsType.
/**
* Extract the current called-methods type from {@code currentType}, and then add each element of
* {@code methodNames} to it, and return the result. This method is similar to GLB, but should be
* used when the new methods come from a source other than an {@code CalledMethods} annotation.
*
* @param currentType the current type in the called-methods hierarchy
* @param methodNames the names of the new methods to add to the type
* @return the new annotation to be added to the type, or null if the current type cannot be
* converted to an accumulator annotation
*/
@Nullable
private AnnotationMirror getUpdatedCalledMethodsType(AnnotatedTypeMirror currentType, List<String> methodNames) {
AnnotationMirror type;
if (currentType == null || !currentType.isAnnotatedInHierarchy(atypeFactory.top)) {
type = atypeFactory.top;
} else {
type = currentType.getAnnotationInHierarchy(atypeFactory.top);
}
// require reasoning about the predicate itself. Instead, start over from top.
if (AnnotationUtils.areSameByName(type, "org.checkerframework.checker.calledmethods.qual.CalledMethodsPredicate")) {
type = atypeFactory.top;
}
if (AnnotationUtils.areSame(type, atypeFactory.bottom)) {
return null;
}
List<String> currentMethods = AnnotationUtils.getElementValueArray(type, calledMethodsValueElement, String.class);
List<String> newList = CollectionsPlume.concatenate(currentMethods, methodNames);
return atypeFactory.createAccumulatorAnnotation(newList);
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class CFGTranslationPhaseOne method maybeGetTypeMirror.
/**
* Returns the TypeMirror for the given class, or {@code null} if the type is not present.
*
* <p>This can be used to handle system types that are not present. For example, in Java code that
* is translated to JavaScript using j2cl, the custom bootclasspath contains APIs that are
* emulated in JavaScript, so some types such as OutOfMemoryError are deliberately not present.
*
* @param clazz a class, which must have a canonical name
* @return the TypeMirror for the class, or {@code null} if the type is not present
*/
@Nullable
private TypeMirror maybeGetTypeMirror(Class<?> clazz) {
String name = clazz.getCanonicalName();
assert name != null : clazz + " does not have a canonical name";
TypeElement element = elements.getTypeElement(name);
if (element == null) {
return null;
}
return element.asType();
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class CFGVisualizeLauncher method generateStringOfCFG.
/**
* Generate the String representation of the CFG for a method.
*
* @param <V> the abstract value type to be tracked by the analysis
* @param <S> the store type used in the analysis
* @param <T> the transfer function type that is used to approximated runtime behavior
* @param inputFile a Java source file, used as input
* @param method name of the method to generate the CFG for
* @param clas name of the class which includes the method to generate the CFG for
* @param verbose show verbose information in CFG
* @param analysis analysis to perform before the visualization (or {@code null} if no analysis is
* to be performed)
* @return a map which includes a key "stringGraph" and the String representation of CFG as the
* value
*/
@Nullable
public <V extends AbstractValue<V>, S extends Store<S>, T extends TransferFunction<V, S>> Map<String, Object> generateStringOfCFG(String inputFile, String method, String clas, boolean verbose, @Nullable Analysis<V, S, T> analysis) {
ControlFlowGraph cfg = generateMethodCFG(inputFile, clas, method);
if (analysis != null) {
analysis.performAnalysis(cfg);
}
Map<String, Object> args = Collections.singletonMap("verbose", verbose);
CFGVisualizer<V, S, T> viz = new StringCFGVisualizer<>();
viz.init(args);
Map<String, Object> res = viz.visualize(cfg, cfg.getEntryBlock(), analysis);
viz.shutdown();
return res;
}
Aggregations