mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Code streamlining.
This commit is contained in:
parent
e923b9a3c9
commit
4a37d52c1c
1 changed files with 25 additions and 24 deletions
|
@ -10,6 +10,11 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core.model;
|
package org.eclipse.cdt.codan.internal.core.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
import org.eclipse.cdt.codan.core.CodanCorePlugin;
|
||||||
import org.eclipse.cdt.codan.core.CodanRuntime;
|
import org.eclipse.cdt.codan.core.CodanRuntime;
|
||||||
import org.eclipse.cdt.codan.core.model.AbstractProblemReporter;
|
import org.eclipse.cdt.codan.core.model.AbstractProblemReporter;
|
||||||
|
@ -28,16 +33,11 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Problem reported that created eclipse markers
|
* Problem reported that created eclipse markers
|
||||||
*/
|
*/
|
||||||
public class CodanMarkerProblemReporter extends AbstractProblemReporter implements IProblemReporterPersistent,
|
public class CodanMarkerProblemReporter extends AbstractProblemReporter implements
|
||||||
IProblemReporterSessionPersistent {
|
IProblemReporterPersistent, IProblemReporterSessionPersistent {
|
||||||
private IResource resource;
|
private IResource resource;
|
||||||
private IChecker checker;
|
private IChecker checker;
|
||||||
private ArrayList<ICodanProblemMarker> toAdd = new ArrayList<ICodanProblemMarker>();
|
private ArrayList<ICodanProblemMarker> toAdd = new ArrayList<ICodanProblemMarker>();
|
||||||
|
@ -99,7 +99,8 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter implemen
|
||||||
|
|
||||||
public void deleteAllProblems() {
|
public void deleteAllProblems() {
|
||||||
try {
|
try {
|
||||||
ResourcesPlugin.getWorkspace().getRoot().deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
|
ResourcesPlugin.getWorkspace().getRoot().deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE,
|
||||||
|
true, IResource.DEPTH_INFINITE);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CodanCorePlugin.log(e);
|
CodanCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
|
@ -125,12 +126,14 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter implemen
|
||||||
Collection<IMarker> res = new ArrayList<IMarker>();
|
Collection<IMarker> res = new ArrayList<IMarker>();
|
||||||
IMarker[] markers;
|
IMarker[] markers;
|
||||||
if (resource.exists()) {
|
if (resource.exists()) {
|
||||||
markers = resource.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
|
markers = resource.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, true,
|
||||||
|
IResource.DEPTH_INFINITE);
|
||||||
} else {
|
} else {
|
||||||
if (resource.getProject() == null || !resource.getProject().isAccessible())
|
if (resource.getProject() == null || !resource.getProject().isAccessible())
|
||||||
return res;
|
return res;
|
||||||
// non resource markers attached to a project itself
|
// non resource markers attached to a project itself
|
||||||
markers = resource.getProject().findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, true, IResource.DEPTH_ZERO);
|
markers = resource.getProject().findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, true,
|
||||||
|
IResource.DEPTH_ZERO);
|
||||||
}
|
}
|
||||||
ICheckersRegistry reg = CodanRuntime.getInstance().getCheckersRegistry();
|
ICheckersRegistry reg = CodanRuntime.getInstance().getCheckersRegistry();
|
||||||
Collection<IProblem> problems = reg.getRefProblems(checker);
|
Collection<IProblem> problems = reg.getRefProblems(checker);
|
||||||
|
@ -235,7 +238,7 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter implemen
|
||||||
ICodanProblemMarker cm = iterator.next();
|
ICodanProblemMarker cm = iterator.next();
|
||||||
if (mcm.equals(cm))
|
if (mcm.equals(cm))
|
||||||
return cm;
|
return cm;
|
||||||
if (similarTo(mcm, cm)) {
|
if (markersAreSimilar(mcm, cm)) {
|
||||||
cand.add(cm);
|
cand.add(cm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,17 +248,17 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mcm
|
* @param marker1
|
||||||
* @param cm
|
* @param marker2
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean similarTo(ICodanProblemMarker mcm, ICodanProblemMarker other) {
|
private boolean markersAreSimilar(ICodanProblemMarker marker1, ICodanProblemMarker marker2) {
|
||||||
if (!mcm.getProblem().getId().equals(other.getProblem().getId()))
|
if (!marker1.getProblem().getId().equals(marker2.getProblem().getId()))
|
||||||
return false;
|
return false;
|
||||||
if (!Arrays.equals(mcm.getArgs(), other.getArgs()))
|
if (!Arrays.equals(marker1.getArgs(), marker2.getArgs()))
|
||||||
return false;
|
return false;
|
||||||
IProblemLocation loc1 = mcm.getLocation();
|
IProblemLocation loc1 = marker1.getLocation();
|
||||||
IProblemLocation loc2 = other.getLocation();
|
IProblemLocation loc2 = marker2.getLocation();
|
||||||
if (!loc1.getFile().equals(loc2.getFile()))
|
if (!loc1.getFile().equals(loc2.getFile()))
|
||||||
return false;
|
return false;
|
||||||
if (Math.abs(loc1.getLineNumber() - loc2.getLineNumber()) > 2)
|
if (Math.abs(loc1.getLineNumber() - loc2.getLineNumber()) > 2)
|
||||||
|
@ -266,13 +269,11 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter implemen
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see org.eclipse.cdt.codan.core.model.IProblemReporterSessionPersistent#
|
* @see IProblemReporterSessionPersistent#deleteProblems(boolean)
|
||||||
* deleteProblems(boolean)
|
|
||||||
*/
|
*/
|
||||||
public void deleteProblems(boolean all) {
|
public void deleteProblems(boolean all) {
|
||||||
if (all == false)
|
if (all)
|
||||||
deleteProblems(resource, checker);
|
|
||||||
else
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
deleteProblems(resource, checker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue