Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Try not to use modules
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Jul 7, 2022
1 parent c271894 commit 2b84123
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 186 deletions.
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

JDK_8="/usr/lib/jvm/java-8-openjdk-amd64"
if [ -d "$JDK_8" ]; then
export JAVA_HOME=$JDK_8
fi

ant -f ./make/langtools/netbeans/nb-javac "$@"
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public enum SourceVersion {
* {@return the latest source version that can be modeled}
*/
public static SourceVersion latest() {
return RELEASE_17;
return RELEASE_8;
}

private static final SourceVersion latestSupported = getLatestSupported();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ public int run(InputStream in, OutputStream out, OutputStream err, String... arg

@Override @DefinedBy(Api.COMPILER)
public Set<SourceVersion> getSourceVersions() {
// AndroidIDE changed: Allow upto Java 11
return Collections.unmodifiableSet(EnumSet.range(SourceVersion.RELEASE_3,
SourceVersion.latest()));
SourceVersion.RELEASE_11));
}

@Override @DefinedBy(Api.COMPILER)
Expand Down
183 changes: 105 additions & 78 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,22 @@

import static com.sun.tools.javac.main.Option.*;

/** The source language version accepted.
/**
* The source language version accepted.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
* <p>
* <b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/

public enum Source {
/** 1.0 had no inner classes, and so could not pass the JCK. */
// public static final Source JDK1_0 = new Source("1.0");
// public static final Source JDK1_0 = new Source("1.0");

/** 1.1 did not have strictfp, and so could not pass the JCK. */
// public static final Source JDK1_1 = new Source("1.1");
// public static final Source JDK1_1 = new Source("1.1");

/** 1.2 introduced strictfp. */
JDK1_2("1.2"),
Expand All @@ -63,8 +65,10 @@ public enum Source {
/** 1.4 introduced assert. */
JDK1_4("1.4"),

/** 1.5 introduced generics, attributes, foreach, boxing, static import,
* covariant return, enums, varargs, et al. */
/**
* 1.5 introduced generics, attributes, foreach, boxing, static import,
* covariant return, enums, varargs, et al.
*/
JDK5("5"),

/** 1.6 reports encoding problems as errors instead of warnings. */
Expand Down Expand Up @@ -101,18 +105,18 @@ public enum Source {
JDK14("14"),

/**
* 15, text blocks
*/
* 15, text blocks
*/
JDK15("15"),

/**
* 16, tbd
*/
* 16, tbd
*/
JDK16("16"),

/**
* 17, tbd
*/
* 17, tbd
*/
JDK17("17");

private static final Context.Key<Source> sourceKey = new Context.Key<>();
Expand All @@ -122,16 +126,18 @@ public static Source instance(Context context) {
if (instance == null) {
Options options = Options.instance(context);
String sourceString = options.get(SOURCE);
if (sourceString != null) instance = lookup(sourceString);
if (instance == null) instance = DEFAULT;
if (sourceString != null)
instance = lookup(sourceString);
if (instance == null)
instance = DEFAULT;
context.put(sourceKey, instance);
}
return instance;
}

public final String name;

private static final Map<String,Source> tab = new HashMap<>();
private static final Map<String, Source> tab = new HashMap<>();
static {
for (Source s : values()) {
tab.put(s.name, s);
Expand Down Expand Up @@ -165,34 +171,52 @@ public boolean isSupported() {

public Target requiredTarget() {

if (this.compareTo(JDK17) >= 0) return Target.JDK1_17;
if (this.compareTo(JDK16) >= 0) return Target.JDK1_16;
if (this.compareTo(JDK15) >= 0) return Target.JDK1_15;
if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
if (this.compareTo(JDK17) >= 0)
return Target.JDK1_17;
if (this.compareTo(JDK16) >= 0)
return Target.JDK1_16;
if (this.compareTo(JDK15) >= 0)
return Target.JDK1_15;
if (this.compareTo(JDK14) >= 0)
return Target.JDK1_14;
if (this.compareTo(JDK13) >= 0)
return Target.JDK1_13;
if (this.compareTo(JDK12) >= 0)
return Target.JDK1_12;
if (this.compareTo(JDK11) >= 0)
return Target.JDK1_11;
if (this.compareTo(JDK10) >= 0)
return Target.JDK1_10;
if (this.compareTo(JDK9) >= 0)
return Target.JDK1_9;
if (this.compareTo(JDK8) >= 0)
return Target.JDK1_8;
if (this.compareTo(JDK7) >= 0)
return Target.JDK1_7;
if (this.compareTo(JDK6) >= 0)
return Target.JDK1_6;
if (this.compareTo(JDK5) >= 0)
return Target.JDK1_5;
if (this.compareTo(JDK1_4) >= 0)
return Target.JDK1_4;
return Target.JDK1_1;

}

/**
* Models a feature of the Java programming language. Each feature can be associated with a
* minimum source level, a maximum source level and a diagnostic fragment describing the feature,
* which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
* Models a feature of the Java programming language. Each feature can be
* associated with a
* minimum source level, a maximum source level and a diagnostic fragment
* describing the feature,
* which is used to generate error messages of the kind
* {@code feature XYZ not supported in source N}.
*/
public enum Feature {

DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
MODULES(JDK9, Fragments.FeatureModules, DiagKind.PLURAL),
EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES(JDK9, Fragments.FeatureVarInTryWithResources, DiagKind.PLURAL),
EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES(JDK9, Fragments.FeatureVarInTryWithResources,
DiagKind.PLURAL),
DEPRECATION_ON_IMPORT(MIN, JDK8),
POLY(JDK8),
LAMBDA(JDK8, Fragments.FeatureLambda, DiagKind.PLURAL),
Expand Down Expand Up @@ -260,6 +284,9 @@ enum DiagKind {
}

public boolean allowedInSource(Source source) {
if (optFragment == Fragments.FeatureModules) {
return false;
}
return source.compareTo(minLevel) >= 0 &&
source.compareTo(maxLevel) <= 0;
}
Expand All @@ -276,57 +303,57 @@ public Fragment nameFragment() {

public Fragment fragment(String sourceName) {
Assert.checkNonNull(optFragment);
return optKind == DiagKind.NORMAL ?
Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
return optKind == DiagKind.NORMAL
? Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name)
: Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
}

public Error error(String sourceName) {
Assert.checkNonNull(optFragment);
return optKind == DiagKind.NORMAL ?
Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
return optKind == DiagKind.NORMAL
? Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name)
: Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
}
}

public static SourceVersion toSourceVersion(Source source) {

switch(source) {
case JDK1_2:
return RELEASE_2;
case JDK1_3:
return RELEASE_3;
case JDK1_4:
return RELEASE_4;
case JDK5:
return RELEASE_5;
case JDK6:
return RELEASE_6;
case JDK7:
return RELEASE_7;
case JDK8:
return RELEASE_8;
case JDK9:
return RELEASE_9;
case JDK10:
return RELEASE_10;
case JDK11:
return RELEASE_11;
case JDK12:
return RELEASE_12;
case JDK13:
return RELEASE_13;
case JDK14:
return RELEASE_14;
case JDK15:
return RELEASE_15;
case JDK16:
return RELEASE_16;
case JDK17:
return RELEASE_17;

default:
return null;
switch (source) {
case JDK1_2:
return RELEASE_2;
case JDK1_3:
return RELEASE_3;
case JDK1_4:
return RELEASE_4;
case JDK5:
return RELEASE_5;
case JDK6:
return RELEASE_6;
case JDK7:
return RELEASE_7;
case JDK8:
return RELEASE_8;
case JDK9:
return RELEASE_9;
case JDK10:
return RELEASE_10;
case JDK11:
return RELEASE_11;
case JDK12:
return RELEASE_12;
case JDK13:
return RELEASE_13;
case JDK14:
return RELEASE_14;
case JDK15:
return RELEASE_15;
case JDK16:
return RELEASE_16;
case JDK17:
return RELEASE_17;

default:
return null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ public static JRTIndex instance(Context context) {
}

public static boolean isAvailable() {
try {
FileSystems.getFileSystem(URI.create("jrt:/"));
return true;
} catch (ProviderNotFoundException | FileSystemNotFoundException e) {
return false;
}
// AndroidIDE changed: No JRT file system on Android
return false;
}


Expand Down
Loading

0 comments on commit 2b84123

Please sign in to comment.