aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2020-06-25 23:01:06 +0200
committerRoel Spilker <r.spilker@gmail.com>2020-06-25 23:01:06 +0200
commite75517d561790bf8ee01763a1c75e091d03132e9 (patch)
tree6d351aa8988156311a1595bf0069c212a546c61c
parent3ffef5d23be17e9bffca30936d43bca852feaa93 (diff)
downloadlombok-e75517d561790bf8ee01763a1c75e091d03132e9.tar.gz
lombok-e75517d561790bf8ee01763a1c75e091d03132e9.tar.bz2
lombok-e75517d561790bf8ee01763a1c75e091d03132e9.zip
Avoid class.getSimpleName except in static initializers or error messages
-rw-r--r--src/core/lombok/core/handlers/InclusionExclusionUtils.java9
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleConstructor.java10
-rw-r--r--src/core/lombok/javac/handlers/HandleConstructor.java9
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java24
-rw-r--r--src/utils/lombok/javac/JavacTreeMaker.java5
-rw-r--r--src/utils/lombok/javac/java8/CommentCollectingTokenizer.java4
6 files changed, 31 insertions, 30 deletions
diff --git a/src/core/lombok/core/handlers/InclusionExclusionUtils.java b/src/core/lombok/core/handlers/InclusionExclusionUtils.java
index e785db3f..0aa6c47b 100644
--- a/src/core/lombok/core/handlers/InclusionExclusionUtils.java
+++ b/src/core/lombok/core/handlers/InclusionExclusionUtils.java
@@ -112,7 +112,7 @@ public class InclusionExclusionUtils {
return name;
}
- public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode, boolean includeTransient) {
+ private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> inclType, String replaceName, Class<? extends Annotation> exclType, LombokNode<A, L, N> typeNode, AnnotationValues<?> annotation, LombokNode<A, L, N> annotationNode, boolean includeTransient) {
List<String> oldExcludes = (annotation != null && annotation.isExplicit("exclude")) ? annotation.getAsStringList("exclude") : null;
List<String> oldIncludes = (annotation != null && annotation.isExplicit("of")) ? annotation.getAsStringList("of") : null;
@@ -124,9 +124,6 @@ public class InclusionExclusionUtils {
if (typeNode == null || typeNode.getKind() != Kind.TYPE) return null;
checkForBogusFieldNames(typeNode, annotation, oldExcludes, oldIncludes);
- String inclTypeName = innerAnnName(inclType);
- String exclTypeName = innerAnnName(exclType);
-
if (oldExcludes != null && oldIncludes != null) {
oldExcludes = null;
if (annotation != null) annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
@@ -140,7 +137,7 @@ public class InclusionExclusionUtils {
if (markExclude || markInclude != null) memberAnnotationMode = true;
if (markInclude != null && markExclude) {
- child.addError("@" + exclTypeName + " and @" + inclTypeName + " are mutually exclusive; the @Include annotation will be ignored");
+ child.addError("@" + innerAnnName(exclType) + " and @" + innerAnnName(inclType) + " are mutually exclusive; the @Include annotation will be ignored");
markInclude = null;
}
@@ -163,7 +160,7 @@ public class InclusionExclusionUtils {
I inc = markInclude.getInstance();
if (child.getKind() == Kind.METHOD) {
if (child.countMethodParameters() > 0) {
- child.addError("Methods included with @" + inclTypeName + " must have no arguments; it will not be included");
+ child.addError("Methods included with @" + innerAnnName(inclType) + " must have no arguments; it will not be included");
continue;
}
String n = replaceName != null ? markInclude.getAsString(replaceName) : "";
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 129fa7c0..06c9ecd9 100755
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -84,13 +84,14 @@ import org.mangosdk.spi.ProviderFor;
public class HandleConstructor {
@ProviderFor(EclipseAnnotationHandler.class)
public static class HandleNoArgsConstructor extends EclipseAnnotationHandler<NoArgsConstructor> {
+ private static final String NAME = NoArgsConstructor.class.getSimpleName();
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.NO_ARGS_CONSTRUCTOR_FLAG_USAGE, "@NoArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
EclipseNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
NoArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
String staticName = ann.staticName();
@@ -106,13 +107,14 @@ public class HandleConstructor {
@ProviderFor(EclipseAnnotationHandler.class)
public static class HandleRequiredArgsConstructor extends EclipseAnnotationHandler<RequiredArgsConstructor> {
+ private static final String NAME = RequiredArgsConstructor.class.getSimpleName();
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.REQUIRED_ARGS_CONSTRUCTOR_FLAG_USAGE, "@RequiredArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
EclipseNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
RequiredArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
if (level == AccessLevel.NONE) return;
@@ -166,13 +168,15 @@ public class HandleConstructor {
@ProviderFor(EclipseAnnotationHandler.class)
public static class HandleAllArgsConstructor extends EclipseAnnotationHandler<AllArgsConstructor> {
+ private static final String NAME = AllArgsConstructor.class.getSimpleName();
+
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<AllArgsConstructor> annotation, Annotation ast, EclipseNode annotationNode) {
handleFlagUsage(annotationNode, ConfigurationKeys.ALL_ARGS_CONSTRUCTOR_FLAG_USAGE, "@AllArgsConstructor", ConfigurationKeys.ANY_CONSTRUCTOR_FLAG_USAGE, "any @xArgsConstructor");
EclipseNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
AllArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
if (level == AccessLevel.NONE) return;
diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java
index e0abb53b..2a683767 100644
--- a/src/core/lombok/javac/handlers/HandleConstructor.java
+++ b/src/core/lombok/javac/handlers/HandleConstructor.java
@@ -68,6 +68,7 @@ import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult;
public class HandleConstructor {
@ProviderFor(JavacAnnotationHandler.class)
public static class HandleNoArgsConstructor extends JavacAnnotationHandler<NoArgsConstructor> {
+ private static final String NAME = NoArgsConstructor.class.getSimpleName();
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<NoArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
@@ -76,7 +77,7 @@ public class HandleConstructor {
deleteAnnotationIfNeccessary(annotationNode, NoArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, NoArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@NoArgsConstructor(onConstructor", annotationNode);
NoArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
@@ -89,6 +90,7 @@ public class HandleConstructor {
@ProviderFor(JavacAnnotationHandler.class)
public static class HandleRequiredArgsConstructor extends JavacAnnotationHandler<RequiredArgsConstructor> {
+ private static final String NAME = RequiredArgsConstructor.class.getSimpleName();
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<RequiredArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
@@ -97,7 +99,7 @@ public class HandleConstructor {
deleteAnnotationIfNeccessary(annotationNode, RequiredArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, RequiredArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@RequiredArgsConstructor(onConstructor", annotationNode);
RequiredArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
@@ -138,6 +140,7 @@ public class HandleConstructor {
@ProviderFor(JavacAnnotationHandler.class)
public static class HandleAllArgsConstructor extends JavacAnnotationHandler<AllArgsConstructor> {
+ private static final String NAME = AllArgsConstructor.class.getSimpleName();
private HandleConstructor handleConstructor = new HandleConstructor();
@Override public void handle(AnnotationValues<AllArgsConstructor> annotation, JCAnnotation ast, JavacNode annotationNode) {
@@ -146,7 +149,7 @@ public class HandleConstructor {
deleteAnnotationIfNeccessary(annotationNode, AllArgsConstructor.class);
deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel");
JavacNode typeNode = annotationNode.up();
- if (!checkLegality(typeNode, annotationNode, AllArgsConstructor.class.getSimpleName())) return;
+ if (!checkLegality(typeNode, annotationNode, NAME)) return;
List<JCAnnotation> onConstructor = unboxAndRemoveAnnotationParameter(ast, "onConstructor", "@AllArgsConstructor(onConstructor", annotationNode);
AllArgsConstructor ann = annotation.getInstance();
AccessLevel level = ann.access();
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 7eb8410b..238dd379 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1323,7 +1323,7 @@ public class PrettyPrinter extends JCTree.Visitor {
print(";");
needsNewLine = true;
needsAlign = true;
- } else if (tree.stats.head.getClass().getSimpleName().equals("JCYield")) {
+ } else if (tree.stats.head.getClass().getName().endsWith("$JCYield")) {
print((JCExpression) readObject(tree.stats.head, "value", null));
print(";");
needsNewLine = true;
@@ -1600,25 +1600,25 @@ public class PrettyPrinter extends JCTree.Visitor {
}
@Override public void visitTree(JCTree tree) {
- String simpleName = tree.getClass().getSimpleName();
- if ("JCTypeUnion".equals(simpleName)) {
+ String className = tree.getClass().getName();
+ if (className.endsWith("$JCTypeUnion")) {
List<JCExpression> types = readObject(tree, "alternatives", List.<JCExpression>nil());
print(types, " | ");
- } else if ("JCTypeIntersection".equals(simpleName)) {
+ } else if (className.endsWith("$JCTypeIntersection")) {
print(readObject(tree, "bounds", List.<JCExpression>nil()), " & ");
- } else if ("JCMemberReference".equals(simpleName)) {
+ } else if (className.endsWith("$JCMemberReference")) {
printMemberReference0(tree);
- } else if ("JCLambda".equals(simpleName)) {
+ } else if (className.endsWith("$JCLambda")) {
printLambda0(tree);
- } else if ("JCAnnotatedType".equals(simpleName)) {
+ } else if (className.endsWith("$JCAnnotatedType")) {
printAnnotatedType0(tree);
- } else if ("JCPackageDecl".equals(simpleName)) {
+ } else if (className.endsWith("$JCPackageDecl")) {
// Starting with JDK9, this is inside the import list, but we've already printed it. Just ignore it.
- } else if ("JCSwitchExpression".equals(simpleName)) { // Introduced as preview feature in JDK12
+ } else if (className.endsWith(".JCSwitchExpression")) { // Introduced as preview feature in JDK12
printSwitchExpression(tree);
- } else if ("JCYield".equals(simpleName)) { // Introduced as preview feature in JDK13, part of switch expressions.
+ } else if (className.endsWith("$JCYield")) { // Introduced as preview feature in JDK13, part of switch expressions.
printYieldExpression(tree);
- } else if ("JCBindingPattern".equals(simpleName)) { // Introduced as preview in JDK14
+ } else if (className.endsWith("$JCBindingPattern")) { // Introduced as preview in JDK14
printBindingPattern(tree);
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
@@ -1638,7 +1638,7 @@ public class PrettyPrinter extends JCTree.Visitor {
if (o == null) return false;
if (jcAnnotatedTypeInit) return jcAnnotatedTypeClass == o.getClass();
Class<?> c = o.getClass();
- if (c.getSimpleName().equals("JCAnnotatedType")) {
+ if (c.getName().endsWith("$JCAnnotatedType")) {
jcAnnotatedTypeClass = c;
jcAnnotatedTypeInit = true;
return true;
diff --git a/src/utils/lombok/javac/JavacTreeMaker.java b/src/utils/lombok/javac/JavacTreeMaker.java
index 20f4b66d..15a11151 100644
--- a/src/utils/lombok/javac/JavacTreeMaker.java
+++ b/src/utils/lombok/javac/JavacTreeMaker.java
@@ -343,10 +343,7 @@ public class JavacTreeMaker {
Method method = getFromCache(m);
try {
if (m.returnType.isPrimitive()) {
- Object res = method.invoke(owner, args);
- String sn = res.getClass().getSimpleName().toLowerCase();
- if (!sn.startsWith(m.returnType.getSimpleName())) throw new ClassCastException(res.getClass() + " to " + m.returnType);
- return (J) res;
+ return (J) method.invoke(owner, args);
}
return m.returnType.cast(method.invoke(owner, args));
} catch (InvocationTargetException e) {
diff --git a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
index 08477e61..d7b1d569 100644
--- a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
+++ b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2019 The Project Lombok Authors.
+ * Copyright (C) 2013-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -59,7 +59,7 @@ class CommentCollectingTokenizer extends JavaTokenizer {
@Override public Token readToken() {
Token token = super.readToken();
prevEndPosition = pos();
- if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getSimpleName().equals("StringToken")) {
+ if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getName().endsWith("$StringToken")) {
char[] start = reader.getRawCharacters(token.pos, token.pos + 3);
if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.add(token.pos);
}