Search in sources :

Example 1 with ICoreQuickfixProvider

use of com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider in project dsl-devkit by dsldevkit.

the class DefaultCheckQuickfixProvider method collectMethods.

/**
 * Gets <em>all</em> provider methods by examining the Check quickfix extension point's registered clients. Includes eventual
 * "fix methods" of current class.
 * <p>
 * {@inheritDoc}
 */
@Override
protected Iterable<Method> collectMethods(final Class<? extends AbstractDeclarativeQuickfixProvider> clazz, final String issueCode) {
    if (!issueCodeToQuickfixMethods.containsKey(issueCode)) {
        // Adds this class' methods: this class potentially is a quickfix provider
        Iterable<Method> result = Lists.newArrayList(clazz.getMethods());
        for (final ICoreQuickfixProvider provider : getProviders()) {
            result = Iterables.concat(result, methodsForProvider(provider, issueCode));
        }
        issueCodeToQuickfixMethods.put(issueCode, Iterables.filter(result, getFixMethodPredicate(issueCode)));
    }
    return issueCodeToQuickfixMethods.get(issueCode);
}
Also used : ICoreQuickfixProvider(com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider) Method(java.lang.reflect.Method)

Example 2 with ICoreQuickfixProvider

use of com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider in project dsl-devkit by dsldevkit.

the class DefaultCheckQuickfixProvider method getResolutions.

/**
 * Invokes quickfix methods and creates IssueResolution objects. Both "native" quickfix providers and Check
 * quickfix providers are considered.
 * <p>
 * {@inheritDoc}
 */
@Override
protected List<IssueResolution> getResolutions(final Issue issue, final List<Method> fixMethods) {
    final ICoreIssueResolutionAcceptor coreIssueResolutionAcceptor = coreIssueResolutionAcceptorProvider.get();
    final IssueResolutionAcceptor defaultIssueResolutionAcceptor = issueResolutionAcceptorProvider.get();
    for (Method fixMethod : fixMethods) {
        try {
            fixMethod.setAccessible(true);
            if (Lists.newArrayList(getClass().getMethods()).contains(fixMethod)) {
                if (fixMethod.getAnnotation(CoreFix.class) != null) {
                    fixMethod.invoke(this, issue, coreIssueResolutionAcceptor);
                } else {
                    // Legacy code: executes native quickfixes
                    fixMethod.invoke(this, issue, defaultIssueResolutionAcceptor);
                }
            } else {
                // the fix method
                for (final ICoreQuickfixProvider p : getProviders()) {
                    if (Iterables.contains(methodsForProvider(p, issue.getCode()), fixMethod)) {
                        fixMethod.invoke(p, issue, coreIssueResolutionAcceptor);
                    }
                }
            }
        // CHECKSTYLE:OFF
        } catch (Exception e) {
            // CHECKSTYLE:ON
            // $NON-NLS-1$
            LOGGER.error("Error executing fix method", e);
        }
    }
    final Iterable<IssueResolution> allResolutions = Iterables.concat(Lists.transform(coreIssueResolutionAcceptor.getIssueResolutions(), new Function<CoreIssueResolution, IssueResolution>() {

        @Override
        public IssueResolution apply(final CoreIssueResolution from) {
            return new IssueResolutionWrapper(from);
        }
    }), defaultIssueResolutionAcceptor.getIssueResolutions());
    return Lists.newArrayList(allResolutions);
}
Also used : Function(com.google.common.base.Function) CoreIssueResolution(com.avaloq.tools.ddk.check.runtime.quickfix.CoreIssueResolution) ICoreIssueResolutionAcceptor(com.avaloq.tools.ddk.check.runtime.quickfix.ICoreIssueResolutionAcceptor) CoreFix(com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix) ICoreQuickfixProvider(com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider) CoreIssueResolution(com.avaloq.tools.ddk.check.runtime.quickfix.CoreIssueResolution) IssueResolution(org.eclipse.xtext.ui.editor.quickfix.IssueResolution) Method(java.lang.reflect.Method) IssueResolutionAcceptor(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor) ICoreIssueResolutionAcceptor(com.avaloq.tools.ddk.check.runtime.quickfix.ICoreIssueResolutionAcceptor)

Aggregations

ICoreQuickfixProvider (com.avaloq.tools.ddk.check.runtime.quickfix.ICoreQuickfixProvider)2 Method (java.lang.reflect.Method)2 CoreFix (com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix)1 CoreIssueResolution (com.avaloq.tools.ddk.check.runtime.quickfix.CoreIssueResolution)1 ICoreIssueResolutionAcceptor (com.avaloq.tools.ddk.check.runtime.quickfix.ICoreIssueResolutionAcceptor)1 Function (com.google.common.base.Function)1 IssueResolution (org.eclipse.xtext.ui.editor.quickfix.IssueResolution)1 IssueResolutionAcceptor (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor)1