use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-eclipse by eclipse.
the class XtextGrammarQuickfixProvider method fixInvalidMetaModelName.
@Fix(INVALID_METAMODEL_NAME)
public void fixInvalidMetaModelName(final Issue issue, IssueResolutionAcceptor acceptor) {
final String metaModelName = issue.getData()[0];
acceptor.accept(issue, "Fix metamodel name '" + metaModelName + "'", "Fix metamodel name '" + metaModelName + "'", NULL_QUICKFIX_IMAGE, new IModification() {
@Override
public void apply(IModificationContext context) throws Exception {
context.getXtextDocument().replace(issue.getOffset(), issue.getLength(), Strings.toFirstLower(metaModelName));
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification 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.model.edit.IModification 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.model.edit.IModification 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;
}
});
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModification in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newXtendAnnotationQuickfix.
protected void newXtendAnnotationQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
String packageDescription = getPackageDescription(explicitPackage);
issueResolutionAcceptor.accept(issue, "Create Xtend annotation '" + typeName + "'" + packageDescription, "Opens the new Xtend annotation wizard to create the type '" + typeName + "'" + packageDescription, "xtend_file.png", new IModification() {
@Override
public void apply(/* @Nullable */
IModificationContext context) throws Exception {
runAsyncInDisplayThread(new Runnable() {
@Override
public void run() {
NewElementWizard newXtendAnnotationWizard = newXtendAnnotationWizardProvider.get();
WizardDialog dialog = createWizardDialog(newXtendAnnotationWizard);
NewXtendAnnotationWizardPage page = (NewXtendAnnotationWizardPage) newXtendAnnotationWizard.getStartingPage();
configureWizardPage(page, resource.getURI(), typeName, explicitPackage);
dialog.open();
}
});
}
});
}
Aggregations