aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/lombok')
-rw-r--r--src/utils/lombok/eclipse/Eclipse.java20
-rw-r--r--src/utils/lombok/eclipse/Java14Bits.java11
-rw-r--r--src/utils/lombok/javac/Java14Flags.java26
-rw-r--r--src/utils/lombok/javac/Javac.java25
-rw-r--r--src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java27
-rw-r--r--src/utils/lombok/javac/java8/CommentCollectingTokenizer.java50
-rw-r--r--src/utils/lombok/permit/dummy/Child.java9
-rw-r--r--src/utils/lombok/permit/dummy/GrandChild.java19
-rw-r--r--src/utils/lombok/permit/dummy/Parent.java12
-rw-r--r--src/utils/lombok/permit/dummy/package-info.java8
10 files changed, 181 insertions, 26 deletions
diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java
index 31979955..8af481b9 100644
--- a/src/utils/lombok/eclipse/Eclipse.java
+++ b/src/utils/lombok/eclipse/Eclipse.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2019 The Project Lombok Authors.
+ * Copyright (C) 2009-2021 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
@@ -60,6 +60,13 @@ public class Eclipse {
*/
public static final int ECLIPSE_DO_NOT_TOUCH_FLAG = ASTNode.Bit24;
+ /* This section includes flags that are in ecj files too new vs. the deps we compile against.
+ * Specifically: org.eclipse.jdt.internal.compiler.ast.ASTNode and org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers
+ */
+ public static final int AccRecord = ASTNode.Bit25; // ECM.AccRecord
+ public static final int IsCanonicalConstructor = ASTNode.Bit10; // ASTNode.IsCanonicalConstructor
+ public static final int IsImplicit = ASTNode.Bit11; // ASTNode.IsImplicit
+
private static final Pattern SPLIT_AT_DOT = Pattern.compile("\\.");
private Eclipse() {
@@ -239,9 +246,14 @@ public class Eclipse {
for (Field f : CompilerOptions.class.getDeclaredFields()) {
try {
- if (f.getName().startsWith("VERSION_1_")) {
- ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(f.getName().substring("VERSION_1_".length())));
- }
+ String fName = f.getName();
+ String versionNumber = null;
+ if (fName.startsWith("VERSION_1_")) {
+ versionNumber = fName.substring("VERSION_1_".length());
+ } else if (fName.startsWith("VERSION_")) {
+ versionNumber = fName.substring("VERSION_".length());
+ } else continue;
+ ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(versionNumber));
} catch (Exception ignore) {}
}
diff --git a/src/utils/lombok/eclipse/Java14Bits.java b/src/utils/lombok/eclipse/Java14Bits.java
new file mode 100644
index 00000000..c7e00c39
--- /dev/null
+++ b/src/utils/lombok/eclipse/Java14Bits.java
@@ -0,0 +1,11 @@
+package lombok.eclipse;
+
+import org.eclipse.jdt.internal.compiler.ast.ASTNode;
+
+public class Java14Bits {
+ private Java14Bits() { }
+
+ public static final int AccRecord = ASTNode.Bit25;
+ public static final int IsCanonicalConstructor = ASTNode.Bit10; // record declaration
+ public static final int IsImplicit = ASTNode.Bit11; // record declaration / generated statements in compact constructor
+}
diff --git a/src/utils/lombok/javac/Java14Flags.java b/src/utils/lombok/javac/Java14Flags.java
new file mode 100644
index 00000000..0d565dca
--- /dev/null
+++ b/src/utils/lombok/javac/Java14Flags.java
@@ -0,0 +1,26 @@
+package lombok.javac;
+
+public class Java14Flags {
+ private Java14Flags() { }
+
+ /**
+ * Flag to indicate that a class is a record. The flag is also used to mark fields that are
+ * part of the state vector of a record and to mark the canonical constructor
+ */
+ public static final long RECORD = 1L<<61; // ClassSymbols, MethodSymbols and VarSymbols
+
+ /**
+ * Flag to mark a record constructor as a compact one
+ */
+ public static final long COMPACT_RECORD_CONSTRUCTOR = 1L<<51; // MethodSymbols only
+
+ /**
+ * Flag to mark a record field that was not initialized in the compact constructor
+ */
+ public static final long UNINITIALIZED_FIELD= 1L<<51; // VarSymbols only
+
+ /** Flag is set for compiler-generated record members, it could be appplied to
+ * accessors and fields
+ */
+ public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols
+}
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 33bd7265..c0bda93c 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -75,6 +75,12 @@ public class Javac {
private static final AtomicInteger compilerVersion = new AtomicInteger(-1);
+ /* This section includes flags that would ordinarily be in Flags, but which are 'too new' (we don't compile against older versions of javac for compatibility). */
+ public static final long RECORD = 1L << 61; // ClassSymbols, MethodSymbols, VarSymbols (Marks types as being records, as well as the 'fields' in the compact declaration, and the canonical constructor)
+ public static final long COMPACT_RECORD_CONSTRUCTOR = 1L << 51; // MethodSymbols (the 'implicit' many-args constructor that records have)
+ public static final long UNINITIALIZED_FIELD = 1L << 51; // VarSymbols (To identify fields that the compact record constructor won't initialize)
+ public static final long GENERATED_MEMBER = 1L << 24; // MethodSymbols, VarSymbols (marks methods and the constructor generated in records)
+
/**
* Returns the version of this java compiler, i.e. the JDK that it shipped in. For example, for javac v1.7, this returns {@code 7}.
*/
@@ -279,6 +285,17 @@ public class Javac {
return null;
}
+ /**
+ * Checks if the javadoc comment associated with {@code tree} has a position set.
+ *
+ * Returns true if there is no javadoc comment on the node, or it has position (position isn't -1).
+ */
+ public static boolean validateDocComment(JCCompilationUnit cu, JCTree tree) {
+ Object dc = getDocComments(cu);
+ if (!instanceOfDocCommentTable(dc)) return true;
+ return JavadocOps_8.validateJavadoc(dc, tree);
+ }
+
@SuppressWarnings("unchecked")
public static void setDocComment(JCCompilationUnit cu, JCTree node, String javadoc) {
if (javadoc == null) return;
@@ -302,6 +319,12 @@ public class Javac {
return javadoc.getText();
}
+ public static boolean validateJavadoc(Object dc, JCTree node) {
+ DocCommentTable dct = (DocCommentTable) dc;
+ Comment javadoc = dct.getComment(node);
+ return javadoc == null || javadoc.getText() == null || javadoc.getSourcePos(0) >= 0;
+ }
+
static void setJavadoc(Object dc, JCTree node, String javadoc) {
DocCommentTable dct = (DocCommentTable) dc;
Comment newCmt = createJavadocComment(javadoc, node);
@@ -315,7 +338,7 @@ public class Javac {
}
@Override public int getSourcePos(int index) {
- return -1;
+ return field == null ? -1 : field.getStartPosition();
}
@Override public CommentStyle getStyle() {
diff --git a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java
index cb0d2e12..f29f501b 100644
--- a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java
+++ b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2019 The Project Lombok Authors.
+ * Copyright (C) 2011-2021 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
@@ -72,18 +72,31 @@ public class CommentCollectingScannerFactory extends ScannerFactory {
super(context);
}
+ @SuppressWarnings("all")
@Override
public Scanner newScanner(CharSequence input, boolean keepDocComments) {
- if (input instanceof CharBuffer) {
- CharBuffer buf = (CharBuffer) input;
- return new CommentCollectingScanner(this, new CommentCollectingTokenizer(this, buf, findTextBlocks));
+ char[] array;
+ int limit;
+ if (input instanceof CharBuffer && ((CharBuffer) input).hasArray()) {
+ CharBuffer cb = (CharBuffer) input;
+ cb.compact().flip();
+ array = cb.array();
+ limit = cb.limit();
+ } else {
+ array = input.toString().toCharArray();
+ limit = array.length;
+ }
+ if (array.length == limit) {
+ // work around a bug where the last comment in a file falls away in this case.
+ char[] d = new char[limit + 1];
+ System.arraycopy(array, 0, d, 0, limit);
+ array = d;
}
- char[] array = input.toString().toCharArray();
- return newScanner(array, array.length, keepDocComments);
+ return newScanner(array, limit, keepDocComments);
}
@Override
public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) {
- return new CommentCollectingScanner(this, new CommentCollectingTokenizer(this, input, inputLength, findTextBlocks));
+ return new CommentCollectingScanner(this, CommentCollectingTokenizer.create(this, input, inputLength, findTextBlocks));
}
}
diff --git a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
index d7b1d569..4a31fc81 100644
--- a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
+++ b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2020 The Project Lombok Authors.
+ * Copyright (C) 2013-2021 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
@@ -23,36 +23,51 @@ package lombok.javac.java8;
import java.nio.CharBuffer;
-import lombok.javac.CommentInfo;
-import lombok.javac.CommentInfo.EndConnection;
-import lombok.javac.CommentInfo.StartConnection;
-
import com.sun.tools.javac.parser.JavaTokenizer;
import com.sun.tools.javac.parser.ScannerFactory;
import com.sun.tools.javac.parser.Tokens.Comment;
-import com.sun.tools.javac.parser.Tokens.Token;
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
+import com.sun.tools.javac.parser.Tokens.Token;
import com.sun.tools.javac.parser.UnicodeReader;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
+import lombok.javac.CommentInfo;
+import lombok.javac.CommentInfo.EndConnection;
+import lombok.javac.CommentInfo.StartConnection;
+
class CommentCollectingTokenizer extends JavaTokenizer {
+
+ private static final boolean tokenizerIsUnicodeReader = JavaTokenizer.class.getSuperclass().getSimpleName().equals("UnicodeReader");
+
private int prevEndPosition = 0;
private final ListBuffer<CommentInfo> comments = new ListBuffer<CommentInfo>();
private final ListBuffer<Integer> textBlockStarts;
private int endComment = 0;
- CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) {
+ static CommentCollectingTokenizer create(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) {
+ if (tokenizerIsUnicodeReader) {
+ return new CommentCollectingTokenizer(fac, buf, inputLength, findTextBlocks, true);
+ }
+ return new CommentCollectingTokenizer(fac, buf, inputLength, findTextBlocks);
+ }
+
+ // pre java 16
+ private CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) {
super(fac, new PositionUnicodeReader(fac, buf, inputLength));
textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null;
}
- CommentCollectingTokenizer(ScannerFactory fac, CharBuffer buf, boolean findTextBlocks) {
- super(fac, new PositionUnicodeReader(fac, buf));
+ // from java 16
+ private CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks, boolean java16Signature) {
+ super(fac, buf, inputLength);
textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null;
}
int pos() {
+ if (tokenizerIsUnicodeReader) {
+ return position();
+ }
return ((PositionUnicodeReader) reader).pos();
}
@@ -60,8 +75,8 @@ class CommentCollectingTokenizer extends JavaTokenizer {
Token token = super.readToken();
prevEndPosition = pos();
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);
+ char[] start = reader().getRawCharacters(token.pos, token.pos + 3);
+ if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.append(token.pos);
}
return token;
}
@@ -70,7 +85,7 @@ class CommentCollectingTokenizer extends JavaTokenizer {
protected Comment processComment(int pos, int endPos, CommentStyle style) {
int prevEndPos = Math.max(prevEndPosition, endComment);
endComment = endPos;
- String content = new String(reader.getRawCharacters(pos, endPos));
+ String content = new String(reader().getRawCharacters(pos, endPos));
StartConnection start = determineStartConnection(prevEndPos, pos);
EndConnection end = determineEndConnection(endPos);
@@ -85,7 +100,7 @@ class CommentCollectingTokenizer extends JavaTokenizer {
for (int i = pos;; i++) {
char c;
try {
- c = reader.getRawCharacters(i, i + 1)[0];
+ c = reader().getRawCharacters(i, i + 1)[0];
} catch (IndexOutOfBoundsException e) {
c = '\n';
}
@@ -104,7 +119,7 @@ class CommentCollectingTokenizer extends JavaTokenizer {
if (from == to) {
return StartConnection.DIRECT_AFTER_PREVIOUS;
}
- char[] between = reader.getRawCharacters(from, to);
+ char[] between = reader().getRawCharacters(from, to);
if (isNewLine(between[between.length - 1])) {
return StartConnection.START_OF_LINE;
}
@@ -128,6 +143,13 @@ class CommentCollectingTokenizer extends JavaTokenizer {
return textBlockStarts == null ? List.<Integer>nil() : textBlockStarts.toList();
}
+ private UnicodeReader reader() {
+ if (tokenizerIsUnicodeReader) {
+ return (UnicodeReader) (Object) this;
+ }
+ return reader;
+ }
+
static class PositionUnicodeReader extends UnicodeReader {
protected PositionUnicodeReader(ScannerFactory sf, char[] input, int inputLength) {
super(sf, input, inputLength);
diff --git a/src/utils/lombok/permit/dummy/Child.java b/src/utils/lombok/permit/dummy/Child.java
new file mode 100644
index 00000000..c189ee37
--- /dev/null
+++ b/src/utils/lombok/permit/dummy/Child.java
@@ -0,0 +1,9 @@
+package lombok.permit.dummy;
+
+@SuppressWarnings("all")
+public abstract class Child extends Parent {
+ private transient volatile boolean foo;
+ private transient volatile Object[] bar;
+ private transient volatile Object baz;
+
+}
diff --git a/src/utils/lombok/permit/dummy/GrandChild.java b/src/utils/lombok/permit/dummy/GrandChild.java
new file mode 100644
index 00000000..ef182aa7
--- /dev/null
+++ b/src/utils/lombok/permit/dummy/GrandChild.java
@@ -0,0 +1,19 @@
+package lombok.permit.dummy;
+
+@SuppressWarnings("all")
+public final class GrandChild extends Child {
+ private Class<?> a;
+ private int b;
+ private String c;
+ private Class<?> d;
+ private Class<?>[] e;
+ private Class<?>[] f;
+ private int g;
+ private transient String h;
+ private transient Object i;
+ private byte[] j;
+ private byte[] k;
+ private byte[] l;
+ private volatile Object m;
+ private Object n;
+}
diff --git a/src/utils/lombok/permit/dummy/Parent.java b/src/utils/lombok/permit/dummy/Parent.java
new file mode 100644
index 00000000..33928aeb
--- /dev/null
+++ b/src/utils/lombok/permit/dummy/Parent.java
@@ -0,0 +1,12 @@
+package lombok.permit.dummy;
+
+import java.io.OutputStream;
+
+@SuppressWarnings("all")
+public class Parent {
+ boolean first;
+ static final Object staticObj = OutputStream.class;
+ volatile Object second;
+ private static volatile boolean staticSecond;
+ private static volatile boolean staticThird;
+}
diff --git a/src/utils/lombok/permit/dummy/package-info.java b/src/utils/lombok/permit/dummy/package-info.java
new file mode 100644
index 00000000..87ca839a
--- /dev/null
+++ b/src/utils/lombok/permit/dummy/package-info.java
@@ -0,0 +1,8 @@
+/**
+ * This package recreates the type hierarchy of {@code java.lang.reflect.AccessibleObject} and friends (such as {@code java.lang.reflect.Method});
+ * its purpose is to allow us to ask {@code sun.misc.internal.Unsafe} about the exact offset of the {@code override} field of {@code AccessibleObject};
+ * asking about that field directly doesn't work after jdk14, presumably because the fields of AO are expressly hidden somehow.
+ *
+ * NB: It's usually 12, on the vast majority of OS, VM, and architecture combos.
+ */
+package lombok.permit.dummy;