Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -155,15 +166,32 @@ 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") ?
((Integer)attributes.get("lineNumber")).intValue() : 1;
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);
}
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down