Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.checkerframework.common.value;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.NewClassTree;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signature.qual.CanonicalNameOrEmpty;
import org.checkerframework.checker.signature.qual.ClassGetName;
import org.checkerframework.common.basetype.BaseTypeChecker;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;
import org.plumelib.util.CollectionsPlume;
import org.plumelib.util.StringsPlume;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
// The use of reflection in ReflectiveEvaluator is troubling.
// A static analysis such as the Checker Framework should always use compiler APIs, never
// reflection, to obtain values, for these reasons:
// * The program being compiled is not necessarily on the classpath nor the processorpath.
// * There might even be a different class of the same fully-qualified name on the processorpath.
// * Loading a class can have side effects (say, caused by static initializers).
//
// A better implementation strategy would be to use BeanShell or the like to perform evaluation.
/**
* Evaluates expressions (such as method calls and field accesses) at compile time, to determine
* whether they have compile-time constant values.
*/
public class ReflectiveEvaluator {
/** The checker that is using this ReflectiveEvaluator. */
private final BaseTypeChecker checker;
/**
* Whether to report warnings about problems with evaluation. Controlled by the
* -AreportEvalWarns command-line option.
*/
private final boolean reportWarnings;
/**
* Create a new ReflectiveEvaluator.
*
* @param checker the BaseTypeChecker
* @param factory the annotated type factory
* @param reportWarnings if true, report warnings about problems with evaluation
*/
public ReflectiveEvaluator(
BaseTypeChecker checker, ValueAnnotatedTypeFactory factory, boolean reportWarnings) {
this.checker = checker;
this.reportWarnings = reportWarnings;
}
/**
* Returns all possible values that the method may return, or null if the method could not be
* evaluated.
*
* @param allArgValues a list of lists where the first list corresponds to all possible values
* for the first argument. Pass null to indicate that the method has no arguments.
* @param receiverValues a list of possible receiver values. null indicates that the method has
* no receiver.
* @param tree location to report any errors
* @return all possible values that the method may return, or null if the method could not be
* evaluated
*/
public @Nullable List> evaluateMethodCall(
@Nullable List> allArgValues,
@Nullable List> receiverValues,
MethodInvocationTree tree) {
Method method = getMethodObject(tree);
if (method == null) {
return null;
}
if (receiverValues == null) {
// Method does not have a receiver
// the first parameter of Method.invoke should be null
receiverValues = Collections.singletonList(null);
}
List