diff options
author | Jan Belle | 2019-03-29 12:51:17 +0000 |
---|---|---|
committer | Jan Belle | 2019-04-02 14:44:14 +0000 |
commit | 8cfabe4a58f5fe3853e30f094a9346af6e10741f (patch) | |
tree | c9bbe83242b61336298626fdb0c04f629ff8a598 /plugins | |
parent | d941d5a98db578e4bff2c284b06a498f1aab1c23 (diff) | |
download | org.eclipse.etrice-8cfabe4a58f5fe3853e30f094a9346af6e10741f.tar.gz org.eclipse.etrice-8cfabe4a58f5fe3853e30f094a9346af6e10741f.tar.xz org.eclipse.etrice-8cfabe4a58f5fe3853e30f094a9346af6e10741f.zip |
[common.ui] Support basic comments in modelpath description file
Bug 545924
Change-Id: I86a344a9820bac6066a879311a600a55b12c839b
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathDescription.java | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathDescription.java b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathDescription.java index 380365055..e784a61aa 100644 --- a/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathDescription.java +++ b/plugins/org.eclipse.etrice.core.common.ui/src/org/eclipse/etrice/core/common/ui/modelpath/ModelPathDescription.java @@ -41,10 +41,13 @@ public class ModelPathDescription { private final List<IFolder> sourceDirectories; private final List<IProject> projectDependencies; + private final List<IMarker> problemMarkers; - private ModelPathDescription(List<IFolder> sourceDirectories, List<IProject> projectDependencies) { + private ModelPathDescription(List<IFolder> sourceDirectories, List<IProject> projectDependencies, List<IMarker> problemMarkers) { this.sourceDirectories = sourceDirectories; this.projectDependencies = projectDependencies; + + this.problemMarkers = problemMarkers; } /** @@ -62,6 +65,13 @@ public class ModelPathDescription { } /** + * @return the list of problem markers + */ + public List<IMarker> getProblemMarkers() { + return problemMarkers; + } + + /** * Loads the modelpath description from a file. * * @param file the file to load from @@ -93,6 +103,7 @@ public class ModelPathDescription { private IWorkspaceRoot root; private List<IFolder> srcDirs; private List<IProject> projects; + private List<IMarker> problemMarkers; private int lineNumber; public ModelPathDescriptionLoader(IFile file) { @@ -101,6 +112,7 @@ public class ModelPathDescription { root = ResourcesPlugin.getWorkspace().getRoot(); srcDirs = new ArrayList<>(); projects = new ArrayList<>(); + problemMarkers = new ArrayList<IMarker>(); lineNumber = 0; } @@ -109,11 +121,14 @@ public class ModelPathDescription { try(BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()))) { for(String line = reader.readLine(); line != null; line = reader.readLine(), lineNumber++) { + line = trimComments(line); parseLine(line); } } - return new ModelPathDescription(Collections.unmodifiableList(srcDirs), Collections.unmodifiableList(projects)); + return new ModelPathDescription(Collections.unmodifiableList(srcDirs), + Collections.unmodifiableList(projects), + Collections.unmodifiableList(problemMarkers)); } private void parseLine(String line) throws CoreException { @@ -130,42 +145,59 @@ public class ModelPathDescription { parseProject(str); break; default: - createProblemMarker(IMarker.SEVERITY_ERROR, "unexpected keyword " + keyword); + addProblemMarker(IMarker.SEVERITY_ERROR, "unexpected keyword " + keyword); } } } + private String trimComments(String line) { + int index = line.indexOf("//"); + if(index != -1) { + line = line.substring(0, index); + } + return line; + } + private void parseSrcDir(String str) throws CoreException { - if(Path.EMPTY.isValidPath(str)) { - IFolder dir = project.getFolder(str); - if(!dir.exists()) { - createProblemMarker(IMarker.SEVERITY_WARNING, "directory " + dir.getFullPath() + " doesn't exist"); - } - srcDirs.add(dir); + if(str.isEmpty()) { + addProblemMarker(IMarker.SEVERITY_ERROR, "directory path is missing"); + return; } - else { - createProblemMarker(IMarker.SEVERITY_ERROR, str + " isn't a valid path"); + if(!Path.EMPTY.isValidPath(str)) { + addProblemMarker(IMarker.SEVERITY_ERROR, str + " isn't a valid path"); + return; + } + + IFolder dir = project.getFolder(str); + if(!dir.exists()) { + addProblemMarker(IMarker.SEVERITY_WARNING, "directory " + dir.getFullPath() + " doesn't exist"); } + srcDirs.add(dir); } private void parseProject(String str) throws CoreException { - if(Path.EMPTY.isValidSegment(str)) { - IProject project = root.getProject(str); - if(!project.isAccessible()) { - createProblemMarker(IMarker.SEVERITY_WARNING, "project " + project.getName() + " doesn't exist"); - } - projects.add(project); + if(str.isEmpty()) { + addProblemMarker(IMarker.SEVERITY_ERROR, "project name is missing"); + return; + } + if(!Path.EMPTY.isValidSegment(str)) { + addProblemMarker(IMarker.SEVERITY_ERROR, str + " isn't a valid project name"); + return; } - else { - createProblemMarker(IMarker.SEVERITY_ERROR, str + " isn't a valid project name"); + + IProject project = root.getProject(str); + if(!project.isAccessible()) { + addProblemMarker(IMarker.SEVERITY_WARNING, "project " + project.getName() + " doesn't exist"); } + projects.add(project); } - private void createProblemMarker(int severity, String message) throws CoreException { + private void addProblemMarker(int severity, String message) throws CoreException { IMarker marker = file.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.SEVERITY, severity); marker.setAttribute(IMarker.LINE_NUMBER, lineNumber + 1); marker.setAttribute(IMarker.MESSAGE, message); + problemMarkers.add(marker); } } }
\ No newline at end of file |