Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8306112 Implementation of JEP 445: Unnamed Classes and Instance Main Methods (Preview) #13689

Closed
wants to merge 56 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bbd1de8
JEP 445
Apr 20, 2023
8545dcc
Merge branch 'master' into 8306112
Apr 24, 2023
d5ebe61
Revised main method lookup
Apr 24, 2023
a7bca07
remnant import
Apr 24, 2023
891d00b
Clean up
Apr 25, 2023
8c023f5
Merge branch 'master' into 8306112
Apr 25, 2023
db12c9a
Update TestJavacTaskScanner.java
Apr 25, 2023
44af61d
Clean up testing
Apr 26, 2023
ef56b9e
Update VM.java
Apr 26, 2023
3f174fc
Corrections
Apr 26, 2023
a89cb96
Missing exception
Apr 26, 2023
cfe08f3
Clean up isPreview
Apr 27, 2023
a55af76
PreviewFeatures.isEnabled()
Apr 27, 2023
53a5321
Merge branch 'master' into 8306112
Apr 27, 2023
f66f6e4
Recommended changes #1
Apr 27, 2023
e5ca303
Can't be invokeExact for instance main
Apr 28, 2023
6f81996
Unused variables
Apr 28, 2023
2c32183
Leave exception alone
Apr 28, 2023
201c9ee
Revert java launch
Apr 29, 2023
a09a0a1
Move AnonymousMainClass to parser
Apr 29, 2023
ffc7763
Add test
May 1, 2023
ff7cd4c
Anonymous main classes renamed to unnamed classes
May 1, 2023
788b4e5
Recommended changes #2
May 5, 2023
0c8add6
Typo
May 5, 2023
b91e75a
Refactor source code launcher
May 5, 2023
c3cfa83
Merge branch 'master' into 8306112
May 11, 2023
90b1e98
Update VirtualParser.java
May 11, 2023
2b625a3
Requested Changes #2
May 15, 2023
185532a
Merge branch 'master' into 8306112
May 16, 2023
83f3152
Give subclass priority
May 18, 2023
6b57ee9
Issue warning if traditional main not used.
May 23, 2023
b2e9c4f
Merge branch 'master' into 8306112
May 23, 2023
b55f82f
Fix missing constructor error messages and handle inner class launching
May 23, 2023
e590c73
Allow unqualified access to unnamed class (internally visible)
May 24, 2023
8ccb950
Ignore SKIPs (semicolon class declarations)
May 24, 2023
cfac821
Improving error recovery in presence of less important syntactic erro…
May 25, 2023
4e54c17
Add main tests for inferface/enum/record
May 26, 2023
06aa43e
Remove trailing whitespace
May 26, 2023
a8b3101
Remove mandated flag
May 31, 2023
d0189fc
Merge branch 'master' into 8306112
May 31, 2023
4bfb802
Restrict access to unnamed class members when doing separate compilat…
Jun 1, 2023
850a215
Missing Preview feature enum
Jun 1, 2023
9d111c2
Integrate JDK-8308916 and JDK-8308831 - javax.model
Jun 1, 2023
f1acdb0
Integrating JDK-8308913
Jun 1, 2023
e39e3fe
Merge branch 'master' into 8306112
Jun 1, 2023
f1e875c
Update reflection to follow spec
Jun 2, 2023
0edcd9a
Merge branch 'master' into 8306112
Jun 2, 2023
0d21a30
ClassSymbol#getSimpleName() returning empty name breaks some tools
Jun 2, 2023
97a522f
Use getQualifiedName() to indicate unnamed class
Jun 2, 2023
55b6be5
Update the specification for TypeElement#getQualifiedName and TypeEle…
Jun 2, 2023
c75ebf5
Source code launcher to use getSimpleName() when launching unnamed class
Jun 5, 2023
319795b
Requested clean ups
Jun 5, 2023
94d1eef
Merge branch 'master' into 8306112
Jun 5, 2023
3bbdb8f
Final clean up
Jun 5, 2023
663ca88
Merge branch 'master' into 8306112
Jun 5, 2023
d0fdf69
-Xprint unnamed classes to use e.getSimpleName()
Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -31,33 +31,6 @@
import java.util.List;

public class MainMethodFinder {
private static final boolean IS_PREVIEW = getIsPreview();

/**
* { @return true if vm is in preview mode }
*/
public static boolean isPreview() {
return IS_PREVIEW;
}

/*
* TODO: not perfect, if user adds "--enable-preview" after class argument then will get false positive.
*/
private static boolean getIsPreview() {
String[] args = VM.getRuntimeArguments();

if (args != null) {
for (String arg : args) {
if ("--enable-preview".equals(arg)) {
return true;
}
}
}

return false;
}


private static boolean isPrivate(Method method) {
return method != null && Modifier.isPrivate(method.getModifiers());
JimLaskey marked this conversation as resolved.
Show resolved Hide resolved
}
@@ -173,7 +146,7 @@ public static Method findMainMethod(Class<?> mainClass) throws NoSuchMethodExcep

return mainClass.getMethod("main", String[].class);
JimLaskey marked this conversation as resolved.
Show resolved Hide resolved
} catch (NoSuchMethodException nsme) {
if (!isPreview()) {
if (!PreviewFeatures.isEnabled()) {
throw nsme;
}

3 changes: 2 additions & 1 deletion src/java.base/share/classes/sun/launcher/LauncherHelper.java
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@

import jdk.internal.util.OperatingSystem;
import jdk.internal.misc.MainMethodFinder;
import jdk.internal.misc.PreviewFeatures;
import jdk.internal.misc.VM;
import jdk.internal.module.ModuleBootstrap;
import jdk.internal.module.Modules;
@@ -891,7 +892,7 @@ static void validateMainClass(Class<?> mainClass) {
boolean isPublic = Modifier.isPublic(mods);
boolean hasArgs = mainMethod.getParameterCount() != 0;

if (!MainMethodFinder.isPreview()) {
if (!PreviewFeatures.isEnabled()) {
if (!isStatic || !isPublic || !hasArgs) {
abort(null, "java.launcher.cls.error2", "static",
mainMethod.getDeclaringClass().getName());
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@
import com.sun.tools.javac.util.JCDiagnostic.Error;

import jdk.internal.misc.MainMethodFinder;
import jdk.internal.misc.PreviewFeatures;
import jdk.internal.misc.VM;

import static javax.tools.JavaFileObject.Kind.SOURCE;
@@ -434,7 +435,7 @@ private void execute(String mainClassName, String[] appArgs, Context context)
try {
Class<?> appClass = Class.forName(mainClassName, true, cl);
Method main = MainMethodFinder.findMainMethod(appClass);
if (!MainMethodFinder.isPreview() && (!isStatic(main) || !isPublic(main))) {
if (!PreviewFeatures.isEnabled() && (!isStatic(main) || !isPublic(main))) {
JimLaskey marked this conversation as resolved.
Show resolved Hide resolved
throw new Fault(Errors.MainNotPublicStatic);
}
if (!main.getReturnType().equals(void.class)) {