Update style to better resemble rest of the project

This commit is contained in:
Pim van der Loos committed 2023-04-18 18:07:53 +02:00
1 parent 0129a0d18b
commit dfddf8f52c
8 files changed
+35 -71

No files matched your search

@@ -40,8 +40,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
public class HandleLocked extends EclipseAnnotationHandler<Locked> {
private static final String ANNOTATION_NAME = "@Locked";
private static final char[][] LOCK_CLASS = new char[][] { TypeConstants.JAVA, TypeConstants.UTIL,
"concurrent".toCharArray(), "locks".toCharArray(),
"ReentrantLock".toCharArray() };
"concurrent".toCharArray(), "locks".toCharArray(), "ReentrantLock".toCharArray() };
@Override public void handle(AnnotationValues<Locked> annotation, Annotation source, EclipseNode annotationNode) {
String annotationValue = annotation.getInstance().value();
@@ -41,8 +41,7 @@ public class HandleLockedRead extends EclipseAnnotationHandler<Locked.Read> {
private static final char[] LOCK_METHOD = "readLock".toCharArray();
private static final String ANNOTATION_NAME = "@Locked.Read";
private static final char[][] LOCK_CLASS = new char[][] { TypeConstants.JAVA, TypeConstants.UTIL,
"concurrent".toCharArray(), "locks".toCharArray(),
"ReentrantReadWriteLock".toCharArray() };
"concurrent".toCharArray(), "locks".toCharArray(), "ReentrantReadWriteLock".toCharArray() };
@Override public void handle(AnnotationValues<Locked.Read> annotation, Annotation source, EclipseNode annotationNode) {
String annotationValue = annotation.getInstance().value();
@@ -80,8 +80,7 @@ public final class HandleLockedUtil {
createLockField(annotationValue, annotationNode, lockClass, new boolean[] { method.isStatic() }, false);
}
private static char[] createLockField(String name, EclipseNode annotationNode, char[][] lockClass,
boolean[] isStatic, boolean reportErrors) {
private static char[] createLockField(String name, EclipseNode annotationNode, char[][] lockClass, boolean[] isStatic, boolean reportErrors) {
char[] lockName = name.toCharArray();
Annotation source = (Annotation) annotationNode.get();
@@ -109,9 +108,8 @@ public final class HandleLockedUtil {
isStatic[0] = st;
if (exists == MemberExistsResult.EXISTS_BY_LOMBOK && !typeReferenceNameEquals(lockType, def.type)) {
annotationNode.addError("Expected field " + charArrToString(lockName) + " to be of type " +
lockType + " but got type " + def.type + "!" +
" Did you mix @Locked with @Locked.Read/Write on the same generated field?");
annotationNode.addError("Expected field " + new String(lockName) + " to be of type " + lockType +
" but got type " + def.type + "! Did you mix @Locked with @Locked.Read/Write on the same generated field?");
return null;
}
break;
@@ -136,11 +134,10 @@ public final class HandleLockedUtil {
}
/**
* See {@link #handle(String, Annotation, EclipseNode, String, char[][], char[])} for
* See {@link #handle(String, Annotation, EclipseNode, String, char[][], char[])} for
* {@code lockableMethodName = null}.
*/
public static void handle(String annotationValue, Annotation ast, EclipseNode annotationNode,
String annotationName, char[][] lockClass) {
public static void handle(String annotationValue, Annotation ast, EclipseNode annotationNode, String annotationName, char[][] lockClass) {
handle(annotationValue, ast, annotationNode, annotationName, lockClass, null);
}
@@ -163,7 +160,7 @@ public final class HandleLockedUtil {
* itself can be locked/unlocked.
*/
public static void handle(String annotationValue, Annotation source, EclipseNode annotationNode,
String annotationName, char[][] lockClass, char[] lockableMethodName) {
String annotationName, char[][] lockClass, char[] lockableMethodName) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOCKED_FLAG_USAGE, annotationName);
int p1 = source.sourceStart -1;
@@ -171,8 +168,7 @@ public final class HandleLockedUtil {
long pos = (((long) p1) << 32) | p2;
EclipseNode methodNode = annotationNode.up();
if (methodNode == null || methodNode.getKind() != AST.Kind.METHOD ||
!(methodNode.get() instanceof MethodDeclaration)) {
if (methodNode == null || methodNode.getKind() != AST.Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) {
annotationNode.addError(annotationName + " is legal only on methods.");
return;
}
@@ -202,10 +198,8 @@ public final class HandleLockedUtil {
block.sourceEnd = method.bodyEnd;
block.sourceStart = method.bodyStart;
Statement acquireLock = getLockingStatement(source, typeNode, LOCK_METHOD, lockName,
lockableMethodName, isStatic[0], p1, p2, pos);
Statement unLock = getLockingStatement(source, typeNode, UNLOCK_METHOD, lockName,
lockableMethodName, isStatic[0], p1, p2, pos);
Statement acquireLock = getLockingStatement(source, typeNode, LOCK_METHOD, lockName, lockableMethodName, isStatic[0], p1, p2, pos);
Statement unLock = getLockingStatement(source, typeNode, UNLOCK_METHOD, lockName, lockableMethodName, isStatic[0], p1, p2, pos);
TryStatement tryStatement = new TryStatement();
tryStatement.tryBlock = block;
@@ -222,8 +216,7 @@ public final class HandleLockedUtil {
}
private static Statement getLockingStatement(ASTNode source, EclipseNode typeNode, char[] lockMethod,
char[] lockableObjectName, char[] lockableMethodName, boolean isStatic,
int p1, int p2, long pos) {
char[] lockableObjectName, char[] lockableMethodName, boolean isStatic, int p1, int p2, long pos) {
MessageSend lockStat = setGeneratedBy(new MessageSend(), source);
lockStat.receiver = getLockable(source, typeNode, lockableObjectName, lockableMethodName, isStatic, p1, p2, pos);
lockStat.selector = lockMethod;
@@ -234,7 +227,7 @@ public final class HandleLockedUtil {
}
private static Expression getLockable(ASTNode source, EclipseNode typeNode, char[] lockName,
char[] lockableMethodName, boolean isStatic, int p1, int p2, long pos) {
char[] lockableMethodName, boolean isStatic, int p1, int p2, long pos) {
Reference lockVariable;
if (isStatic) {
char[][] n = getQualifiedInnerName(typeNode, lockName);
@@ -261,10 +254,4 @@ public final class HandleLockedUtil {
}
return setGeneratedBy(lockable, source);
}
private static String charArrToString(char[] arr) {
String str = "";
for (int idx = 0; idx < arr.length; ++idx) str += arr[idx];
return str;
}
}
@@ -41,8 +41,7 @@ public class HandleLockedWrite extends EclipseAnnotationHandler<Locked.Write> {
private static final char[] LOCK_METHOD = "writeLock".toCharArray();
private static final String ANNOTATION_NAME = "@Locked.Write";
private static final char[][] LOCK_CLASS = new char[][] { TypeConstants.JAVA, TypeConstants.UTIL,
"concurrent".toCharArray(), "locks".toCharArray(),
"ReentrantReadWriteLock".toCharArray() };
"concurrent".toCharArray(), "locks".toCharArray(), "ReentrantReadWriteLock".toCharArray() };
@Override public void handle(AnnotationValues<Locked.Write> annotation, Annotation source, EclipseNode annotationNode) {
String annotationValue = annotation.getInstance().value();
+1 -1
View File
@@ -17,7 +17,7 @@ import java.util.concurrent.locks.ReadWriteLock;
* Because {@link Locked} uses a different type of lock from {@link Locked.Read} and {@link Locked.Write}, using both in
* the same class using the default names will result in a compile time error.
* <p>
* Complete documentation is found at <a href="https://projectlombok.org/features/Locked">the project lombok features page for &#64;Locked</a>.
* Complete documentation is found at <a href="https://projectlombok.org/features/experimental/Locked">the project lombok features page for &#64;Locked</a>.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
@@ -38,12 +38,10 @@ import static com.sun.tools.javac.tree.JCTree.*;
public class HandleLockedRead extends JavacAnnotationHandler<Locked.Read> {
private static final String LOCK_METHOD = "readLock";
private static final String ANNOTATION_NAME = "@Locked.Read";
private static final String[] LOCK_CLASS = new String[]{"java", "util", "concurrent", "locks",
"ReentrantReadWriteLock"};
private static final String[] LOCK_CLASS = new String[]{"java", "util", "concurrent", "locks", "ReentrantReadWriteLock"};
@Override public void handle(AnnotationValues<Locked.Read> annotation, JCAnnotation ast, JavacNode annotationNode) {
String annotationValue = annotation.getInstance().value();
HandleLockedUtil.handle(annotationValue, ast, annotationNode, Locked.Read.class,
ANNOTATION_NAME, LOCK_CLASS, LOCK_METHOD);
HandleLockedUtil.handle(annotationValue, ast, annotationNode, Locked.Read.class, ANNOTATION_NAME, LOCK_CLASS, LOCK_METHOD);
}
}
@@ -53,8 +53,7 @@ public final class HandleLockedUtil {
* {@code lockableMethodName = null}.
*/
public static <T extends Annotation> void handle(String annotationValue, JCTree.JCAnnotation ast,
JavacNode annotationNode, Class<T> annotationClass,
String annotationName, String[] lockClass) {
JavacNode annotationNode, Class<T> annotationClass, String annotationName, String[] lockClass) {
handle(annotationValue, ast, annotationNode, annotationClass, annotationName, lockClass, null);
}
@@ -81,18 +80,15 @@ public final class HandleLockedUtil {
* itself can be locked/unlocked.
* @param <T> The annotation type.
*/
public static <T extends Annotation> void handle(String annotationValue, JCTree.JCAnnotation ast,
JavacNode annotationNode, Class<T> annotationClass,
String annotationName, String[] lockClass,
String lockableMethodName) {
public static <T extends Annotation> void handle(String annotationValue, JCTree.JCAnnotation ast, JavacNode annotationNode,
Class<T> annotationClass, String annotationName, String[] lockClass, String lockableMethodName) {
handleFlagUsage(annotationNode, ConfigurationKeys.LOCKED_FLAG_USAGE, annotationName);
if (inNetbeansEditor(annotationNode)) return;
deleteAnnotationIfNeccessary(annotationNode, annotationClass);
JavacNode methodNode = annotationNode.up();
if (methodNode == null || methodNode.getKind() != AST.Kind.METHOD ||
!(methodNode.get() instanceof JCMethodDecl)) {
if (methodNode == null || methodNode.getKind() != AST.Kind.METHOD || !(methodNode.get() instanceof JCMethodDecl)) {
annotationNode.addError(annotationName + " is legal only on methods.");
return;
}
@@ -127,22 +123,18 @@ public final class HandleLockedUtil {
if (def instanceof JCVariableDecl) {
if (((JCVariableDecl) def).name.contentEquals(lockName)) {
JCVariableDecl varDeclDef = (JCVariableDecl) def;
exists = getGeneratedBy(varDeclDef) == null ? MemberExistsResult.EXISTS_BY_USER :
MemberExistsResult.EXISTS_BY_LOMBOK;
exists = getGeneratedBy(varDeclDef) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
boolean st = ((varDeclDef.mods.flags) & Flags.STATIC) != 0;
if (isStatic[0] != st && exists == MemberExistsResult.EXISTS_BY_LOMBOK) {
annotationNode.addError("The generated field " + lockName +
" does not match the static status of this method");
annotationNode.addError("The generated field " + lockName + " does not match the static status of this method");
return;
}
isStatic[0] = st;
if (exists == MemberExistsResult.EXISTS_BY_LOMBOK &&
!lockType.toString().equals(varDeclDef.vartype.toString())) {
annotationNode.addError("Expected field " + lockName + " to be of type " + lockType +
" but got type " + varDeclDef.vartype + "!" +
" Did you mix @Locked with @Locked.Read/Write on the same generated field?");
if (exists == MemberExistsResult.EXISTS_BY_LOMBOK && !lockType.toString().equals(varDeclDef.vartype.toString())) {
annotationNode.addError("Expected field " + lockName + " to be of type " + lockType + " but got type " +
varDeclDef.vartype + "! Did you mix @Locked with @Locked.Read/Write on the same generated field?");
return;
}
}
@@ -164,8 +156,7 @@ public final class HandleLockedUtil {
JCExpression lockNode;
if (isStatic[0]) {
lockNode = namePlusTypeParamsToTypeReference(maker, typeNode, methodNode.toName(lockName), false,
List.<JCTypeParameter>nil());
lockNode = namePlusTypeParamsToTypeReference(maker, typeNode, methodNode.toName(lockName), false, List.<JCTypeParameter>nil());
} else {
lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
}
@@ -176,23 +167,16 @@ public final class HandleLockedUtil {
if (lockableMethodName == null) {
lockable = lockNode;
} else {
lockable = maker.Apply(NIL_EXPRESSION,
maker.Select(lockNode, methodNode.toName(lockableMethodName)),
NIL_EXPRESSION);
lockable = maker.Apply(NIL_EXPRESSION, maker.Select(lockNode, methodNode.toName(lockableMethodName)), NIL_EXPRESSION);
}
JCExpressionStatement acquireLock =
maker.Exec(maker.Apply(NIL_EXPRESSION, maker.Select(lockable, typeNode.toName("lock")), NIL_EXPRESSION));
JCExpressionStatement releaseLock =
maker.Exec(maker.Apply(NIL_EXPRESSION, maker.Select(lockable, typeNode.toName("unlock")), NIL_EXPRESSION));
JCExpressionStatement acquireLock = maker.Exec(maker.Apply(NIL_EXPRESSION, maker.Select(lockable, typeNode.toName("lock")), NIL_EXPRESSION));
JCExpressionStatement releaseLock = maker.Exec(maker.Apply(NIL_EXPRESSION, maker.Select(lockable, typeNode.toName("unlock")), NIL_EXPRESSION));
JCTry tryBlock = recursiveSetGeneratedBy(maker.Try(maker.Block(0L, method.body.stats),
List.<JCCatch>nil(),
maker.Block(0L, List.<JCStatement>of(releaseLock))),
annotationNode);
JCTry tryBlock = recursiveSetGeneratedBy(maker.Try(maker.Block(0L, method.body.stats), List.<JCCatch>nil(),
maker.Block(0L, List.<JCStatement>of(releaseLock))), annotationNode);
method.body.stats = List.<JCStatement>of(tryBlock)
.prepend(recursiveSetGeneratedBy(acquireLock, annotationNode));
method.body.stats = List.<JCStatement>of(tryBlock).prepend(recursiveSetGeneratedBy(acquireLock, annotationNode));
methodNode.rebuild();
}
}
@@ -38,12 +38,10 @@ import static com.sun.tools.javac.tree.JCTree.*;
public class HandleLockedWrite extends JavacAnnotationHandler<Locked.Write> {
private static final String LOCK_METHOD = "writeLock";
private static final String ANNOTATION_NAME = "@Locked.Write";
private static final String[] LOCK_CLASS = new String[]{"java", "util", "concurrent", "locks",
"ReentrantReadWriteLock"};
private static final String[] LOCK_CLASS = new String[]{"java", "util", "concurrent", "locks", "ReentrantReadWriteLock"};
@Override public void handle(AnnotationValues<Locked.Write> annotation, JCAnnotation ast, JavacNode annotationNode) {
String annotationValue = annotation.getInstance().value();
HandleLockedUtil.handle(annotationValue, ast, annotationNode, Locked.Write.class,
ANNOTATION_NAME, LOCK_CLASS, LOCK_METHOD);
HandleLockedUtil.handle(annotationValue, ast, annotationNode, Locked.Write.class, ANNOTATION_NAME, LOCK_CLASS, LOCK_METHOD);
}
}