mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
Unify compiler options, set level to Java 7
Does not guarantee support for all Java 7 features (only some), but warns about lambdas not being available. Lambdas are not supported, because they make ANTLR angry. Fixes #4034
This commit is contained in:
@@ -216,8 +216,7 @@ public class ASTGenerator {
|
||||
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
|
||||
parser.setCompilerOptions(options);
|
||||
compilationUnit = (CompilationUnit) parser.createAST(null);
|
||||
} else {
|
||||
|
||||
@@ -387,12 +387,7 @@ public class ErrorCheckerService {
|
||||
|
||||
parser.setSource(sourceCodeArray);
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
|
||||
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
|
||||
parser.setCompilerOptions(options);
|
||||
parser.setCompilerOptions(COMPILER_OPTIONS);
|
||||
parser.setStatementsRecovery(true);
|
||||
|
||||
result.compilationUnit = (CompilationUnit) parser.createAST(null);
|
||||
@@ -419,12 +414,7 @@ public class ErrorCheckerService {
|
||||
|
||||
parser.setSource(sourceCodeArray);
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
|
||||
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
|
||||
parser.setCompilerOptions(options);
|
||||
parser.setCompilerOptions(COMPILER_OPTIONS);
|
||||
parser.setStatementsRecovery(true);
|
||||
|
||||
result.compilationUnit = (CompilationUnit) parser.createAST(null);
|
||||
@@ -453,13 +443,8 @@ public class ErrorCheckerService {
|
||||
loadCompClass = false;
|
||||
}
|
||||
|
||||
|
||||
if (compilerSettings == null) {
|
||||
prepareCompilerSetting();
|
||||
}
|
||||
|
||||
problems = compileAndReturnProblems(className, sourceCode,
|
||||
compilerSettings, classLoader);
|
||||
COMPILER_OPTIONS, classLoader);
|
||||
} catch (Exception e) {
|
||||
System.err.println("compileCheck() problem." + e);
|
||||
e.printStackTrace();
|
||||
@@ -815,29 +800,32 @@ public class ErrorCheckerService {
|
||||
return true;
|
||||
}
|
||||
|
||||
static final Map<String, String> COMPILER_OPTIONS;
|
||||
static {
|
||||
Map<String, String> compilerOptions = new HashMap<>();
|
||||
|
||||
/** Options for the JDT Compiler */
|
||||
protected Map<String, String> compilerSettings;
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, compilerOptions);
|
||||
|
||||
final String[] generate = {
|
||||
JavaCore.COMPILER_LINE_NUMBER_ATTR,
|
||||
JavaCore.COMPILER_SOURCE_FILE_ATTR
|
||||
};
|
||||
|
||||
/** Set compiler options for JDT Compiler */
|
||||
protected void prepareCompilerSetting() {
|
||||
compilerSettings = new HashMap<>();
|
||||
final String[] ignore = {
|
||||
JavaCore.COMPILER_PB_UNUSED_IMPORT,
|
||||
JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION,
|
||||
JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE,
|
||||
JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION
|
||||
};
|
||||
|
||||
compilerSettings.put(CompilerOptions.OPTION_LineNumberAttribute,
|
||||
CompilerOptions.GENERATE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_SourceFileAttribute,
|
||||
CompilerOptions.GENERATE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_Source,
|
||||
CompilerOptions.VERSION_1_8);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportUnusedImport,
|
||||
CompilerOptions.IGNORE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportMissingSerialVersion,
|
||||
CompilerOptions.IGNORE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportRawTypeReference,
|
||||
CompilerOptions.IGNORE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation,
|
||||
CompilerOptions.IGNORE);
|
||||
final String[] warn = {
|
||||
};
|
||||
|
||||
for (String s : generate) compilerOptions.put(s, JavaCore.GENERATE);
|
||||
for (String s : ignore) compilerOptions.put(s, JavaCore.IGNORE);
|
||||
for (String s : warn) compilerOptions.put(s, JavaCore.WARNING);
|
||||
|
||||
COMPILER_OPTIONS = Collections.unmodifiableMap(compilerOptions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.dom.AST;
|
||||
import org.eclipse.jdt.core.dom.ASTParser;
|
||||
import org.eclipse.jdt.core.dom.ASTVisitor;
|
||||
@@ -76,12 +74,7 @@ public class XQPreprocessor {
|
||||
parser.setSource(doc.get().toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
|
||||
parser.setCompilerOptions(options);
|
||||
parser.setCompilerOptions(ErrorCheckerService.COMPILER_OPTIONS);
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
cu.recordModifications();
|
||||
rewrite = ASTRewrite.create(cu.getAST());
|
||||
@@ -90,9 +83,7 @@ public class XQPreprocessor {
|
||||
TextEdit edits = cu.rewrite(doc, null);
|
||||
try {
|
||||
edits.apply(doc);
|
||||
} catch (MalformedTreeException e) {
|
||||
e.printStackTrace();
|
||||
} catch (BadLocationException e) {
|
||||
} catch (MalformedTreeException | BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return doc.get();
|
||||
|
||||
Reference in New Issue
Block a user