use of org.eclipse.xtext.ui.editor.model.edit.IModificationContext in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newLocalVariableQuickfix.
protected void newLocalVariableQuickfix(final String variableName, XAbstractFeatureCall call, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
LightweightTypeReference variableType = getNewMemberType(call);
final StringBuilderBasedAppendable localVarDescriptionBuilder = new StringBuilderBasedAppendable();
localVarDescriptionBuilder.append("...").newLine();
final String defaultValueLiteral = getDefaultValueLiteral(variableType);
localVarDescriptionBuilder.append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
localVarDescriptionBuilder.newLine().append("...");
issueResolutionAcceptor.accept(issue, "Create local variable '" + variableName + "'", localVarDescriptionBuilder.toString(), "fix_local_var.png", new SemanticModificationWrapper(issue.getUriToProblem(), new ISemanticModification() {
@Override
public void apply(/* @Nullable */
final EObject element, /* @Nullable */
final IModificationContext context) throws Exception {
if (element != null) {
XtendMember xtendMember = EcoreUtil2.getContainerOfType(element, XtendMember.class);
if (xtendMember != null) {
int offset = getFirstOffsetOfKeyword(xtendMember, "{");
IXtextDocument xtextDocument = context.getXtextDocument();
if (offset != -1 && xtextDocument != null) {
final ReplacingAppendable appendable = appendableFactory.create(xtextDocument, (XtextResource) element.eResource(), offset, 0, new OptionalParameters() {
{
baseIndentationLevel = 1;
}
});
appendable.increaseIndentation().newLine().append("val ").append(variableName).append(" = ").append(defaultValueLiteral);
appendable.commitChanges();
}
}
}
}
}));
}
use of org.eclipse.xtext.ui.editor.model.edit.IModificationContext in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newXtendInterfaceQuickfix.
protected void newXtendInterfaceQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
String packageDescription = getPackageDescription(explicitPackage);
issueResolutionAcceptor.accept(issue, "Create Xtend interface '" + typeName + "'" + packageDescription, "Opens the new Xtend interface 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 newXtendInterfaceWizard = newXtendInterfaceWizardProvider.get();
WizardDialog dialog = createWizardDialog(newXtendInterfaceWizard);
NewXtendInterfaceWizardPage page = (NewXtendInterfaceWizardPage) newXtendInterfaceWizard.getStartingPage();
configureWizardPage(page, resource.getURI(), typeName, explicitPackage);
dialog.open();
}
});
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModificationContext in project xtext-xtend by eclipse.
the class CreateXtendTypeQuickfixes method newXtendClassQuickfix.
protected void newXtendClassQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) {
String packageDescription = getPackageDescription(explicitPackage);
issueResolutionAcceptor.accept(issue, "Create Xtend class '" + typeName + "'" + packageDescription, "Opens the new Xtend class 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 newXtendClassWizard = newXtendClassWizardProvider.get();
WizardDialog dialog = createWizardDialog(newXtendClassWizard);
NewXtendClassWizardPage page = (NewXtendClassWizardPage) newXtendClassWizard.getStartingPage();
configureWizardPage(page, resource.getURI(), typeName, explicitPackage);
dialog.open();
}
});
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModificationContext in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method specifyTypeExplicitly.
@Fix(IssueCodes.API_TYPE_INFERENCE)
public void specifyTypeExplicitly(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Infer type", "Infer type", null, new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
EStructuralFeature featureAfterType = null;
JvmIdentifiableElement jvmElement = null;
if (element instanceof XtendFunction) {
XtendFunction function = (XtendFunction) element;
if (function.getCreateExtensionInfo() == null) {
featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__NAME;
} else {
featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__CREATE_EXTENSION_INFO;
}
jvmElement = associations.getDirectlyInferredOperation((XtendFunction) element);
} else if (element instanceof XtendField) {
featureAfterType = XtendPackage.Literals.XTEND_FIELD__NAME;
jvmElement = associations.getJvmField((XtendField) element);
}
if (jvmElement != null) {
LightweightTypeReference type = batchTypeResolver.resolveTypes(element).getActualType(jvmElement);
INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(element, featureAfterType), null);
if (node == null) {
throw new IllegalStateException("Could not determine node for " + element);
}
if (type == null) {
throw new IllegalStateException("Could not determine type for " + element);
}
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), node.getOffset(), 0);
appendable.append(type);
appendable.append(" ");
appendable.commitChanges();
}
}
});
}
use of org.eclipse.xtext.ui.editor.model.edit.IModificationContext in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method implementAbstractMethods.
@Fix(IssueCodes.CLASS_MUST_BE_ABSTRACT)
public void implementAbstractMethods(final Issue issue, IssueResolutionAcceptor acceptor) {
doOverrideMethods(issue, acceptor, "Add unimplemented methods");
acceptor.accept(issue, "Make class abstract", "Make class abstract", "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
internalDoAddAbstractKeyword(element, context);
}
});
}
Aggregations