From 5aa918931e58bb2957d796003f4a7d5a39ccd4cf Mon Sep 17 00:00:00 2001 From: Charles Morehead Date: Sun, 9 Mar 2014 17:02:28 -0400 Subject: [PATCH] Check in first pass of a "-f" option for ProblemsCommand which filters warnings (not errors) to those for the current file. --- .../command/problems/ProblemsCommand.java | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/org.eclim.core/java/org/eclim/plugin/core/command/problems/ProblemsCommand.java b/org.eclim.core/java/org/eclim/plugin/core/command/problems/ProblemsCommand.java index a4ed3c6fd..6684fa6f5 100644 --- a/org.eclim.core/java/org/eclim/plugin/core/command/problems/ProblemsCommand.java +++ b/org.eclim.core/java/org/eclim/plugin/core/command/problems/ProblemsCommand.java @@ -17,6 +17,7 @@ package org.eclim.plugin.core.command.problems; import java.io.File; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -75,6 +76,7 @@ name = "problems", options = "REQUIRED p project ARG," + + "OPTIONAL f file ARG," + // specifying a file only filters warnings "OPTIONAL e errors NOARG" ) public class ProblemsCommand @@ -91,8 +93,12 @@ public Object execute(CommandLine commandLine) String name = commandLine.getValue(Options.PROJECT_OPTION); boolean errorsOnly = commandLine.hasOption(Options.ERRORS_OPTION); + String fileName = commandLine.getValue(Options.FILE_OPTION); IProject project = ProjectUtils.getProject(name); + File fileFilter = (fileName != null) ? + getCanonicalFile(new File(fileName)) : null; + ContentGeneratorDescriptor descriptor = MarkerSupportRegistry.getInstance().getDefaultContentGenDescriptor(); @@ -126,6 +132,11 @@ public Object execute(CommandLine commandLine) CollectionUtils.addAll(projects, project.getReferencedProjects()); CollectionUtils.addAll(projects, project.getReferencingProjects()); + // store the last path and use it to know when to update the + // current file. Only used if we are filtering warnings by file. + String lastPath = null; + File fileCur = null; + Method getMarker = null; for (Object markerEntry : markers){ if (getMarker == null){ @@ -155,6 +166,23 @@ public Object execute(CommandLine commandLine) continue; } + + + String path = resource.getLocation().toOSString().replace('\\', '/'); + File file = new File(path); + + if ((severity != IMarker.SEVERITY_ERROR) && fileFilter != null) { + // try to minimize the number of calls to getCanonicalFile + // by only updating fileCur when the path has changed + if ((fileCur == null) || !path.equals(lastPath)) { + fileCur = getCanonicalFile(file); + lastPath = path; + } + if (!fileFilter.equals(fileCur)) { + continue; + } + } + int offset = attributes.containsKey("charStart") ? ((Integer)attributes.get("charStart")).intValue() : 1; int line = attributes.containsKey("lineNumber") ? @@ -162,8 +190,8 @@ public Object execute(CommandLine commandLine) int[] pos = {1, 1}; String message = (String)attributes.get("message"); - String path = resource.getLocation().toOSString().replace('\\', '/'); - File file = new File(path); + + if (file.isFile() && file.exists() && offset > 0){ pos = FileUtils.offsetToLineColumn(path, offset); } @@ -184,6 +212,25 @@ public Object execute(CommandLine commandLine) return problems; } + /** Attempt to get the canonical file for the specified path. If + * the canonical File cannot be obtained, returns the absolute + * file, instead. + * + * @param path the path to get the canonical file of + * + * @return the canonical file or, failing that, the absolute file + */ + private File getCanonicalFile(File file) { + File result; + try { + result = file.getCanonicalFile(); + } + catch (IOException e) { + result = file.getAbsoluteFile(); + } + return result; + } + private void waitOnBuild() { CorePlugin plugin = CorePlugin.getDefault(); @@ -217,8 +264,8 @@ public ProblemComparator(IProject project) /** * {@inheritDoc} - * @see Comparator#compare(T,T) - */ + * @see Comparator#compare(T,T) + */ public int compare(Error e1, Error e2) { String ef1 = e1.getFilename();