Skip to content
Permalink
Browse files
Use final.
  • Loading branch information
garydgregory committed Nov 21, 2020
1 parent bde935d commit a49d5b94fe4c7a35b7ff84b76e3cb0de445d9de8
Showing 12 changed files with 47 additions and 47 deletions.
@@ -101,7 +101,7 @@ public final void execute() throws MojoExecutionException, MojoFailureException
final List<String> classpath;
try {
classpath = createClasspath();
} catch (DependencyResolutionException e) {
} catch (final DependencyResolutionException e) {
throw new MojoExecutionException("Error getting classpath artifacts", e);
}
final File target = getTarget();
@@ -38,7 +38,7 @@ protected void doExecute(final File target, final List<String> classpath, final
}
try {
new CleanProcessor(classpath, target, config).clean();
} catch (Exception e) {
} catch (final Exception e) {
throw new MojoExecutionException("cleaning failed due to " + e.getMessage(), e);
}
}
@@ -35,7 +35,7 @@ protected void doExecute(final File target, final List<String> classpath, final
throws MojoExecutionException {
try {
new WeaveProcessor(classpath, target, config).weave();
} catch (Exception e) {
} catch (final Exception e) {
throw new MojoExecutionException("weaving failed due to " + e.getMessage(), e);
}
}
@@ -74,7 +74,7 @@ public void activate() throws MojoExecutionException {
activeHandler.setLevel(Level.ALL);
rootLogger.setLevel(Level.ALL);
rootLogger.addHandler(activeHandler);
} catch (Exception exc) {
} catch (final Exception exc) {
throw new MojoExecutionException("failed to activate the jul logging redirector", exc);
}
}
@@ -89,9 +89,9 @@ public void testParseMissingType() {
Utils.parseTypes("java.lang.Object,,java.lang.Iterable", getClass().getClassLoader());
}

<E> void assertContainsInOrder(Iterable<E> iterable, E... expectedElements) {
<E> void assertContainsInOrder(final Iterable<E> iterable, final E... expectedElements) {
final Iterator<E> iterator = iterable.iterator();
for (E e : expectedElements) {
for (final E e : expectedElements) {
assertTrue(iterator.hasNext());
assertEquals(e, iterator.next());
}
@@ -369,7 +369,7 @@ public List<Annotated<Package>> findAnnotatedPackages(final Class<? extends Anno
return typed(PackageInfo.class, getAnnotationInfos(annotation.getName())::stream).map(packageInfo -> {
try {
return new IncludesClassfile<>(packageInfo.get(), classfileAnnotationsFor(packageInfo));
} catch (ClassNotFoundException e) {
} catch (final ClassNotFoundException e) {
return null;
}
}).filter(hasAnnotation(annotation)).collect(Collectors.toList());
@@ -395,7 +395,7 @@ private List<Annotated<Class<?>>> annotate(final Collection<? extends Info> info
return typed(ClassInfo.class, infos::stream).map(classInfo -> {
try {
return new IncludesClassfile<Class<?>>(classInfo.get(), classfileAnnotationsFor(classInfo));
} catch (ClassNotFoundException e1) {
} catch (final ClassNotFoundException e1) {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
@@ -73,14 +73,14 @@ private Finder finder() {
@Test
public void testElements() throws IOException {
addClassForScanning(ComplexAnnotations.class);
Map<String, Annotated<Field>> fields = new HashMap<String, Annotated<Field>>();
for (Annotated<Field> annotated : finder().withAnnotations().findAnnotatedFields(
final Map<String, Annotated<Field>> fields = new HashMap<String, Annotated<Field>>();
for (final Annotated<Field> annotated : finder().withAnnotations().findAnnotatedFields(
ComplexAnnotations.TestAnnotation.class)) {
fields.put(annotated.get().getName(), annotated);
}
assertEquals(2, fields.size());

TestAnnotation anno1 = fields.get("dummy1").getAnnotation(TestAnnotation.class);
final TestAnnotation anno1 = fields.get("dummy1").getAnnotation(TestAnnotation.class);

assertFalse(anno1.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, anno1.booleanValues()));
@@ -97,7 +97,7 @@ public void testElements() throws IOException {
assertEquals(0L, anno1.longValue());
assertArrayEquals(new long[] { 0L }, anno1.longValues());

NestAnnotation nest1 = anno1.nest();
final NestAnnotation nest1 = anno1.nest();
assertFalse(nest1.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, nest1.booleanValues()));
assertEquals((byte) 0, nest1.byteValue());
@@ -122,7 +122,7 @@ public void testElements() throws IOException {
assertArrayEquals(new Class[] { Object.class }, nest1.types());

assertEquals(1, anno1.nests().length);
NestAnnotation nest1_0 = anno1.nests()[0];
final NestAnnotation nest1_0 = anno1.nests()[0];
assertFalse(nest1_0.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, nest1_0.booleanValues()));
assertEquals((byte) 0, nest1_0.byteValue());
@@ -155,7 +155,7 @@ public void testElements() throws IOException {
assertEquals(Object.class, anno1.type());
assertArrayEquals(new Class[] { Object.class }, anno1.types());

TestAnnotation anno2 = fields.get("dummy2").getAnnotation(TestAnnotation.class);
final TestAnnotation anno2 = fields.get("dummy2").getAnnotation(TestAnnotation.class);
assertFalse(anno2.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, anno2.booleanValues()));
assertEquals((byte) 0, anno2.byteValue());
@@ -171,7 +171,7 @@ public void testElements() throws IOException {
assertEquals(0L, anno2.longValue());
assertArrayEquals(new long[] { 0L }, anno2.longValues());

NestAnnotation nest2 = anno2.nest();
final NestAnnotation nest2 = anno2.nest();
assertFalse(nest2.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, nest2.booleanValues()));
assertEquals((byte) 0, nest2.byteValue());
@@ -196,7 +196,7 @@ public void testElements() throws IOException {
assertArrayEquals(new Class[] { Object.class }, nest2.types());

assertEquals(2, anno2.nests().length);
NestAnnotation nest2_0 = anno2.nests()[0];
final NestAnnotation nest2_0 = anno2.nests()[0];
assertFalse(nest2_0.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, nest2_0.booleanValues()));
assertEquals((byte) 0, nest2_0.byteValue());
@@ -220,7 +220,7 @@ public void testElements() throws IOException {
assertEquals(Object[].class, nest2_0.type());
assertArrayEquals(new Class[] { Object[].class }, nest2_0.types());

NestAnnotation nest2_1 = anno2.nests()[1];
final NestAnnotation nest2_1 = anno2.nests()[1];
assertFalse(nest2_1.booleanValue());
assertTrue(Arrays.equals(new boolean[] { false }, nest2_1.booleanValues()));
assertEquals((byte) 0, nest2_1.byteValue());
@@ -257,9 +257,9 @@ public void testElements() throws IOException {
@Test
public void testObjectMethods() throws IOException {
addClassForScanning(ComplexAnnotations.class);
for (Annotated<Field> annotated : finder().withAnnotations().findAnnotatedFields(
for (final Annotated<Field> annotated : finder().withAnnotations().findAnnotatedFields(
ComplexAnnotations.TestAnnotation.class)) {
TestAnnotation anno = annotated.getAnnotation(TestAnnotation.class);
final TestAnnotation anno = annotated.getAnnotation(TestAnnotation.class);
assertFalse(anno.toString().isEmpty());
assertFalse(anno.hashCode() == 0);
assertTrue(anno.equals(anno));
@@ -274,14 +274,14 @@ public void testFindAssignableTypes() throws IOException {
addClassForScanning(TestBeanWithMethodAnnotation.class);

final Set<Class<?>> implementors = new HashSet<Class<?>>();
for (Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(TestBeanInterface.class)) {
for (final Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(TestBeanInterface.class)) {
implementors.add(annotated.get());
}
assertEquals(1, implementors.size());
assertTrue(implementors.contains(TestBeanWithClassAnnotation.class));

final Set<Class<?>> subclasses = new HashSet<Class<?>>();
for (Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(AbstractTestBean.class)) {
for (final Annotated<Class<?>> annotated : finder().withAnnotations().findAssignableTypes(AbstractTestBean.class)) {
subclasses.add(annotated.get());
}
assertEquals(2, subclasses.size());
@@ -296,18 +296,18 @@ public void testFindAllTypes() throws IOException {
addClassForScanning(TestBeanWithClassAnnotation.class);
addClassForScanning(TestBeanWithMethodAnnotation.class);

List<Annotated<Class<?>>> allClasses = finder().withAnnotations().getAllClasses();
final List<Annotated<Class<?>>> allClasses = finder().withAnnotations().getAllClasses();
assertThat(extract(allClasses), Matchers.<Class<?>> containsInAnyOrder(TestBeanInterface.class,
AbstractTestBean.class, TestBeanWithClassAnnotation.class, TestBeanWithMethodAnnotation.class));
}

private List<Class<?>> extract(List<Annotated<Class<?>>> input) {
private List<Class<?>> extract(final List<Annotated<Class<?>>> input) {
Validate.noNullElements(input);
if (input.isEmpty()) {
return Collections.emptyList();
}
final List<Class<?>> result = new ArrayList<Class<?>>(input.size());
for (Annotated<Class<?>> c : input) {
for (final Annotated<Class<?>> c : input) {
result.add(c.get());
}
return result;
@@ -42,7 +42,7 @@ public void testWeaveVisiting() throws Exception {
final Properties config = new Properties();
config.put("configKey", "configValue");

WeaveProcessor wp = new WeaveProcessor(getClassPathEntries(), getTargetFolder(), config);
final WeaveProcessor wp = new WeaveProcessor(getClassPathEntries(), getTargetFolder(), config);

TestWeaver.wovenClasses.clear();
TestWeaver.wovenMethods.clear();
@@ -52,34 +52,34 @@ public void cleanup() {
*
* @param clazz
*/
protected void addClassForScanning(Class<?> clazz) throws IOException {
String clazzDirName = clazz.getPackage().getName().replace(".", "/");
File targetDirFile = new File(getTargetFolder(), clazzDirName);
protected void addClassForScanning(final Class<?> clazz) throws IOException {
final String clazzDirName = clazz.getPackage().getName().replace(".", "/");
final File targetDirFile = new File(getTargetFolder(), clazzDirName);
targetDirFile.mkdirs();

String fileName = baseName(clazz) + ".class";
String clazzFileName = clazzDirName + "/" + fileName;
URL clazzUrl = getClass().getClassLoader().getResource(clazzFileName);
File targetClazzFile = new File(targetDirFile, fileName);
final String fileName = baseName(clazz) + ".class";
final String clazzFileName = clazzDirName + "/" + fileName;
final URL clazzUrl = getClass().getClassLoader().getResource(clazzFileName);
final File targetClazzFile = new File(targetDirFile, fileName);

byte[] buffer = new byte[0xFFFF];
final byte[] buffer = new byte[0xFFFF];

FileOutputStream fos = new FileOutputStream(targetClazzFile);
final FileOutputStream fos = new FileOutputStream(targetClazzFile);

InputStream inputStream = clazzUrl.openStream();
final InputStream inputStream = clazzUrl.openStream();
int len;
while ((len = inputStream.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.flush();
fos.close();

for (Class<?> inner : clazz.getClasses()) {
for (final Class<?> inner : clazz.getClasses()) {
addClassForScanning(inner);
}
}

private String baseName(Class<?> clazz) {
private String baseName(final Class<?> clazz) {
if (clazz.getDeclaringClass() == null) {
return clazz.getSimpleName();
}
@@ -110,7 +110,7 @@ protected List<String> getClassPathEntries() {
classPathEntries = new ArrayList<String>(1);
try {
classPathEntries.add(getTargetFolder().getCanonicalPath());
} catch (IOException ioe) {
} catch (final IOException ioe) {
throw new RuntimeException(ioe);
}
}
@@ -31,14 +31,14 @@
public class TestCleaner implements Cleaner {

@Override
public boolean clean(WeaveEnvironment environment, Scanner scanner) {
public boolean clean(final WeaveEnvironment environment, final Scanner scanner) {
boolean result = false;

final ScanRequest scanRequest =
new ScanRequest().add(WeaveInterest.of(TestAnnotation.class, ElementType.TYPE)).add(
WeaveInterest.of(TestAnnotation.class, ElementType.METHOD));

for (WeavableClass<?> weavableClass : scanner.scan(scanRequest).getClasses()) {
for (final WeavableClass<?> weavableClass : scanner.scan(scanRequest).getClasses()) {
if (environment.deleteClassfile(weavableClass.getTarget())) {
result = true;
} else {
@@ -46,11 +46,11 @@ public class TestWeaver implements Weaver {
public static List<Class<?>> subclasses = new ArrayList<Class<?>>();

@Override
public boolean process(WeaveEnvironment environment, Scanner scanner) {
public boolean process(final WeaveEnvironment environment, final Scanner scanner) {
Assert.assertNotNull(environment.config);
Assert.assertEquals(1, environment.config.size());

String configValue = environment.config.getProperty("configKey");
final String configValue = environment.config.getProperty("configKey");

Assert.assertEquals("configValue", configValue);
boolean result = false;
@@ -62,22 +62,22 @@ public boolean process(WeaveEnvironment environment, Scanner scanner) {

final ScanResult scanResult = scanner.scan(scanRequest);

for (WeavableClass<?> weavableClass : scanResult.getClasses().with(TestAnnotation.class)) {
for (final WeavableClass<?> weavableClass : scanResult.getClasses().with(TestAnnotation.class)) {
if (wovenClasses.add(weavableClass.getTarget())) {
result = true;
}
}
for (WeavableMethod<?> weavableMethod : scanResult.getMethods().with(TestAnnotation.class)) {
for (final WeavableMethod<?> weavableMethod : scanResult.getMethods().with(TestAnnotation.class)) {
if (wovenMethods.add(weavableMethod.getTarget())) {
result = true;
}
}
for (WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(TestBeanInterface.class)) {
for (final WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(TestBeanInterface.class)) {
if (implementors.add(weavableClass.getTarget())) {
result = true;
}
}
for (WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(AbstractTestBean.class)) {
for (final WeavableClass<?> weavableClass : scanResult.getClassesAssignableTo(AbstractTestBean.class)) {
if (subclasses.add(weavableClass.getTarget())) {
result = true;
}
@@ -76,7 +76,7 @@ public class Z implements FauxWeaveProvider {
public class Monkeywrench implements FauxWeaveProvider {
}

private FauxWeaveProvider a = new A(), b = new B(), c = new C(), w = new W(), x = new X(), y = new Y(), z = new Z(),
private final FauxWeaveProvider a = new A(), b = new B(), c = new C(), w = new W(), x = new X(), y = new Y(), z = new Z(),
monkeywrench = new Monkeywrench();

@Test

0 comments on commit a49d5b9

Please sign in to comment.