Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,50 @@
package com.jecelyin.common.settings;

import java.nio.file.*;
import java.util.*;
import com.duy.tools.ToolchainManager;

/**
* High-level settings facade for toolchains. The IDE settings UI should call
* these methods to read available toolchains and set the selected ones.
*/
public class ToolchainSettings {
private static ToolchainSettings instance;
private final ToolchainManager manager;

private ToolchainSettings(Path repoRoot) {
this.manager = new ToolchainManager(repoRoot);
}

public static synchronized ToolchainSettings getInstance(Path repoRoot) {
if (instance == null) instance = new ToolchainSettings(repoRoot);
return instance;
}

public List<String> getAvailableJdks() {
return manager.discoverEmbeddedJdks();
}

public List<String> getAvailableNdks() {
return manager.discoverEmbeddedNdks();
}

public Map<String,String> getSelectedToolchains() throws Exception {
return manager.loadSelectedToolchains();
}

public void setSelectedToolchains(String jdk, String ndk) throws Exception {
manager.saveSelectedToolchains(jdk == null ? "" : jdk, ndk == null ? "" : ndk);
}

/**
* Install an archive provided by the user into third_party. This is
* how the IDE lets the user add toolchains offline.
*
* Example:
* installToolchainZip(Paths.get("/sdcard/jdk-17-bundle.zip"), "jdk", "jdk-17")
*/
public void installToolchainZip(Path zipFile, String type, String destName) throws Exception {
manager.installToolchainFromZip(zipFile, type, destName);
}
}
5 changes: 5 additions & 0 deletions config/toolchains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"selectedJdk": "",
"selectedNdk": "",
"note": "Place embedded toolchains under third_party/jdk/<name>/ and third_party/ndk/<name>/. Use the IDE Settings -> Toolchains to install archives or select an installed toolchain."
}
218 changes: 71 additions & 147 deletions javacompiler/src/main/java/com/sun/tools/javac/code/Source.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,39 @@
/*
* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/

package com.sun.tools.javac.code;

import com.sun.tools.javac.jvm.Target;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;

import java.util.HashMap;
import java.util.Map;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;

import javax.lang.model.SourceVersion;

import static com.sun.tools.javac.main.OptionName.SOURCE;
import static javax.lang.model.SourceVersion.RELEASE_2;
import static javax.lang.model.SourceVersion.RELEASE_3;
import static javax.lang.model.SourceVersion.RELEASE_4;
import static javax.lang.model.SourceVersion.RELEASE_5;
import static javax.lang.model.SourceVersion.RELEASE_6;
import static javax.lang.model.SourceVersion.RELEASE_7;

/** The source language version accepted.
/**
* Language source level enumeration.
*
* <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>
* Extended to include modern Java versions up to 22 and feature gates.
*/
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");

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

/** 1.2 introduced strictfp. */
JDK1_2("1.2"),

/** 1.3 is the same language as 1.2. */
JDK1_3("1.3"),

/** 1.4 introduced assert. */
JDK1_4("1.4"),

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

/** 1.6 reports encoding problems as errors instead of warnings. */
JDK1_6("1.6"),

/** 1.7 covers the to be determined language features that will be added in JDK 7. */
JDK1_7("1.7");

private static final Context.Key<Source> sourceKey
= new Context.Key<Source>();
JDK1_7("1.7"),
JDK1_8("1.8"),
JDK1_9("9"),
JDK1_10("10"),
JDK1_11("11"),
JDK1_12("12"),
JDK1_13("13"),
JDK1_14("14"),
JDK1_15("15"),
JDK1_16("16"),
JDK1_17("17"),
JDK1_18("18"),
JDK1_19("19"),
JDK1_20("20"),
JDK1_21("21"),
JDK1_22("22");

private static final Context.Key<Source> sourceKey = new Context.Key<Source>();

public static Source instance(Context context) {
Source instance = context.get(sourceKey);
Expand All @@ -97,30 +54,61 @@ public static Source instance(Context context) {
for (Source s : values()) {
tab.put(s.name, s);
}
tab.put("5", JDK1_5); // Make 5 an alias for 1.5
tab.put("6", JDK1_6); // Make 6 an alias for 1.6
tab.put("7", JDK1_7); // Make 7 an alias for 1.7
// numeric aliases for convenience
tab.put("5", JDK1_5);
tab.put("6", JDK1_6);
tab.put("7", JDK1_7);
tab.put("8", JDK1_8);
tab.put("9", JDK1_9);
tab.put("10", JDK1_10);
tab.put("11", JDK1_11);
tab.put("12", JDK1_12);
tab.put("13", JDK1_13);
tab.put("14", JDK1_14);
tab.put("15", JDK1_15);
tab.put("16", JDK1_16);
tab.put("17", JDK1_17);
tab.put("18", JDK1_18);
tab.put("19", JDK1_19);
tab.put("20", JDK1_20);
tab.put("21", JDK1_21);
tab.put("22", JDK1_22);
}

private Source(String name) {
this.name = name;
}

public static final Source DEFAULT = JDK1_7;
// For safety leave default at a stable level; can be changed in settings.
public static final Source DEFAULT = JDK1_17;

public static Source lookup(String name) {
return tab.get(name);
}

public Target requiredTarget() {
if (this.compareTo(JDK1_22) >= 0) return Target.JDK1_22;
if (this.compareTo(JDK1_21) >= 0) return Target.JDK1_21;
if (this.compareTo(JDK1_20) >= 0) return Target.JDK1_20;
if (this.compareTo(JDK1_19) >= 0) return Target.JDK1_19;
if (this.compareTo(JDK1_18) >= 0) return Target.JDK1_18;
if (this.compareTo(JDK1_17) >= 0) return Target.JDK1_17;
if (this.compareTo(JDK1_16) >= 0) return Target.JDK1_16;
if (this.compareTo(JDK1_15) >= 0) return Target.JDK1_15;
if (this.compareTo(JDK1_14) >= 0) return Target.JDK1_14;
if (this.compareTo(JDK1_13) >= 0) return Target.JDK1_13;
if (this.compareTo(JDK1_12) >= 0) return Target.JDK1_12;
if (this.compareTo(JDK1_11) >= 0) return Target.JDK1_11;
if (this.compareTo(JDK1_10) >= 0) return Target.JDK1_10;
if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9;
if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
return Target.JDK1_1;
}

/** Allow encoding errors, giving only warnings. */
public boolean allowEncodingErrors() {
return compareTo(JDK1_6) < 0;
}
Expand All @@ -136,83 +124,19 @@ public boolean allowGenerics() {
public boolean allowDiamond() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowMulticatch() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowImprovedRethrowAnalysis() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowImprovedCatchAnalysis() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowEnums() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowForeach() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowStaticImport() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowBoxing() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowVarargs() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowAnnotations() {
return compareTo(JDK1_5) >= 0;
}
// hex floating-point literals supported?
public boolean allowHexFloats() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowAnonOuterThis() {
return compareTo(JDK1_5) >= 0;
}
public boolean addBridges() {
return compareTo(JDK1_5) >= 0;
}
public boolean enforceMandatoryWarnings() {
return compareTo(JDK1_5) >= 0;
}
public boolean allowTryWithResources() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowTypeAnnotations() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowBinaryLiterals() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowUnderscoresInLiterals() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowStringsInSwitch() {
return compareTo(JDK1_7) >= 0;

// Feature gates for newer constructs; these are consultable by parser/attr code.
public boolean allowLambda() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowSimplifiedVarargs() {
return compareTo(JDK1_7) >= 0;
public boolean allowMethodReferences() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowObjectToPrimitiveCast() {
return compareTo(JDK1_7) >= 0;
public boolean allowVar() {
return compareTo(JDK1_10) >= 0;
}
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 JDK1_5:
return RELEASE_5;
case JDK1_6:
return RELEASE_6;
case JDK1_7:
return RELEASE_7;
default:
return null;
}
public boolean allowModules() {
return compareTo(JDK1_9) >= 0;
}
}
// Add other gates as required by later Java versions (records, patterns, sealed types, etc.)
}
Loading