Some readability improvements for #230.

This commit is contained in:
A Pottinger
2021-07-25 20:29:15 -07:00
parent 75dbfc5090
commit 8a23a838bc
3 changed files with 46 additions and 18 deletions

View File

@@ -110,15 +110,7 @@ class ErrorChecker {
List<Problem> cuProblems = iproblems.stream()
// Filter Warnings if they are not enabled
.filter(iproblem -> !(iproblem.isWarning() && !JavaMode.warningsEnabled))
// Hide a useless error which is produced when a line ends with
// an identifier without a semicolon. "Missing a semicolon" is
// also produced and is preferred over this one.
// (Syntax error, insert ":: IdentifierOrNew" to complete Expression)
// See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=405780
.filter(iproblem -> !iproblem.getMessage()
.contains("Syntax error, insert \":: IdentifierOrNew\""))
.filter(iproblem -> !iproblem.getMessage()
.contains("must be defined in its own file"))
.filter(iproblem -> !(isIgnorableProblem(iproblem)))
// Transform into our Problems
.map(iproblem -> {
JavaProblem p = convertIProblem(iproblem, ps);
@@ -155,6 +147,38 @@ class ErrorChecker {
}
/**
* Determine if a problem can be suppressed from the user.
*
* <p>
* Determine if one can ignore an errors where an ignorable error is one
* "fixed" in later pipeline steps but can make JDT angry or do not actually
* cause issues when reaching javac.
* </p>
*
* @return True if ignoreable and false otherwise.
*/
static private boolean isIgnorableProblem(IProblem iproblem) {
String message = iproblem.getMessage();
// Hide a useless error which is produced when a line ends with
// an identifier without a semicolon. "Missing a semicolon" is
// also produced and is preferred over this one.
// (Syntax error, insert ":: IdentifierOrNew" to complete Expression)
// See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=405780
boolean ignorable = message.contains(
"Syntax error, insert \":: IdentifierOrNew\""
);
// It's ok if the file names do not line up during preprocessing.
ignorable = ignorable || message.contains(
"must be defined in its own file"
);
return ignorable;
}
static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps) {
SketchInterval in = ps.mapJavaToSketch(iproblem);
if (in != SketchInterval.BEFORE_START) {

View File

@@ -483,6 +483,7 @@ public class PreprocService {
OffsetMapper parsableMapper = toParsable.getMapper();
// Create intermediate AST for advanced preprocessing
// Wait on .java tabs due to speed since they don't go through preproc.
CompileResults parseableCompile = compileInMemory(
parsableStage,
className,
@@ -496,13 +497,14 @@ public class PreprocService {
toCompilable.addAll(SourceUtil.preprocessAST(parsableCU));
// Transform code to compilable state
// Again, wait on .java tabs due to speed since they don't go through
// the preprocessor.
String compilableStage = toCompilable.apply();
OffsetMapper compilableMapper = toCompilable.getMapper();
char[] compilableStageChars = compilableStage.toCharArray();
// Create compilable AST to get syntax problems
CompileResults compileableCompile = compileInMemory(
compilableStageChars,
compilableStage,
className,
result.classPathArray,
false
@@ -514,7 +516,8 @@ public class PreprocService {
Arrays.stream(compilableCU.getProblems()).anyMatch(IProblem::isError);
// Generate bindings after getting problems - avoids
// 'missing type' errors when there are syntax problems
// 'missing type' errors when there are syntax problems.
// Introduce .java tabs here for type resolution.
CompileResults bindingsCompile;
if (javaFiles.size() == 0) {
bindingsCompile = compileInMemory(
@@ -599,6 +602,7 @@ public class PreprocService {
String className, String[] classPathArray,
List<JavaSketchCode> javaFiles, boolean resolveBindings) {
ProcessingASTRequester astRequester;
List<Path> temporaryFilesList = new ArrayList<>();
Map<String, Integer> javaFileMapping = new HashMap<>();
@@ -625,12 +629,12 @@ public class PreprocService {
}
// Compile
ProcessingASTRequester processingRequester = new ProcessingASTRequester();
astRequester = new ProcessingASTRequester(mainSource);
parser.createASTs(
temporaryFilesArray,
null,
new String[] {},
processingRequester,
astRequester,
null
);
@@ -639,8 +643,8 @@ public class PreprocService {
// Return
return new CompileResults(
processingRequester.getCompilationUnit(),
processingRequester.getProblems(),
astRequester.getMainCompilationUnit(),
astRequester.getProblems(),
javaFileMapping
);
}

View File

@@ -81,8 +81,8 @@ public class PreprocSketch {
javaFileMapping.get(originalFile),
iproblem.getSourceStart(),
iproblem.getSourceEnd() + 1,
iproblem.getSourceStart(), // Is outside sketch code
iproblem.getSourceEnd() + 1 // Is outside sketch code
iproblem.getSourceStart(), // Is outside main sketch code
iproblem.getSourceEnd() + 1 // Is outside main sketch code
);
} else {
return mapJavaToSketch(