Search in sources :

Example 1 with CoreFix

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

the class DefaultCheckQuickfixProvider method getFixMethodPredicate.

/**
 * Returns a method predicate indicating whether a given method is an executable quickfix method. Both Check
 * quickfix methods and native quickfix methods are considered.
 *
 * @param issueCode
 *          the issue code
 * @return the fix method predicate
 * @see com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix CoreFix annotation
 * @see org.eclipse.xtext.ui.editor.quickfix.Fix Fix annotation
 */
@Override
protected Predicate<Method> getFixMethodPredicate(final String issueCode) {
    return new Predicate<Method>() {

        @Override
        public boolean apply(final Method input) {
            CoreFix coreFixAnnotation = input.getAnnotation(CoreFix.class);
            Fix fixAnnotation = input.getAnnotation(Fix.class);
            if (coreFixAnnotation == null && fixAnnotation == null) {
                // Definitely no candidate
                return false;
            }
            final boolean typesMatch = Void.TYPE == input.getReturnType() && input.getParameterTypes().length == 2 && input.getParameterTypes()[0].isAssignableFrom(Issue.class);
            boolean result;
            if (coreFixAnnotation != null) {
                result = coreFixAnnotation != null && issueCode.equals(coreFixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(CoreIssueResolutionAcceptor.class);
            } else {
                result = fixAnnotation != null && issueCode.equals(fixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(IssueResolutionAcceptor.class);
            }
            return result;
        }
    };
}
Also used : Issue(org.eclipse.xtext.validation.Issue) CoreFix(com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix) CoreFix(com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix) Method(java.lang.reflect.Method) Predicate(com.google.common.base.Predicate)

Aggregations

CoreFix (com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix)1 Predicate (com.google.common.base.Predicate)1 Method (java.lang.reflect.Method)1 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)1 Issue (org.eclipse.xtext.validation.Issue)1