Skip to content

Commit

Permalink
Merge branch 'master' into nimak/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Oct 9, 2024
2 parents 214f73b + 6783200 commit 3ea7bba
Show file tree
Hide file tree
Showing 63 changed files with 211 additions and 17 deletions.
7 changes: 4 additions & 3 deletions annotator-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id 'com.github.sherter.google-java-format' version '0.9'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'maven-publish'
id 'application'
Expand All @@ -52,8 +51,10 @@ dependencies {
}

// Exclude formatting files under resources
googleJavaFormat {
exclude 'src/test/resources/**/*.java'
spotless {
java {
targetExclude 'src/test/resources/**/*.java'
}
}

// Should be the latest supporting version of NullAway.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ public class Annotator {

/** Injector instance. */
private final AnnotationInjector injector;

/** Annotator context. */
public final Context context;

/** Reports cache. */
public final ReportCache cache;

/** Annotator configuration. */
public final Config config;

Expand Down
26 changes: 26 additions & 0 deletions annotator-core/src/main/java/edu/ucr/cs/riple/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,86 +68,111 @@ public class Config {
* zero or less.
*/
public final boolean bailout;

/** If activated, impact of fixes will be computed in parallel. */
public final boolean useParallelGraphProcessor;

/** If activated, impact of fixes will be cached. */
public final boolean useImpactCache;

/**
* If activated, all suggested fixes from the checker will be applied to the source code
* regardless of their effectiveness.
*/
public final boolean exhaustiveSearch;

/**
* If activated, all containing fixes in the fix tree will be applied to the source code,
* otherwise only the root fix will be applied.
*/
public final boolean chain;

/**
* If enabled, at each iteration fixes with effectiveness will be tagged to exclude them in
* further iterations.
*/
public final boolean useCache;

/** If true, build outputs will be redirected to STD Err. */
public final boolean redirectBuildOutputToStdErr;

/** If activated, it will disable the outer loop. */
public final boolean disableOuterLoop;

/** Info of target module. */
public final ModuleConfiguration target;

/** Path to directory where all outputs of checker and scanner checker is located. */
public final Path globalDir;

/** Command to build the target module. */
public final String buildCommand;

/** Fully qualified name of the {@code nullable} annotation. */
public final String nullableAnnot;

/** Fully qualified name of the {@code initializer} annotation. */
public final String initializerAnnot;

/** If enabled, effects of public API on downstream dependencies will be considered. */
public final boolean downStreamDependenciesAnalysisActivated;

/** Sets of context path information for all downstream dependencies. */
public final ImmutableSet<ModuleConfiguration> downstreamConfigurations;

/**
* Path to NullAway library model loader resource directory, which enables the communication
* between annotator and NullAway when processing downstream dependencies. Annotator will write
* annotation on files in this directory and the using Library Model Loader reads them.
*/
public final Path nullawayLibraryModelLoaderPath;

/** Command to build the all downstream dependencies at once. */
public final String downstreamDependenciesBuildCommand;

/**
* Analysis mode. Will impact inference decisions when downstream dependency analysis is
* activated.
*/
public final AnalysisMode mode;

/** Global counter for assigning unique id for each instance. */
private int moduleCounterID;

/**
* If activated, Annotator will try to suppress all remaining errors. The logic is specific to the
* checker suppression mechanism. Annotator will simply call {@link
* edu.ucr.cs.riple.core.checkers.Checker#suppressRemainingErrors} methods.
*/
public final boolean suppressRemainingErrors;

/** Fully qualified NullUnmarked annotation. */
public final String nullUnMarkedAnnotation;

/**
* Set of {@code @Nonnull} annotations to be acknowledged by Annotator. If an element is annotated
* with these annotations along any other annotation ending with {@code "nonnull"}, Annotator will
* acknowledge the annotation and will not add any {@code @Nullable} annotation to the element.
*/
public final ImmutableSet<String> nonnullAnnotations;

/** Depth of the analysis. Default to 5 if not set by the user */
public final int depth;

/**
* Activates inference to add {@code @Nullable} qualifiers.
*
* <p>Note: Inference mode is mostly deactivated for experiments purposes and the default value is
* {@code true} in production.
*/
public final boolean inferenceActivated;

/**
* Generated code detectors. Responsible for detecting regions that are not present in the source
* code and are generated by a processor.
*/
public final ImmutableSet<SourceType> generatedCodeDetectors;

/**
* Checker name to retrieve the {@link edu.ucr.cs.riple.core.checkers.Checker} specific instance.
*/
Expand Down Expand Up @@ -685,6 +710,7 @@ public static class Builder {
public String initializerAnnotation;
public String nullableAnnotation;
public String outputDir;

/**
* List of modules, did not use {@link java.util.Set} to preserve order. First project is the
* target project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ public class Context {

/** Annotator configuration. */
public final Config config;

/** Log instance. Responsible for logging all the information about the build time and count. */
public final Log log;

/** Handler for computing the original offset of reported errors with existing changes. */
public final OffsetHandler offsetHandler;

/** The moduleInfo of target module. */
public final ModuleInfo targetModuleInfo;

/**
* Configuration of the target module, required for building the target module and collecting
* checkers output.
*/
public final ModuleConfiguration targetConfiguration;

/** Sets of context path information for all downstream dependencies. */
public final ImmutableSet<ModuleConfiguration> downstreamConfigurations;

/** Checker instance. Used to execute checker specific tasks. */
public final Checker<? extends Error> checker;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,34 @@ public class Report {

/** Effect on target module. */
public int localEffect;

/** Root of fix tree associated to this report instance. */
public Fix root;

/** Fix tree associated to this report instance. */
public Set<Fix> tree;

/**
* Set of errors that will be triggered in target module if fix tree is applied to the source
* code.
*/
public ImmutableSet<Error> triggeredErrors;

/**
* Set of triggered fixes on target module that will be triggered if fix tree is applied due to
* errors in downstream dependencies.
*/
public ImmutableSet<Fix> triggeredFixesFromDownstreamErrors;

/** If true, this report's tree has been processed for at least one iteration */
public boolean hasBeenProcessedOnce;

/**
* Lower bound of number of errors in downstream dependencies if fix tree is applied to the target
* module.
*/
private int lowerBoundEffectOnDownstreamDependencies;

/**
* Upper bound of number of errors in downstream dependencies if fix tree is applied to the target
* module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class ReportCache {
* efficiently.
*/
private final Map<Fix, Report> store;

/** Cache activation switch. */
private boolean enabled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class Impact {

/** Target fix. */
public final Fix fix;

/** Set of triggered errors, if this fix is applied to source code. */
protected ImmutableSet<Error> triggeredErrors;

/**
* Set of triggered fixes on the target module from downstream dependencies errors if containing
* fix is applied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class CheckerBaseClass<T extends Error> implements Checker<T> {

/** Annotator config. */
protected final Config config;

/** Annotator context. */
protected final Context context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class NullAway extends CheckerBaseClass<NullAwayError> {
* The name of the checker. To select this checker, this name must be used in the configurations.
*/
public static final String NAME = "NULLAWAY";

/** Supported version of NullAway serialization. */
public static final int VERSION = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class NullAwayError extends Error {

/** Error type for method initialization errors from NullAway in {@code String}. */
public static final String METHOD_INITIALIZER_ERROR = "METHOD_NO_INIT";

/** Error type for field initialization errors from NullAway in {@code String}. */
public static final String FIELD_INITIALIZER_ERROR = "FIELD_NO_INIT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public abstract class AbstractEvaluator implements Evaluator {

/** Annotator context. */
protected final Context context;

/** Conflict graph to storing unprocessed fixes. */
protected final ConflictGraph graph;

/** Depth of analysis. */
protected final int depth;

/** Graph processor to process the graph. */
protected ConflictGraphProcessor processor;

/** Supplier used for initialization. */
protected final Supplier supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ConflictGraph {

/** Nodes in this graph */
public final Multimap<Integer, Node> nodes;

/**
* Groups in this graph, nodes which does not have any conflict in regions will in the same group.
* Please note that this is a graph coloring problem, set of groups is calculated using a greedy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,31 @@ public class Node {

/** Root fix of the tree. */
public final Fix root;

/** Set of all fixes in tree. */
public final Set<Fix> tree;

/** Set of potentially impacted by any node in tree. */
public final Set<Region> regions;

/** Set of triggered errors if tree is applied on target module. */
public ImmutableSet<Error> triggeredErrors;

/**
* Set of triggered fixes on target module that will be triggered if fix tree is applied due to
* errors in downstream dependencies.
*/
public ImmutableSet<Fix> triggeredFixesFromDownstreamErrors;

/** Unique id of Node across all nodes. */
public int id;

/** Effect of applying containing change */
public int effect;

/** Corresponding report of processing root. */
public Report report;

/** Regions where original errors reported and NullAway suggested root for that. */
private ImmutableSet<Region> origins;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ public abstract class AbstractConflictGraphProcessor implements ConflictGraphPro

/** Injector used in the processor to inject / remove fixes. */
protected final AnnotationInjector injector;

/** Error store instance to store state of fixes before and after of injections. */
protected final ErrorStore errorStore;

/** Downstream impact cache to retrieve impacts of fixes globally. */
protected final DownstreamImpactCache downstreamImpactCache;

/** Annotator context. */
protected final Context context;

/** Handler to re-run compiler. */
protected final CompilerRunner compilerRunner;

/** ModuleInfo of the input module which the impact of fixes are computed on. */
protected final ModuleInfo moduleInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public abstract class AbstractSupplier implements Supplier {

/** Error Store instance. */
protected final ErrorStore errorStore;

/** Injector instance. */
protected final AnnotationInjector injector;

/** ModuleInfo of the module which the impact of fixes are computed on. */
protected final ModuleInfo moduleInfo;

/** Depth of analysis. */
protected final int depth;

/** Annotator context. */
protected final Context context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ public class VirtualInjector extends AnnotationInjector {

/** Path to library model loader resources directory */
private final Path libraryModelResourcesDirectoryPath;

/**
* Annotator configuration, required to check if downstream dependencies analysis is activated or
* retrieve the path to library model loader.
*/
private final Config config;

/** Name of the resource file in library model loader which contains list of nullable methods. */
public static final String NULLABLE_METHOD_LIST_FILE_NAME = "nullable-methods.tsv";

/** Name of the resource file in library model loader which contains list of nullable fields. */
public static final String NULLABLE_FIELD_LIST_FILE_NAME = "nullable-fields.tsv";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public class Log {

/** Sum of number of nodes constructed in each {@link ConflictGraph}. */
private long nodes;

/** Number of build requests. */
private long requested;

/** Total time spent for annotator from start to finish. */
private long totalTime;

/** Total time spent in building targets. */
private long buildTime = 0;

/**
* Set of approved and injected annotations. These annotations are evaluated and approved and will
* not get removed from the source code.
Expand Down
Loading

0 comments on commit 3ea7bba

Please sign in to comment.