10000 Prepare testing for JDK15, improve enum compat handling, + record constr · sakerbuild/saker.java.compiler@5358a33 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5358a33

Browse files
committed
Prepare testing for JDK15, improve enum compat handling, + record constr
Fixed implicit constructor modifier determining for records. On JDK15, the visibility modifier for implicit record constructors are no longer public, but same as the enclosing record type. Also added test for the modifiers of an inner record class, static modifier is implicit.
1 parent ed6e074 commit 5358a33

File tree

28 files changed

+524
-87
lines changed

28 files changed

+524
-87
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2020 Bence Sipka
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
package saker.java.compiler.api.processing.exc;
17+
18+
import java.util.Objects;
19+
20+
import javax.lang.model.element.ElementKind;
21+
22+
/**
23+
* Exception thrown when an {@link ElementKind} was not found in the current JVM.
24+
* <p>
25+
* Exceptions of this type can be thrown if the compilation is being done by a more recent JVM version than the one that
26+
* tries to retrieve the {@link ElementKind} enumeration value.
27+
* <p>
28+
* The {@linkplain #getMessage() message} returns the name of the {@link ElementKind} that was not found.
29+
*
30+
* @since saker.java.compiler 0.8.7
31+
*/
32+
public class ElementKindNotFoundException extends IllegalArgumentException {
33+
private static final long serialVersionUID = 1L;
34+
35+
/**
36+
* Creates a new instance with the specified enum name and the {@link IllegalArgumentException} that caused it.
37+
*
38+
* @param enumname
39+
* The name of the {@link ElementKind} that was not found.
40+
* @param cause
41+
* The exception that determined that the enumeration was not found. It is the one thrown by
42+
* {@link ElementKind#valueOf(String)}.
43+
* @throws NullPointerException
44+
* If any of the arguments are <code>null</code>.
45+
*/
46+
public ElementKindNotFoundException(String enumname, IllegalArgumentException cause) throws NullPointerException {
47+
super(Objects.requireNonNull(enumname, "enum name"), Objects.requireNonNull(cause, "cause"));
48+
}
49+
50+
/**
51+
* Gets the enumeration name of the {@link ElementKind} that was not found.
52+
* <p>
53+
* {@inheritDoc}
54+
*/
55+
@Override
56+
public String getMessage() {
57+
return super.getMessage();
58+
}
59+
60+
/**
61+
* Gets the exception that was received when the enumeration was tried to be looked up.
62+
* <p>
63+
* The exception is directly thrown by {@link ElementKind#valueOf(String)}.
64+
* <p>
65+
* {@inheritDoc}
66+
*/
67+
@Override
68+
public IllegalArgumentException getCause() {
69+
return (IllegalArgumentException) super.getCause();
70+
}
71+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (C) 2020 Bence Sipka
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
package saker.java.compiler.api.processing.exc;
17+
18+
import java.util.Objects;
19+
20+
import javax.lang.model.element.Element;
21+
import javax.lang.model.element.Modifier;
22+
23+
/**
24+
* Exception thrown when an {@link Modifier} was not found in the current JVM.
25+
* <p>
26+
* Exceptions of this type can be thrown if the compilation is being done by a more recent JVM version than the one that
27+
* tries to retrieve the {@link Modifier} enumeration value.
28+
* <p>
29+
* The {@linkplain #getMessage() message} returns the name of the {@link Modifier} that was not found.
30+
*
31+
* @since saker.java.compiler 0.8.7
32+
* @see Element#getModifiers()
33+
*/
34+
public class ModifierNotFoundException extends IllegalArgumentException {
35+
private static final long serialVersionUID = 1L;
36+
37+
/**
38+
* Creates a new instance with the specified enum name and the {@link IllegalArgumentException} that caused it.
39+
*
40+
* @param enumname
41+
* The name of the {@link Modifier} that was not found.
42+
* @param cause
43+
* The exception that determined that the enumeration was not found. It is the one thrown by
44+
* {@link Modifier#valueOf(String)}.
45+
* @throws NullPointerException
46+
* If any of the arguments are <code>null</code>.
47+
*/
48+
public ModifierNotFoundException(String enumname, IllegalArgumentException cause) throws NullPointerException {
49+
super(Objects.requireNonNull(enumname, "enum name"), Objects.requireNonNull(cause, "cause"));
50+
}
51+
52+
/**
53+
* Gets the enumeration name of the {@link Modifier} that was not found.
54+
* <p>
55+
* {@inheritDoc}
56+
*/
57+
@Override
58+
public String getMessage() {
59+
return super.getMessage();
60+
}
61+
62+
/**
63+
* Gets the exception that was received when the enumeration was tried to be looked up.
64+
* <p>
65+
* The exception is directly thrown by {@link Modifier#valueOf(String)}.
66+
* <p>
67+
* {@inheritDoc}
68+
*/
69+
@Override
70+
public IllegalArgumentException getCause() {
71+
return (IllegalArgumentException) super.getCause();
72+
}
73+
}

api/src/main/saker/java/compiler/api/processing/exc/SourceVersionNotFoundException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import java.util.Objects;
1919

20+
import javax.annotation.processing.ProcessingEnvironment;
2021
import javax.lang.model.SourceVersion;
22+
import javax.lang.model.util.Elements;
2123

2224
/**
2325
* Exception describing the scenario when a {@link SourceVersion} enumeration cannot be retrieved due to it not being
@@ -30,12 +32,14 @@
3032
* <p>
3133
* The actual name of the enumeration that was not found can be retrieved by calling {@link #getMessage()}. It is in the
3234
* format of <code>RELEASE_*</code>.
35+
*
36+
* @see ProcessingEnvironment#getSourceVersion()
3337
*/
3438
public final class SourceVersionNotFoundException extends IllegalArgumentException {
3539
private static final long serialVersionUID = 1L;
3640

3741
/**
38-
* Creates a new instance with the specified enum name and the {@link IllegalArgumentException} that caused this.
42+
* Creates a new instance with the specified enum name and the {@link IllegalArgumentException} that caused it.
3943
*
4044
* @param enumname
4145
* The name of the {@link SourceVersion} that was not found.

impl-jdk12/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
3232
import saker.java.compiler.impl.compile.handler.info.RealizedSignatureData;
33+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
3334
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
3435
import saker.java.compiler.jdk.impl.incremental.model.IncrementalElementsTypes;
3536
import saker.java.compiler.jdk.impl.parser.signature.CompilationUnitSignatureParser;
@@ -54,9 +55,9 @@ public static AbiUsageParser createAbiUsageParser(Trees trees, String srcver, Pa
5455
return new AbiUsageParser(trees, srcver, cache);
5556
}
5657

57-
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync, String srcver,
58-
ParserCache cache) {
59-
return new IncrementalElementsTypes(realelements, javacsync, cache);
58+
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync,
59+
CompilationContextInformation context, ParserCache cache) {
60+
return new IncrementalElementsTypes(realelements, javacsync, cache, context);
6061
}
6162

6263
public static RealizedSignatureData getRealizedSignatures(CompilationUnitTree unit, Trees trees, String filename,

impl-jdk12/src/main/saker/java/compiler/jdk/impl/incremental/model/IncrementalElementsTypes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import javax.lang.model.util.Elements;
1919

20+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
2021
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
2122
import saker.java.compiler.util9.impl.model.IncrementalElementsTypes9;
2223

2324
public class IncrementalElementsTypes extends IncrementalElementsTypes9 {
24-
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache) {
25-
super(realelements, javacsync, cache);
25+
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache,
26+
CompilationContextInformation context) {
27+
super(realelements, javacsync, cache, context);
2628
}
2729
}

impl-jdk13/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import saker.build.thirdparty.saker.rmi.connection.RMITransferProperties;
3232
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
3333
import saker.java.compiler.impl.compile.handler.info.RealizedSignatureData;
34+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
3435
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
3536
import saker.java.compiler.jdk.impl.incremental.model.IncrementalElementsTypes;
3637
import saker.java.compiler.jdk.impl.parser.signature.CompilationUnitSignatureParser;
@@ -53,9 +54,9 @@ public static AbiUsageParser createAbiUsageParser(Trees trees, String srcver, Pa
5354
return new AbiUsageParser(trees, srcver, cache);
5455
}
5556

56-
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync, String srcver,
57-
ParserCache cache) {
58-
return new IncrementalElementsTypes(realelements, javacsync, cache);
57+
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync,
58+
CompilationContextInformation context, ParserCache cache) {
59+
return new IncrementalElementsTypes(realelements, javacsync, cache, context);
5960
}
6061

6162
public static RealizedSignatureData getRealizedSignatures(CompilationUnitTree unit, Trees trees, String filename,

impl-jdk13/src/main/saker/java/compiler/jdk/impl/incremental/model/IncrementalElementsTypes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import javax.lang.model.util.Elements;
1919

20+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
2021
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
2122
import saker.java.compiler.util9.impl.model.IncrementalElementsTypes9;
2223

2324
public class IncrementalElementsTypes extends IncrementalElementsTypes9 {
24-
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache) {
25-
super(realelements, javacsync, cache);
25+
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache,
26+
CompilationContextInformation context) {
27+
super(realelements, javacsync, cache, context);
2628
}
2729
}

impl-jdk14/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import saker.build.thirdparty.saker.rmi.connection.RMITransferProperties;
3131
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
3232
import saker.java.compiler.impl.compile.handler.info.RealizedSignatureData;
33+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
3334
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
3435
import saker.java.compiler.jdk.impl.incremental.model.IncrementalElementsTypes;
3536
import saker.java.compiler.jdk.impl.parser.signature.CompilationUnitSignatureParser;
@@ -54,9 +55,9 @@ public static AbiUsageParser createAbiUsageParser(Trees trees, String srcver, Pa
5455
return new AbiUsageParser(trees, srcver, cache);
5556
}
5657

57-
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync, String srcver,
58-
ParserCache cache) {
59-
return new IncrementalElementsTypes(realelements, javacsync, cache);
58+
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync,
59+
CompilationContextInformation context, ParserCache cache) {
60+
return new IncrementalElementsTypes(realelements, javacsync, cache, context);
6061
}
6162

6263
public static RealizedSignatureData getRealizedSignatures(CompilationUnitTree unit, Trees trees, String filename,
@@ -81,6 +82,7 @@ public static String getModuleNameOf(Element elem) {
8182
return Java9LanguageUtils.getModuleNameOf(elem);
8283
}
8384

85+
//TODO remove element kind related functions
8486
public static boolean isModuleElementKind(ElementKind kind) {
8587
return Java9LanguageUtils.isModuleElementKind(kind);
8688
}

impl-jdk14/src/main/saker/java/compiler/jdk/impl/incremental/model/IncrementalElementsTypes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import javax.lang.model.util.Elements;
1919

20+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
2021
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
2122
import saker.java.compiler.util14.impl.model.IncrementalElementsTypes14;
2223

2324
public class IncrementalElementsTypes extends IncrementalElementsTypes14 {
24-
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache) {
25-
super(realelements, javacsync, cache);
25+
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache,
26+
CompilationContextInformation context) {
27+
super(realelements, javacsync, cache, context);
2628
}
2729
}

impl-jdk8/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import saker.java.compiler.impl.JavaTaskUtils;
3737
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
3838
import saker.java.compiler.impl.compile.handler.info.RealizedSignatureData;
39+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
3940
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
4041
import saker.java.compiler.impl.signature.element.ClassSignature;
4142
import saker.java.compiler.impl.signature.element.ModuleSignature;
@@ -60,9 +61,9 @@ public static AbiUsageParser createAbiUsageParser(Trees trees, String srcver, Pa
6061
return new AbiUsageParser(trees, srcver, cache);
6162
}
6263

63-
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync, String srcver,
64-
ParserCache cache) {
65-
return new IncrementalElementsTypes(realelements, javacsync, cache);
64+
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync,
65+
CompilationContextInformation context, ParserCache cache) {
66+
return new IncrementalElementsTypes(realelements, javacsync, cache, context);
6667
}
6768

6869
public static RealizedSignatureData getRealizedSignatures(CompilationUnitTree unit, Trees trees, String filename,

impl-jdk8/src/main/saker/java/compiler/jdk/impl/incremental/model/IncrementalElementsTypes.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
import javax.lang.model.util.Elements;
1919

20+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
2021
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
2122
import saker.java.compiler.util8.impl.model.IncrementalElementsTypes8;
2223

2324
public class IncrementalElementsTypes extends IncrementalElementsTypes8 {
24-
25-
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache) {
26-
super(realelements, javacsync, cache);
25+
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache,
26+
CompilationContextInformation context) {
27+
super(realelements, javacsync, cache, context);
2728
}
2829
}

impl-jdk9/src/main/saker/java/compiler/jdk/impl/JavaCompilationUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import saker.java.compiler.impl.compile.file.IncrementalDirectoryPaths;
3131
import saker.java.compiler.impl.compile.handler.info.RealizedSignatureData;
32+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
3233
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
3334
import saker.java.compiler.jdk.impl.incremental.model.IncrementalElementsTypes;
3435
import saker.java.compiler.jdk.impl.parser.signature.CompilationUnitSignatureParser;
@@ -76,9 +77,9 @@ public static AbiUsageParser createAbiUsageParser(Trees trees, String srcver, Pa
7677
return new AbiUsageParser(trees, srcver, cache);
7778
}
7879

79-
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync, String srcver,
80-
ParserCache cache) {
81-
return new IncrementalElementsTypes(realelements, javacsync, cache);
80+
public static IncrementalElementsTypes createElementsTypes(Elements realelements, Object javacsync,
81+
CompilationContextInformation context, ParserCache cache) {
82+
return new IncrementalElementsTypes(realelements, javacsync, cache, context);
8283
}
8384

8485
public static RealizedSignatureData getRealizedSignatures(CompilationUnitTree unit, Trees trees, String filename,

impl-jdk9/src/main/saker/java/compiler/jdk/impl/incremental/model/IncrementalElementsTypes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
import javax.lang.model.util.Elements;
1919

20+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
2021
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
2122
import saker.java.compiler.util9.impl.model.IncrementalElementsTypes9;
2223

2324
public class IncrementalElementsTypes extends IncrementalElementsTypes9 {
24-
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache) {
25-
super(realelements, javacsync, cache);
25+
public IncrementalElementsTypes(Elements realelements, Object javacsync, ParserCache cache,
26+
CompilationContextInformation context) {
27+
super(realelements, javacsync, cache, context);
2628
}
2729
}

impl-util-jdk14/src/main/saker/java/compiler/util14/impl/model/IncrementalElementsTypes14.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import saker.java.compiler.impl.compile.handler.incremental.model.elem.IncrementalElement;
77
import saker.java.compiler.impl.compile.handler.incremental.model.elem.IncrementalTypeElement;
88
import saker.java.compiler.impl.compile.handler.incremental.model.forwarded.elem.ForwardingElementBase;
9+
import saker.java.compiler.impl.compile.handler.invoker.CompilationContextInformation;
910
import saker.java.compiler.impl.compile.signature.parser.ParserCache;
1011
import saker.java.compiler.impl.signature.element.FieldSignature;
1112
import saker.java.compiler.util14.impl.model.elem.IncrementalRecordComponentElement;
@@ -14,8 +15,9 @@
1415

1516
public class IncrementalElementsTypes14 extends IncrementalElementsTypes9 {
1617

17-
public IncrementalElementsTypes14(Elements realelements, Object javacsync, ParserCache cache) {
18-
super(realelements, javacsync, cache);
18+
public IncrementalElementsTypes14(Elements realelements, Object javacsync, ParserCache cache,
19+
CompilationContextInformation context) {
20+
super(realelements, javacsync, cache, context);
1921
setForwardingElementVisitor(new ForwardingElementVisitor14());
2022
}
2123

0 commit comments

Comments
 (0)
0