org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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();
							}
						}
					}
				}
			}));
}
 
Example #2
Source File: IssueResolutionAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification) {
	IModification modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification);
	issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue),
			modificationWrapper));
}
 
Example #3
Source File: IssueResolutionAcceptor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.4
 */
public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification, int relevance) {
	IModification modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification);
	issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue),
			modificationWrapper, relevance));
}