1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

fixed usage of improper attribute for problem id, added marker groupping support

This commit is contained in:
Alena Laskavaia 2010-08-13 02:18:56 +00:00
parent d535cea64c
commit 992cf58f31
10 changed files with 150 additions and 29 deletions

View file

@ -42,7 +42,7 @@
name="category">
</attribute>
<attribute
name="org.eclipse.core.resources.problemmarker">
name="id">
</attribute>
<persistent
value="true">

View file

@ -21,6 +21,9 @@ import org.eclipse.core.runtime.CoreException;
* @since 2.0
*/
public interface ICodanProblemMarker {
public static final String ID = "id"; //$NON-NLS-1$
public static final String CATEGORY = "category"; //$NON-NLS-1$
/**
* @return problem location
*/

View file

@ -140,7 +140,7 @@ public class CodanMarkerProblemReporter extends AbstractProblemReporter
Collection<IProblem> problems = reg.getRefProblems(checker);
for (int i = 0; i < markers.length; i++) {
IMarker m = markers[i];
String id = m.getAttribute(IMarker.PROBLEM, ""); //$NON-NLS-1$
String id = m.getAttribute(ICodanProblemMarker.ID, ""); //$NON-NLS-1$
for (Iterator<IProblem> iterator = problems.iterator(); iterator
.hasNext();) {
IProblem iProblem = iterator.next();

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.codan.internal.core.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.cdt.codan.core.model.IProblem;
@ -54,23 +55,55 @@ public class CodanProblemCategory implements IProblemCategory, Cloneable {
if (object instanceof IProblemCategory) {
IProblemCategory cat = (IProblemCategory) object;
IProblem found = findProblem(cat, id);
if (found != null) return found;
if (found != null)
return found;
} else if (object instanceof IProblem) {
IProblem p = (IProblem) object;
if (p.getId().equals(id)) return p;
if (p.getId().equals(id))
return p;
}
}
return null;
}
/**
* Find all categories in which problem with id present
*
* @param c - root category
* @param id - problem id
* @return list of categories
*/
public static IProblemCategory[] findProblemCategories(IProblemCategory c,
String id) {
ArrayList<IProblemCategory> list = new ArrayList<IProblemCategory>();
Object[] children = c.getChildren();
for (Object object : children) {
if (object instanceof IProblemCategory) {
IProblemCategory cat = (IProblemCategory) object;
IProblemCategory[] found = findProblemCategories(cat, id);
if (found.length > 0) {
list.addAll(Arrays.asList(found));
}
} else if (object instanceof IProblem) {
IProblem p = (IProblem) object;
if (p.getId().equals(id)) {
list.add(c);
}
}
}
return list.toArray(new IProblemCategory[list.size()]);
}
public static IProblemCategory findCategory(IProblemCategory cat, String id) {
if (cat.getId().equals(id)) return cat;
if (cat.getId().equals(id))
return cat;
Object[] children = cat.getChildren();
for (Object object : children) {
if (object instanceof IProblemCategory) {
IProblemCategory cat2 = (IProblemCategory) object;
IProblemCategory found = findCategory(cat2, id);
if (found != null) return found;
if (found != null)
return found;
}
}
return null;
@ -86,7 +119,8 @@ public class CodanProblemCategory implements IProblemCategory, Cloneable {
try {
CodanProblemCategory clone = (CodanProblemCategory) super.clone();
clone.list = new ArrayList<IProblemElement>();
for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator.hasNext();) {
for (Iterator<IProblemElement> iterator = this.list.iterator(); iterator
.hasNext();) {
IProblemElement child = iterator.next();
clone.list.add((IProblemElement) child.clone());
}

View file

@ -20,7 +20,9 @@ import java.util.Properties;
import org.eclipse.cdt.codan.core.model.CodanSeverity;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemCategory;
import org.eclipse.cdt.codan.core.model.IProblemLocation;
import org.eclipse.cdt.codan.core.model.IProblemProfile;
import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
@ -95,12 +97,16 @@ public class CodanProblemMarker implements ICodanProblemMarker {
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
marker.setAttribute(IMarker.PROBLEM, problem.getId());
marker.setAttribute(ID, problem.getId());
marker.setAttribute(IMarker.CHAR_END, loc.getEndingChar());
marker.setAttribute(IMarker.CHAR_START, loc.getStartingChar());
marker.setAttribute("org.eclipse.cdt.core.problem", 42); //$NON-NLS-1$
String propArgs = serializeArgs(args);
marker.setAttribute(PROBLEM_ARGS, propArgs);
IProblemCategory[] cats = CodanProblemCategory.findProblemCategories(
getProfile(file).getRoot(), problem.getId());
String cat = cats.length > 0 ? cats[0].getId() : ""; //$NON-NLS-1$
marker.setAttribute(CATEGORY, cat);
return marker;
}
@ -192,7 +198,7 @@ public class CodanProblemMarker implements ICodanProblemMarker {
*/
public static String getProblemId(IMarker marker) {
try {
return (String) marker.getAttribute(IMarker.PROBLEM);
return (String) marker.getAttribute(ICodanProblemMarker.ID);
} catch (CoreException e) {
return null;
}
@ -240,14 +246,23 @@ public class CodanProblemMarker implements ICodanProblemMarker {
if (id == null)
return null;
IResource resource = marker.getResource();
CodanProblem problem = (CodanProblem) ((CodanProblem) CheckersRegistry
.getInstance().getResourceProfile(resource).findProblem(id))
.clone();
IProblemProfile profile = getProfile(resource);
CodanProblem problem = (CodanProblem) ((CodanProblem) profile.findProblem(id)).clone();
CodanSeverity sev = getSeverity(marker);
problem.setSeverity(sev);
return problem;
}
/**
* @param resource
* @return
*/
public static IProblemProfile getProfile(IResource resource) {
IProblemProfile profile = CheckersRegistry.getInstance()
.getResourceProfile(resource);
return profile;
}
/**
* @param marker
* @return location object using marker attributes

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
@ -63,7 +64,7 @@ public abstract class AbstractCodanCQuickFixProcessor implements IQuickFixProces
IMarker m = markers[i];
int start = m.getAttribute(IMarker.CHAR_START, -1);
if (start==loc.getOffset()) {
String id = m.getAttribute(IMarker.PROBLEM,""); //$NON-NLS-1$
String id = m.getAttribute(ICodanProblemMarker.ID,""); //$NON-NLS-1$
return getCorrections(context, id, m);
}
}

View file

@ -116,4 +116,58 @@
markerType="org.eclipse.cdt.core.problem">
</markerResolutionGenerator>
</extension>
<extension
point="org.eclipse.ui.ide.markerSupport">
<markerTypeCategory
name="Code Analysis Problem">
<markerTypeReference
id="org.eclipse.cdt.codan.core.codanProblem">
</markerTypeReference>
</markerTypeCategory>
<markerGrouping
id="org.eclipse.cdt.codan.ui.markerGrouping"
label="Codan Problem Type">
</markerGrouping>
<markerAttributeGrouping
attribute="category"
defaultGroupingEntry="org.eclipse.cdt.codan.ui.markerGroupingUnknown"
markerType="org.eclipse.cdt.codan.core.codanProblem">
<markerAttributeMapping
markerGroupingEntry="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
value="org.eclipse.cdt.codan.core.categories.ProgrammingProblems">
</markerAttributeMapping>
<markerAttributeMapping
markerGroupingEntry="org.eclipse.cdt.codan.core.categories.CompilerErrors"
value="org.eclipse.cdt.codan.core.categories.CompilerErrors">
</markerAttributeMapping>
<markerAttributeMapping
markerGroupingEntry="org.eclipse.cdt.codan.core.categories.CodeStyle"
value="org.eclipse.cdt.codan.core.categories.CodeStyle">
</markerAttributeMapping>
</markerAttributeGrouping>
<markerGroupingEntry
id="org.eclipse.cdt.codan.ui.markerGroupingUnknown"
label="Unknown"
markerGrouping="org.eclipse.cdt.codan.ui.markerGrouping"
priority="90">
</markerGroupingEntry>
<markerGroupingEntry
id="org.eclipse.cdt.codan.core.categories.ProgrammingProblems"
label="Programming Problems"
markerGrouping="org.eclipse.cdt.codan.ui.markerGrouping"
priority="10">
</markerGroupingEntry>
<markerGroupingEntry
id="org.eclipse.cdt.codan.core.categories.CompilerErrors"
label="Compiler Errors"
markerGrouping="org.eclipse.cdt.codan.ui.markerGrouping"
priority="2">
</markerGroupingEntry>
<markerGroupingEntry
id="org.eclipse.cdt.codan.core.categories.CodeStyle"
label="Coding Style"
markerGrouping="org.eclipse.cdt.codan.ui.markerGrouping"
priority="80">
</markerGroupingEntry>
</extension>
</plugin>

View file

@ -19,6 +19,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution;
import org.eclipse.core.resources.IMarker;
@ -50,7 +51,7 @@ public class CodanProblemMarkerResolutionGenerator implements
if (resolutionsLoaded == false) {
readExtensions();
}
String id = marker.getAttribute(IMarker.PROBLEM, null);
String id = marker.getAttribute(ICodanProblemMarker.ID, null);
if (id == null && resolutions.get(null) == null)
return new IMarkerResolution[0];
String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.codan.internal.ui.views;
import java.util.Collection;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.cdt.codan.ui.AbstractCodanProblemDetailsProvider;
import org.eclipse.cdt.codan.ui.CodanEditorUtility;
@ -48,7 +49,8 @@ public class ProblemDetails extends ViewPart {
*/
private Link message;
/**
* Control for problem description which can include links to help or web-sites with extra info
* Control for problem description which can include links to help or
* web-sites with extra info
*/
private Link description;
private GenericCodanProblemDetailsProvider genProvider = new GenericCodanProblemDetailsProvider();
@ -64,6 +66,7 @@ public class ProblemDetails extends ViewPart {
* This is a callback that will allow us
* to create the area and initialize it.
*/
@Override
public void createPartControl(Composite parent) {
final String problemsViewId = "org.eclipse.ui.views.ProblemView"; //$NON-NLS-1$
area = new Composite(parent, SWT.NONE);
@ -81,10 +84,11 @@ public class ProblemDetails extends ViewPart {
// link file format example "file:/tmp/file.c#42", 42 is the line number
if (link.startsWith("file:")) { //$NON-NLS-1$
try {
CodanEditorUtility.openInEditor(link, curProvider.getMarker().getResource());
} catch (PartInitException e1) {
CodanUIActivator.log(e1);
}
CodanEditorUtility.openInEditor(link, curProvider
.getMarker().getResource());
} catch (PartInitException e1) {
CodanUIActivator.log(e1);
}
return;
}
if (link.startsWith("help:")) { //$NON-NLS-1$
@ -99,9 +103,11 @@ public class ProblemDetails extends ViewPart {
description = new Link(area, SWT.WRAP);
description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
description.addSelectionListener(linkSelAdapter);
ISelectionService ser = (ISelectionService) getSite().getService(ISelectionService.class);
ISelectionService ser = (ISelectionService) getSite().getService(
ISelectionService.class);
ser.addSelectionListener(new ISelectionListener() {
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
public void selectionChanged(IWorkbenchPart part,
ISelection selection) {
if (part.getSite().getId().equals(problemsViewId)) {
processSelection(selection);
}
@ -115,10 +121,12 @@ public class ProblemDetails extends ViewPart {
if (selection == null || selection.isEmpty())
return;
if (selection instanceof IStructuredSelection) {
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
Object firstElement = ((IStructuredSelection) selection)
.getFirstElement();
IMarker marker = null;
if (firstElement instanceof IAdaptable) {
marker = (IMarker) ((IAdaptable) firstElement).getAdapter(IMarker.class);
marker = (IMarker) ((IAdaptable) firstElement)
.getAdapter(IMarker.class);
} else if (firstElement instanceof IMarker) {
marker = (IMarker) firstElement;
}
@ -130,8 +138,9 @@ public class ProblemDetails extends ViewPart {
}
private void queryProviders(IMarker marker) {
String id = marker.getAttribute(IMarker.PROBLEM, "id"); //$NON-NLS-1$
Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions.getProviders(id);
String id = marker.getAttribute(ICodanProblemMarker.ID, "id"); //$NON-NLS-1$
Collection<AbstractCodanProblemDetailsProvider> providers = ProblemDetailsExtensions
.getProviders(id);
for (AbstractCodanProblemDetailsProvider provider : providers) {
synchronized (provider) {
provider.setMarker(marker);
@ -148,10 +157,12 @@ public class ProblemDetails extends ViewPart {
private void applyProvider(AbstractCodanProblemDetailsProvider provider) {
curProvider = provider;
setTextSafe(message, provider, provider.getStyledProblemMessage());
setTextSafe(description, provider, provider.getStyledProblemDescription());
setTextSafe(description, provider,
provider.getStyledProblemDescription());
}
protected void setTextSafe(Link control, AbstractCodanProblemDetailsProvider provider, String text) {
protected void setTextSafe(Link control,
AbstractCodanProblemDetailsProvider provider, String text) {
try {
control.setText(text);
} catch (Exception e) {
@ -163,6 +174,7 @@ public class ProblemDetails extends ViewPart {
/**
* Passing the focus request to the area's control.
*/
@Override
public void setFocus() {
message.setFocus();
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.codan.ui;
import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.internal.core.model.CodanProblemMarker;
import org.eclipse.core.resources.IMarker;
@ -63,7 +64,7 @@ public abstract class AbstractCodanProblemDetailsProvider {
* @return
*/
protected String getProblemId() {
String id = marker.getAttribute(IMarker.PROBLEM, (String) null);
String id = marker.getAttribute(ICodanProblemMarker.ID, (String) null);
return id;
}