use of org.eclipse.xtext.ui.editor.quickfix.Fix in project xtext-eclipse by eclipse.
the class StatemachineQuickfixProvider method capitalizeName.
@Fix(StatemachineValidator.INVALID_NAME)
public void capitalizeName(final Issue issue, final IssueResolutionAcceptor acceptor) {
String _firstLower = StringExtensions.toFirstLower(IterableExtensions.<String>head(((Iterable<String>) Conversions.doWrapArray(issue.getData()))));
String _plus = ("Change to \'" + _firstLower);
String _plus_1 = (_plus + "\'.");
String _firstLower_1 = StringExtensions.toFirstLower(IterableExtensions.<String>head(((Iterable<String>) Conversions.doWrapArray(issue.getData()))));
String _plus_2 = ("Change to \'" + _firstLower_1);
String _plus_3 = (_plus_2 + "\'.");
final IModification _function = (IModificationContext it) -> {
final String firstLetter = it.getXtextDocument().get((issue.getOffset()).intValue(), 1);
it.getXtextDocument().replace((issue.getOffset()).intValue(), 1, firstLetter.toLowerCase());
};
acceptor.accept(issue, _plus_1, _plus_3, "upcase.png", _function);
}
use of org.eclipse.xtext.ui.editor.quickfix.Fix in project xtext-eclipse by eclipse.
the class ArithmeticsQuickfixProvider method normalize.
@Fix(ArithmeticsValidator.NORMALIZABLE)
public void normalize(final Issue issue, final IssueResolutionAcceptor acceptor) {
final String string = issue.getData()[0];
final IModification _function = (IModificationContext it) -> {
it.getXtextDocument().replace((issue.getOffset()).intValue(), (issue.getLength()).intValue(), string);
};
acceptor.accept(issue, ("Replace with " + string), (("Replace expression with \'" + string) + "\'"), "upcase.png", _function);
}
use of org.eclipse.xtext.ui.editor.quickfix.Fix 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;
}
};
}
use of org.eclipse.xtext.ui.editor.quickfix.Fix in project dsl-devkit by dsldevkit.
the class CheckQuickfixProvider method fixIllegalDefaultSeverity.
/**
* Fixes an illegally set default severity. The default severity must be within given severity range.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE)
public void fixIllegalDefaultSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) {
if (issue.getData() != null) {
for (final String severityProposal : issue.getData()) {
final String label = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_LABEL, severityProposal);
final String descn = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_DESCN, severityProposal);
acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
IXtextDocument xtextDocument = context.getXtextDocument();
xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal);
}
});
}
}
}
use of org.eclipse.xtext.ui.editor.quickfix.Fix in project dsl-devkit by dsldevkit.
the class FormatQuickfixProvider method setOverride.
/**
* Semantic quickfix setting the override flag for a rule.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(FormatJavaValidator.OVERRIDE_MISSING_CODE)
public void setOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Set override", "Set override flag.", null, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(final XtextResource state) {
Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
rule.setOverride(true);
return null;
}
});
}
});
}
Aggregations