Search in sources :

Example 1 with WrappingPMDMarker

use of ch.acanda.eclipse.pmd.marker.WrappingPMDMarker in project eclipse-pmd by acanda.

the class ASTQuickFixTestCase method getQuickFix.

@SuppressWarnings("unchecked")
private ASTQuickFix<ASTNode> getQuickFix() {
    try {
        final Type typeArgument = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        final Class<T> quickFixClass = (Class<T>) typeArgument;
        final IMarker marker = mock(IMarker.class);
        when(marker.getAttribute(eq("ruleName"), isA(String.class))).thenReturn(params.rulename.orNull());
        final String markerText = params.source.substring(params.offset, params.offset + params.length);
        if (!markerText.contains("\n")) {
            when(marker.getAttribute(eq("markerText"), isA(String.class))).thenReturn(markerText);
        }
        return (ASTQuickFix<ASTNode>) quickFixClass.getConstructor(PMDMarker.class).newInstance(new WrappingPMDMarker(marker));
    } catch (SecurityException | ReflectiveOperationException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AST(org.eclipse.jdt.core.dom.AST) WrappingPMDMarker(ch.acanda.eclipse.pmd.marker.WrappingPMDMarker) IMarker(org.eclipse.core.resources.IMarker)

Example 2 with WrappingPMDMarker

use of ch.acanda.eclipse.pmd.marker.WrappingPMDMarker in project eclipse-pmd by acanda.

the class TextEditQuickFixTestCase method getQuickFix.

@SuppressWarnings("unchecked")
private ASTRewriteQuickFix<ASTNode> getQuickFix() {
    try {
        final Type typeArgument = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        final Class<T> quickFixClass = (Class<T>) typeArgument;
        final IMarker marker = mock(IMarker.class);
        when(marker.getAttribute(eq("ruleName"), isA(String.class))).thenReturn(params.rulename.orNull());
        final String markerText = params.source.substring(params.offset, params.offset + params.length);
        when(marker.getAttribute(eq("markerText"), isA(String.class))).thenReturn(markerText);
        return (ASTRewriteQuickFix<ASTNode>) quickFixClass.getConstructor(PMDMarker.class).newInstance(new WrappingPMDMarker(marker));
    } catch (SecurityException | ReflectiveOperationException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AST(org.eclipse.jdt.core.dom.AST) WrappingPMDMarker(ch.acanda.eclipse.pmd.marker.WrappingPMDMarker) IMarker(org.eclipse.core.resources.IMarker)

Example 3 with WrappingPMDMarker

use of ch.acanda.eclipse.pmd.marker.WrappingPMDMarker in project eclipse-pmd by acanda.

the class PMDMarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(final IMarker marker) {
    final JavaQuickFixContext context = new JavaQuickFixContext(getCompilerCompliance(marker));
    final ImmutableList<IMarkerResolution> quickFixes = quickFixGenerator.getQuickFixes(new WrappingPMDMarker(marker), context);
    return quickFixes.toArray(new IMarkerResolution[quickFixes.size()]);
}
Also used : IMarkerResolution(org.eclipse.ui.IMarkerResolution) WrappingPMDMarker(ch.acanda.eclipse.pmd.marker.WrappingPMDMarker)

Aggregations

WrappingPMDMarker (ch.acanda.eclipse.pmd.marker.WrappingPMDMarker)3 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 IMarker (org.eclipse.core.resources.IMarker)2 AST (org.eclipse.jdt.core.dom.AST)2 IMarkerResolution (org.eclipse.ui.IMarkerResolution)1