checkstyle

This commit is contained in:
Clément Fournier committed 2022-11-27 01:24:39 +01:00
1 parent d29a2b093f
commit a3bdd62c40
7 files changed
+54 -60

No files matched your search

@@ -15,19 +15,20 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot;
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolEquality;
import net.sourceforge.pmd.lang.java.types.TypeSystem;
/**
*
* Wraps an instance of a JVM {@link Annotation} and provide the same API as {@link SymAnnot}.
*/
class AnnotWrapperImpl implements SymAnnot {
class AnnotWrapper implements SymAnnot {
private final Annotation annotation;
private final Class<? extends Annotation> annotationClass;
private final JClassSymbol annotationClassSymbol;
private AnnotWrapperImpl(JClassSymbol annotationClassSymbol, @NonNull Annotation annotation) {
private AnnotWrapper(JClassSymbol annotationClassSymbol, @NonNull Annotation annotation) {
this.annotationClassSymbol = annotationClassSymbol;
this.annotation = annotation;
this.annotationClass = annotation.annotationType();
@@ -38,7 +39,7 @@ class AnnotWrapperImpl implements SymAnnot {
if (sym == null) {
return null;
}
return new AnnotWrapperImpl(sym, annotation);
return new AnnotWrapper(sym, annotation);
}
@Override
@@ -69,7 +70,9 @@ class AnnotWrapperImpl implements SymAnnot {
} catch (Exception ignored) {
return null;
}
}).findAny().orElse(null);
})
.filter(Objects::nonNull)
.findAny().orElse(null);
}
@Override
@@ -88,7 +88,7 @@ public interface SymbolicValue {
}
if (value instanceof Annotation) {
return AnnotWrapperImpl.wrap(ts, (Annotation) value);
return AnnotWrapper.wrap(ts, (Annotation) value);
}
if (value instanceof Class<?>) {
@@ -11,7 +11,7 @@ class AnnotationBuilderVisitor extends SymbolicValueBuilder {
final SymbolicAnnotationImpl annot;
private final AnnotationOwner owner;
public AnnotationBuilderVisitor(AnnotationOwner owner, AsmSymbolResolver resolver, boolean visible, String descriptor) {
AnnotationBuilderVisitor(AnnotationOwner owner, AsmSymbolResolver resolver, boolean visible, String descriptor) {
super(resolver);
this.annot = new SymbolicAnnotationImpl(resolver, visible, descriptor);
this.owner = owner;
@@ -12,11 +12,11 @@ import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.objectweb.asm.Opcodes;
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue;
import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol;
import net.sourceforge.pmd.lang.java.symbols.JFormalParamSymbol;
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue;
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolEquality;
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolToStrings;
import net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.LazyMethodType;
@@ -8,7 +8,6 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -12,9 +12,8 @@ import java.util.List;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
import net.sourceforge.pmd.lang.java.BaseParserTest;
import net.sourceforge.pmd.lang.java.JavaParsingHelper;
class ASTSwitchLabelTest extends BaseParserTest {
@@ -56,60 +55,52 @@ class ASTSwitchLabelTest extends BaseParserTest {
assertFalse(switchStmt.isExhaustiveEnumSwitch());
}
private static final String TEST1 = "public class Foo {\n" +
" void bar() {\n" +
" switch (x) {\n" +
" case 1: y = 2;\n" +
" }\n" +
" }\n" +
"}";
private static final String SWITCH_WITH_DEFAULT =
"public class Foo {\n" +
" void bar() {\n" +
" switch (x) {\n" +
" default: y = 2;\n" +
" case 4: break;\n" +
" }\n" +
" }\n" +
"}";
"public class Foo {\n"
+ " void bar() {\n"
+ " switch (x) {\n"
+ " default: y = 2;\n"
+ " case 4: break;\n"
+ " }\n"
+ " }\n"
+ "}";
private static final String EXHAUSTIVE_ENUM =
"public class Foo {\n" +
" void bar() {\n" +
" enum LocalEnum { A, B, C } " +
" var v = LocalEnum.A; " +
" switch (v) {\n" +
" case A: break;\n" +
" case B: break;\n" +
" case C: break;\n" +
" }\n" +
" }\n" +
"}";
"public class Foo {\n"
+ " void bar() {\n"
+ " enum LocalEnum { A, B, C } "
+ " var v = LocalEnum.A; "
+ " switch (v) {\n"
+ " case A: break;\n"
+ " case B: break;\n"
+ " case C: break;\n"
+ " }\n"
+ " }\n"
+ "}";
private static final String NOT_EXHAUSTIVE_ENUM =
"public class Foo {\n" +
" void bar() {\n" +
" enum LocalEnum { A, B, C } " +
" var v = LocalEnum.A; " +
" switch (v) {\n" +
" case A: break;\n" +
" // case B: break;\n" +
" case C: break;\n" +
" }\n" +
" }\n" +
"}";
"public class Foo {\n"
+ " void bar() {\n"
+ " enum LocalEnum { A, B, C } "
+ " var v = LocalEnum.A; "
+ " switch (v) {\n"
+ " case A: break;\n"
+ " // case B: break;\n"
+ " case C: break;\n"
+ " }\n"
+ " }\n"
+ "}";
private static final String ENUM_SWITCH_WITH_DEFAULT =
"public class Foo {\n" +
" void bar() {\n" +
" enum LocalEnum { A, B, C } " +
" var v = LocalEnum.A; " +
" switch (v) {\n" +
" case A: break;\n" +
" case C: break;\n" +
" default: break;\n" +
" }\n" +
" }\n" +
"}";
"public class Foo {\n"
+ " void bar() {\n"
+ " enum LocalEnum { A, B, C } "
+ " var v = LocalEnum.A; "
+ " switch (v) {\n"
+ " case A: break;\n"
+ " case C: break;\n"
+ " default: break;\n"
+ " }\n"
+ " }\n"
+ "}";
}
@@ -206,6 +206,7 @@ public class SymbolReflectionTest {
Assert.assertTrue(sym.isInterface());
return sym;
}
private @NonNull JClassSymbol loadClass(Class<?> klass) {
JClassSymbol sym = loader.resolveClassFromBinaryName(klass.getName());
Assert.assertNotNull(sym);