diff --git a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ISourceAnalyzer.java b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ISourceAnalyzer.java index 6468328e48e7b085667b0a1cdc4ddfff018b88aa..2fd1285d433cfedf38d901bc721ea8f3724df3e3 100755 --- a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ISourceAnalyzer.java +++ b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ISourceAnalyzer.java @@ -18,21 +18,22 @@ import org.eclipse.titan.lsp.Interval; * An interface for source code analyzers. * * @author Kristof Szabados + * @author Adam Knapp * */ public interface ISourceAnalyzer { - /** @return the errors from ANTLR 4 lexer and parser */ + /** @return the errors from ANTLR 4 lexer and parser, never returns {@code null} */ List<SyntacticErrorStorage> getErrorStorage(); /** * @return the list of markers created for the parse time found - * unsupported features and bad practices + * unsupported features and bad practices, never returns {@code null} */ List<TITANMarker> getWarnings(); /** * @return the list of markers created for the parse time found - * unsupported features + * unsupported features, never returns {@code null} */ List<TITANMarker> getUnsupportedConstructs(); @@ -46,13 +47,9 @@ public interface ISourceAnalyzer { * Parses the provided elements. If the contents of an editor are to be * parsed, than the file parameter is only used to report the errors to. * - * @param file - * the file to parse, and report the errors to - * @param code - * the contents of an editor, or null. - * - * @exception FileNotFoundException - * if this method fails, the file was not found. + * @param file the file to parse, and report the errors to. + * @param code the contents of an editor, or {@code null}. + * @exception FileNotFoundException if this method fails, the file was not found. * */ void parse(Path file, String code) throws FileNotFoundException; } diff --git a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ProjectSourceSyntacticAnalyzer.java b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ProjectSourceSyntacticAnalyzer.java index d775d9c29e29f48d1d4ef8acba297db3d0a9e116..551d3591da7876ef198696e19f9e4ffb8cc39477 100755 --- a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ProjectSourceSyntacticAnalyzer.java +++ b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ProjectSourceSyntacticAnalyzer.java @@ -566,21 +566,16 @@ public final class ProjectSourceSyntacticAnalyzer { * @return true if it had parse errors */ private boolean processParserErrors(final Path aFile, final ISourceAnalyzer aAnalyzer) { - List<SyntacticErrorStorage> errors = null; - - errors = aAnalyzer.getErrorStorage(); - - if (errors != null) { - for (int i = 0; i < errors.size(); i++) { - // ParserMarkerSupport.createOnTheFlySyntacticMarker(aFile, errors.get(i), IMarker.SEVERITY_ERROR); - SyntacticErrorStorage storage = errors.get(i); - Range range = new Range(new Position(storage.lineNumber - 1, storage.charStart), new Position(storage.lineNumber - 1, storage.charEnd)); - Location location = new Location(aFile.toFile(), range); - location.reportError("Syntax error"); - } + List<SyntacticErrorStorage> errors = aAnalyzer.getErrorStorage(); + for (SyntacticErrorStorage storage : errors) { + // ParserMarkerSupport.createOnTheFlySyntacticMarker(aFile, errors.get(i), IMarker.SEVERITY_ERROR); + Range range = new Range(new Position(storage.lineNumber - 1, storage.charStart), + new Position(storage.lineNumber - 1, storage.charEnd)); + Location location = new Location(aFile.toFile(), range); + location.reportError("Syntax error"); } - return errors != null && !errors.isEmpty(); + return !errors.isEmpty(); } /** @@ -600,7 +595,7 @@ public final class ProjectSourceSyntacticAnalyzer { uptodateFiles.put(file, module.getName()); final List<TITANMarker> unsupportedConstructs = parsedData.getUnsupportedConstructs(); - if (unsupportedConstructs != null && !unsupportedConstructs.isEmpty()) { + if (!unsupportedConstructs.isEmpty()) { unsupportedConstructMap.put(file, unsupportedConstructs); } diff --git a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/asn1parser/ASN1Analyzer.java b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/asn1parser/ASN1Analyzer.java index 9782b85c5a3a6c284a6b636b954e83e8d0a35dd8..1177c95d6642c9b475909af70a5b22705c4b7da5 100755 --- a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/asn1parser/ASN1Analyzer.java +++ b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/asn1parser/ASN1Analyzer.java @@ -15,7 +15,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.nio.file.Path; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -33,6 +33,7 @@ import org.eclipse.titan.lsp.parsers.TITANMarker; * ASN1 Analyzer * @author Kristof Szabados * @author Arpad Lovassy + * @author Adam Knapp */ public class ASN1Analyzer implements ISourceAnalyzer { @@ -45,12 +46,12 @@ public class ASN1Analyzer implements ISourceAnalyzer { @Override public List<TITANMarker> getWarnings() { - return warnings; + return warnings == null ? Collections.emptyList() : warnings; } @Override public List<TITANMarker> getUnsupportedConstructs() { - return unsupportedConstructs; + return unsupportedConstructs == null ? Collections.emptyList() : unsupportedConstructs; } @Override @@ -67,7 +68,7 @@ public class ASN1Analyzer implements ISourceAnalyzer { public List<SyntacticErrorStorage> getErrorStorage() { if (lexerListener == null || parserListener == null) { // the parser was not yet run for some reason. - return new ArrayList<SyntacticErrorStorage>(); + return Collections.emptyList(); } if (!lexerListener.getErrorsStored().isEmpty() && parserListener.getErrorsStored().isEmpty()) { @@ -79,7 +80,7 @@ public class ASN1Analyzer implements ISourceAnalyzer { return lexerListener.getErrorsStored(); } } - return new ArrayList<SyntacticErrorStorage>(); + return Collections.emptyList(); } @Override diff --git a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ttcn3parser/TTCN3Analyzer.java b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ttcn3parser/TTCN3Analyzer.java index bb5f00be1a9b53496a41cbef256c8b650589168e..c7c86bcd3680809eb97b8bf7a05ddf6afee2a7ef 100755 --- a/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ttcn3parser/TTCN3Analyzer.java +++ b/lsp/src/main/java/org/eclipse/titan/lsp/parsers/ttcn3parser/TTCN3Analyzer.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.nio.file.Path; +import java.util.Collections; import java.util.List; import org.antlr.v4.runtime.CharStream; @@ -47,6 +48,7 @@ import org.eclipse.titan.lsp.parsers.TitanParseTreeListener; * * @author Arpad Lovassy * @author Miklos Magyari + * @author Adam Knapp */ public class TTCN3Analyzer implements ISourceAnalyzer { private List<TITANMarker> warningsAndErrors; @@ -62,17 +64,17 @@ public class TTCN3Analyzer implements ISourceAnalyzer { @Override public List<SyntacticErrorStorage> getErrorStorage() { - return mErrorsStored; + return mErrorsStored == null ? Collections.emptyList() : mErrorsStored; } @Override public List<TITANMarker> getWarnings() { - return warningsAndErrors; + return warningsAndErrors == null ? Collections.emptyList() : warningsAndErrors; } @Override public List<TITANMarker> getUnsupportedConstructs() { - return unsupportedConstructs; + return unsupportedConstructs == null ? Collections.emptyList() : unsupportedConstructs; } @Override