Skip to content

Commit

Permalink
fix plugin config, remove jetbrains annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Nicklas Körtge <[email protected]>
  • Loading branch information
n1ckl0sk0rtge committed Nov 20, 2024
1 parent fd6b256 commit b09c936
Show file tree
Hide file tree
Showing 492 changed files with 1,207 additions and 1,577 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Unmodifiable;

public class DetectionStore<R, T, S, P> implements IHookDetectionObserver<R, T, S, P> {
protected final int level;
Expand Down Expand Up @@ -120,7 +119,6 @@ public Optional<IAction<T>> getActionValue() {
* @return a list of all detection values in the order they were added to the store.
*/
@Nonnull
@Unmodifiable
public List<IValue<T>> getDetectionValues() {
if (actionValue == null) {
return detectionValues.values().stream().flatMap(List::stream).toList();
Expand All @@ -142,7 +140,7 @@ public List<IValue<T>> getDetectionValues() {
* inputs.
*/
public void detectionValuesForEachParameter(
@Nonnull BiConsumer<Integer, @Unmodifiable List<IValue<T>>> consumer) {
@Nonnull BiConsumer<Integer, List<IValue<T>>> consumer) {
this.detectionValues.forEach(
(k, v) ->
consumer.accept(
Expand All @@ -159,7 +157,6 @@ public void detectionValuesForEachParameter(
* @return an immutable and non-null list of all the children stores
*/
@Nonnull
@Unmodifiable
public List<DetectionStore<R, T, S, P>> getChildren() {
return children.values().stream().flatMap(List::stream).toList();
}
Expand All @@ -170,7 +167,6 @@ public List<DetectionStore<R, T, S, P>> getChildren() {
* @return the eventual child detection stores, whose detection rule relates to the method
*/
@Nonnull
@Unmodifiable
public List<DetectionStore<R, T, S, P>> getChildrenForMethod() {
return Optional.ofNullable(this.children.get(-1)).orElse(List.of());
}
Expand All @@ -186,7 +182,7 @@ public List<DetectionStore<R, T, S, P>> getChildrenForMethod() {
* on these inputs.
*/
public void childrenForEachParameter(
@Nonnull BiConsumer<Integer, @Unmodifiable List<DetectionStore<R, T, S, P>>> consumer) {
@Nonnull BiConsumer<Integer, List<DetectionStore<R, T, S, P>>> consumer) {
for (Map.Entry<Integer, List<DetectionStore<R, T, S, P>>> entry :
this.children.entrySet()) {
if (entry.getKey() == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ private void onHookInvocation(
if (hook
instanceof
MethodInvocationHookWithParameterResolvement<R, T, S, P>
methodInvocationHookWithParameterResolvement) {
methodInvocationHookWithParameterResolvement) {
handleMethodInvocationHookWithParameterResolvement(
invocationTree, methodInvocationHookWithParameterResolvement, isSuccessive);
} else if (hook
instanceof
MethodInvocationHookWithReturnResolvement<R, T, S, P>
methodInvocationHookWithReturnResolvement) {
methodInvocationHookWithReturnResolvement) {
handleMethodInvocationHookWithReturnResolvement(
methodInvocationHookWithReturnResolvement, isSuccessive);
} else if (hook instanceof EnumHook<R, T, S, P> enumHook) {
Expand Down
3 changes: 1 addition & 2 deletions engine/src/main/java/com/ibm/engine/detection/Finding.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.ibm.engine.rule.IBundle;
import java.util.List;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public record Finding<R, T, S, P>(@Nonnull DetectionStore<R, T, S, P> detectionStore) {

Expand Down Expand Up @@ -58,7 +57,7 @@ public int hashCode() {
+ calculateHashCodeForChildren(detectionStore.getChildren());
}

private int calculateHashCodeForChildren(@NotNull List<DetectionStore<R, T, S, P>> children) {
private int calculateHashCodeForChildren(@Nonnull List<DetectionStore<R, T, S, P>> children) {
return children.stream()
.map(
store ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.TestOnly;
import org.sonarsource.analyzer.commons.collections.SetUtils;

public final class MethodMatcher<T> {
Expand Down Expand Up @@ -175,17 +174,17 @@ public boolean match(
&& this.parameterTypes.test(param);
}

@TestOnly
@Nonnull
public List<String> getInvokedObjectTypeStringsSerializable() {
return this.invokedObjectTypeStringsSerializable;
}

@TestOnly
@Nonnull
public List<String> getMethodNamesSerializable() {
return this.methodNamesSerializable;
}

@TestOnly
@Nonnull
public List<String> getParameterTypesSerializable() {
return this.parameterTypesSerializable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

import com.ibm.common.IDomainEvent;
import com.ibm.common.IObserver;
import com.ibm.engine.detection.*;
import com.ibm.engine.detection.DetectionStore;
import com.ibm.engine.detection.Finding;
import com.ibm.engine.detection.Handler;
import com.ibm.engine.language.IScanContext;
import com.ibm.engine.rule.IDetectionRule;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.Unmodifiable;

public class DetectionExecutive<R, T, S, P>
implements IStatusReporting<R, T, S, P>, IDomainEvent<Finding<R, T, S, P>> {
Expand Down Expand Up @@ -81,7 +84,6 @@ public void addAdditionalExpectedRuleVisits(int number) {
}

@Nonnull
@Unmodifiable
private List<DetectionStore<R, T, S, P>> getRootStoresWithValue(
@Nonnull DetectionStore<R, T, S, P> detectionStore) {
if (!detectionStore.getDetectionValues().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private void createAMethodHook(
if (this.detectionStore
instanceof
final DetectionStoreWithHook<JavaCheck, Tree, Symbol, JavaFileScannerContext>
detectionStoreWithHook) {
detectionStoreWithHook) {
detectionStoreWithHook.onSuccessiveHook(methodInvocationHookWithReturnResolvement);
} else {
if (handler.addHookToHookRepository(methodInvocationHookWithReturnResolvement)) {
Expand All @@ -449,7 +449,7 @@ private void createAMethodHook(
if (this.detectionStore
instanceof
final DetectionStoreWithHook<JavaCheck, Tree, Symbol, JavaFileScannerContext>
detectionStoreWithHook) {
detectionStoreWithHook) {
detectionStoreWithHook.onSuccessiveHook(methodInvocationHookWithParameterResolvement);
} else {
if (handler.addHookToHookRepository(methodInvocationHookWithParameterResolvement)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.java.model.ExpressionUtils;
Expand Down Expand Up @@ -66,7 +65,7 @@ public ILanguageTranslation<Tree> translation() {

@Nonnull
@Override
public @NotNull DetectionExecutive<JavaCheck, Tree, Symbol, JavaFileScannerContext>
public DetectionExecutive<JavaCheck, Tree, Symbol, JavaFileScannerContext>
createDetectionExecutive(
@Nonnull Tree tree,
@Nonnull IDetectionRule<Tree> detectionRule,
Expand All @@ -76,7 +75,7 @@ public ILanguageTranslation<Tree> translation() {

@Nonnull
@Override
public @NotNull IDetectionEngine<Tree, Symbol> createDetectionEngineInstance(
public IDetectionEngine<Tree, Symbol> createDetectionEngineInstance(
@Nonnull
DetectionStore<JavaCheck, Tree, Symbol, JavaFileScannerContext>
detectionStore) {
Expand All @@ -85,13 +84,13 @@ public ILanguageTranslation<Tree> translation() {

@Nonnull
@Override
public @NotNull IBaseMethodVisitorFactory<Tree, Symbol> getBaseMethodVisitorFactory() {
public IBaseMethodVisitorFactory<Tree, Symbol> getBaseMethodVisitorFactory() {
return JavaBaseMethodVisitor::new;
}

@Nonnull
@Override
public @NotNull Optional<Tree> getEnclosingMethod(@Nonnull Tree expression) {
public Optional<Tree> getEnclosingMethod(@Nonnull Tree expression) {
if (expression instanceof ExpressionTree expressionTree) {
return Optional.ofNullable(ExpressionUtils.getEnclosingMethod(expressionTree));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
import com.ibm.engine.detection.IType;
import com.ibm.engine.detection.MatchContext;
import com.ibm.engine.language.ILanguageTranslation;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.java.model.ExpressionUtils;
import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.tree.Arguments;
import org.sonar.plugins.java.api.tree.ClassTree;
import org.sonar.plugins.java.api.tree.ExpressionTree;
import org.sonar.plugins.java.api.tree.IdentifierTree;
import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;
import org.sonar.plugins.java.api.tree.MethodInvocationTree;
import org.sonar.plugins.java.api.tree.NewClassTree;
import org.sonar.plugins.java.api.tree.Tree;

public class JavaLanguageTranslation implements ILanguageTranslation<Tree> {
@Nonnull
Expand Down Expand Up @@ -126,7 +136,7 @@ public Optional<IType> getInvokedObjectTypeString(

@Nonnull
@Override
public @NotNull Optional<IType> getMethodReturnTypeString(
public Optional<IType> getMethodReturnTypeString(
@Nonnull MatchContext matchContext, @Nonnull Tree methodInvocation) {
if (methodInvocation instanceof MethodInvocationTree methodInvocationTree) {
return Optional.of(methodInvocationTree.methodSymbol())
Expand All @@ -146,7 +156,7 @@ public Optional<IType> getInvokedObjectTypeString(

@Nonnull
@Override
public @NotNull List<IType> getMethodParameterTypes(
public List<IType> getMethodParameterTypes(
@Nonnull MatchContext matchContext, @Nonnull Tree methodInvocation) {
Arguments arguments;
if (methodInvocation instanceof MethodInvocationTree methodInvocationTree) {
Expand Down Expand Up @@ -203,7 +213,7 @@ public Optional<IType> getInvokedObjectTypeString(

@Nonnull
@Override
public @NotNull Optional<String> resolveIdentifierAsString(
public Optional<String> resolveIdentifierAsString(
@Nonnull MatchContext matchContext, @Nonnull Tree identifier) {
if (identifier instanceof IdentifierTree identifierTree) {
return Optional.of(identifierTree.identifierToken().text());
Expand All @@ -213,7 +223,7 @@ public Optional<IType> getInvokedObjectTypeString(

@Nonnull
@Override
public @NotNull Optional<String> getEnumIdentifierName(
public Optional<String> getEnumIdentifierName(
@Nonnull MatchContext matchContext, @Nonnull Tree enumIdentifier) {
if (enumIdentifier instanceof IdentifierTree identifierTree) {
return Optional.of(identifierTree.name());
Expand All @@ -223,7 +233,7 @@ public Optional<IType> getInvokedObjectTypeString(

@Nonnull
@Override
public @NotNull Optional<String> getEnumClassName(
public Optional<String> getEnumClassName(
@Nonnull MatchContext matchContext, @Nonnull Tree enumClass) {
if (enumClass instanceof ClassTree classTree) {
IdentifierTree enumClassIdentifier = classTree.simpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.ibm.engine.language.IScanContext;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.plugins.java.api.JavaCheck;
import org.sonar.plugins.java.api.JavaFileScannerContext;
Expand All @@ -37,13 +36,13 @@ public void reportIssue(

@Nonnull
@Override
public @NotNull InputFile getInputFile() {
public InputFile getInputFile() {
return this.javaFileScannerContext.getInputFile();
}

@Nonnull
@Override
public @NotNull String getFilePath() {
public String getFilePath() {
return this.javaFileScannerContext.getInputFile().uri().getPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.sonar.plugins.python.api.PythonCheck;
import org.sonar.plugins.python.api.PythonVisitorContext;
import org.sonar.plugins.python.api.symbols.Symbol;
Expand Down Expand Up @@ -128,9 +127,9 @@ public Tree extractArgumentFromMethodCaller(
}

@Override
public <O> @NotNull List<ResolvedValue<O, Tree>> resolveValuesInInnerScope(
@NotNull Class<O> clazz,
@NotNull Tree expression,
public <O> @Nonnull List<ResolvedValue<O, Tree>> resolveValuesInInnerScope(
@Nonnull Class<O> clazz,
@Nonnull Tree expression,
@Nullable IValueFactory<Tree> valueFactory) {
if (expression instanceof Expression expressionTree) {
return PythonSemantic.resolveValues(
Expand Down Expand Up @@ -194,7 +193,7 @@ private void createAMethodHook(
if (this.detectionStore
instanceof
final DetectionStoreWithHook<PythonCheck, Tree, Symbol, PythonVisitorContext>
detectionStoreWithHook) {
detectionStoreWithHook) {
detectionStoreWithHook.onSuccessiveHook(methodInvocationHookWithReturnResolvement);
} else {
handler.addHookToHookRepository(methodInvocationHookWithReturnResolvement);
Expand All @@ -211,7 +210,7 @@ private void createAMethodHook(
if (this.detectionStore
instanceof
final DetectionStoreWithHook<PythonCheck, Tree, Symbol, PythonVisitorContext>
detectionStoreWithHook) {
detectionStoreWithHook) {
detectionStoreWithHook.onSuccessiveHook(methodInvocationHookWithParameterResolvement);
} else {
handler.addHookToHookRepository(methodInvocationHookWithParameterResolvement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.LinkedList;
import java.util.Optional;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
import org.sonar.plugins.python.api.PythonCheck;
import org.sonar.plugins.python.api.PythonVisitorContext;
import org.sonar.plugins.python.api.symbols.Symbol;
Expand All @@ -62,28 +61,29 @@ public ILanguageTranslation<Tree> translation() {
}

@Override
public @NotNull DetectionExecutive<PythonCheck, Tree, Symbol, PythonVisitorContext>
public @Nonnull DetectionExecutive<PythonCheck, Tree, Symbol, PythonVisitorContext>
createDetectionExecutive(
@NotNull Tree tree,
@NotNull IDetectionRule<Tree> detectionRule,
@NotNull IScanContext<PythonCheck, Tree> scanContext) {
@Nonnull Tree tree,
@Nonnull IDetectionRule<Tree> detectionRule,
@Nonnull IScanContext<PythonCheck, Tree> scanContext) {
return new DetectionExecutive<>(tree, detectionRule, scanContext, this.handler);
}

@Override
public @NotNull IDetectionEngine<Tree, Symbol> createDetectionEngineInstance(
@NotNull DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext>
public @Nonnull IDetectionEngine<Tree, Symbol> createDetectionEngineInstance(
@Nonnull
DetectionStore<PythonCheck, Tree, Symbol, PythonVisitorContext>
detectionStore) {
return new PythonDetectionEngine(detectionStore, this.handler);
}

@Override
public @NotNull IBaseMethodVisitorFactory<Tree, Symbol> getBaseMethodVisitorFactory() {
public @Nonnull IBaseMethodVisitorFactory<Tree, Symbol> getBaseMethodVisitorFactory() {
return PythonBaseMethodVisitor::new;
}

@Override
public @NotNull Optional<Tree> getEnclosingMethod(@NotNull Tree expression) {
public @Nonnull Optional<Tree> getEnclosingMethod(@Nonnull Tree expression) {
// In Python, there isn't necessarily an enclosing method: we return it if it exists,
// otherwise we return the highest level root node corresponding to all the content of the
// current file.
Expand All @@ -98,7 +98,7 @@ public ILanguageTranslation<Tree> translation() {
}

@Override
public MethodMatcher<Tree> createMethodMatcherBasedOn(@NotNull Tree methodDefinition) {
public MethodMatcher<Tree> createMethodMatcherBasedOn(@Nonnull Tree methodDefinition) {
if (methodDefinition instanceof FunctionDef functionDefTree) {
// The `invocationObjectName` consists of the filename + the class(es). We use
// `fullyQualifiedName`, here that basically is `invocationObjectName` + the function
Expand Down Expand Up @@ -135,7 +135,7 @@ public MethodMatcher<Tree> createMethodMatcherBasedOn(@NotNull Tree methodDefini

@Override
public EnumMatcher<Tree> createSimpleEnumMatcherFor(
@NotNull Tree enumIdentifier, @Nonnull MatchContext matchContext) {
@Nonnull Tree enumIdentifier, @Nonnull MatchContext matchContext) {
Optional<String> enumIdentifierName =
translation().getEnumIdentifierName(matchContext, enumIdentifier);
return enumIdentifierName.<EnumMatcher<Tree>>map(EnumMatcher::new).orElse(null);
Expand Down
Loading

0 comments on commit b09c936

Please sign in to comment.