Search in sources :

Example 56 with Nullable

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;
    }
}
Also used : SegmentContext(com.amazonaws.xray.contexts.SegmentContext) Entity(com.amazonaws.xray.entities.Entity) TraceID(com.amazonaws.xray.entities.TraceID) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 57 with Nullable

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;
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 58 with Nullable

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);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 59 with Nullable

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();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 60 with Nullable

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;
}
Also used : ControlFlowGraph(org.checkerframework.dataflow.cfg.ControlFlowGraph) JavaFileObject(javax.tools.JavaFileObject) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)285 ArrayList (java.util.ArrayList)27 TypeElement (javax.lang.model.element.TypeElement)23 IOException (java.io.IOException)21 Map (java.util.Map)21 ExecutableElement (javax.lang.model.element.ExecutableElement)19 ServerLevel (net.minecraft.server.level.ServerLevel)19 List (java.util.List)16 Instant (org.joda.time.Instant)16 VariableElement (javax.lang.model.element.VariableElement)15 HashMap (java.util.HashMap)14 Optional (java.util.Optional)14 Element (javax.lang.model.element.Element)13 TreePath (com.sun.source.util.TreePath)12 BlockPos (net.minecraft.core.BlockPos)12 Method (java.lang.reflect.Method)11 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)10 VariableTree (com.sun.source.tree.VariableTree)8 ClassTree (com.sun.source.tree.ClassTree)7