Java Code Examples for org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor#acceptMulti()

The following examples show how to use org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor#acceptMulti() . 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: QuickfixCrossrefTestLanguageQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Fix(QuickfixCrossrefTestLanguageValidator.BAD_NAME_IN_SUBELEMENTS)
public void fixBadNames(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.acceptMulti(issue, "Fix Bad Names", "Fix Bad Names", null, (Element main, ICompositeModificationContext<Element> ctx) -> {
		ctx.addModification(main.eContainer(), c -> {
			List<Element> siblings = (List<Element>) main.eContainer().eGet(main.eContainmentFeature());
			int index = siblings.indexOf(main);
			Element newEle = QuickfixCrossrefFactory.eINSTANCE.createElement();
			newEle.setName("newElement");
			siblings.add(index, newEle);
		});
		for (String s : issue.getData()[0].split(";")) {
			EObject ele = main.eResource().getEObject(s);
			Assert.assertTrue(ele instanceof Element);
			ctx.addModification((Element) ele, e -> {
				e.setName("goodname");
			});
		}
	});
}
 
Example 2
Source File: QuickfixCrossrefTestLanguageQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(QuickfixCrossrefTestLanguageValidator.MULTIFIXABLE_ISSUE)
public void addDocumentation(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.acceptMulti(issue, "Multi fix", "Multi fix", null, (Element main, ICompositeModificationContext<Element> ctx) -> {
		ctx.setUpdateCrossReferences(false);
		ctx.addModification(main, (obj) -> {
			main.setDoc("Better documentation");
		});
	});
}
 
Example 3
Source File: QuickfixCrossrefTestLanguageQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(QuickfixCrossrefTestLanguageValidator.FIXABLE)
public void renameFixable(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.acceptMulti(issue, "rename fixable", "rename fixable", null, (Element main, ICompositeModificationContext<Element> ctx) -> {
		ctx.setUpdateCrossReferences(false);
		ctx.addModification(main, (obj) -> {
			main.setName("fixedName");
		});
	});
}
 
Example 4
Source File: XtextGrammarQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(EMPTY_ENUM_LITERAL)
public void fixEmptyEnumLiteral(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.acceptMulti(issue, "Fix empty enum literal", "Fix empty enum literal", NULL_QUICKFIX_IMAGE,
			(EObject element) -> {
				EnumLiteralDeclaration enumLiteralDeclaration = (EnumLiteralDeclaration) element;
				Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
				keyword.setValue(enumLiteralDeclaration.getEnumLiteral().getName().toLowerCase());
				enumLiteralDeclaration.setLiteral(keyword);
			});
}
 
Example 5
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.EQUALS_WITH_NULL)
public void fixEqualsWithNull(final Issue issue, IssueResolutionAcceptor acceptor) {
	String message = "Replace '==' with '===' and '!=' with '!=='";
	acceptor.acceptMulti(issue, message, message, null, new ICompositeModification<XBinaryOperation>() {
		@Override
		public void apply(XBinaryOperation element, ICompositeModificationContext<XBinaryOperation> context) {
			context.setUpdateCrossReferences(false);
			context.setUpdateRelatedFiles(false);
			context.addModification(element, (object) -> {
				replaceOperator(object, OperatorMapping.EQUALS, OperatorMapping.TRIPLE_EQUALS);
				replaceOperator(object, OperatorMapping.NOT_EQUALS, OperatorMapping.TRIPLE_NOT_EQUALS);
			});
		}
	});
}
 
Example 6
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.UNUSED_LOCAL_VARIABLE)
public void removeUnusedLocalVariable(final Issue issue, IssueResolutionAcceptor acceptor) {
	// use the same label, description and image
	// to be able to use the quickfixes (issue resolution) in batch mode
	String label = "Remove local variable.";
	String description = "Remove the unused local variable.";
	String image = "delete_edit.png";
	acceptor.acceptMulti(issue, label, description, image, (ICompositeModification<XVariableDeclaration>) (element, ctx) -> {
		ctx.setUpdateCrossReferences(false);
		ctx.setUpdateRelatedFiles(false);
		ctx.addModification(element, ele -> EcoreUtil.remove(ele));
	});
}
 
Example 7
Source File: DotQuickfixProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void provideMultiQuickfix(String invalidValue, String validValue,
		String suffix, Issue issue, IssueResolutionAcceptor acceptor,
		IMultiModification<EObject> multiModification) {
	acceptor.acceptMulti(issue,
			"Replace '" + invalidValue + "' with '" + validValue //$NON-NLS-1$ //$NON-NLS-2$
					+ "'.", //$NON-NLS-1$
			"Use valid '" + validValue + "' instead of invalid '" //$NON-NLS-1$ //$NON-NLS-2$
					+ invalidValue + "' " + suffix + ".", //$NON-NLS-1$ //$NON-NLS-2$
			null, multiModification);
}
 
Example 8
Source File: XtendQuickfixProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.INVALID_RETURN_TYPE_IN_CASE_OF_JUNIT_ANNOTATION)
public void changeJUnitMethodReturnTypeToVoid(final Issue issue, IssueResolutionAcceptor acceptor) {
	// use the same label, description and image
	// to be able to use the quickfixes (issue resolution) in batch mode
	String label = "Change return type to void.";
	String description = "Change the return type to void to be recognized by JUnit.";
	String image = "fix_indent.gif";
	acceptor.acceptMulti(issue, label, description, image, (ICompositeModification<XtendFunction>) (element, ctx) -> {
		ctx.setUpdateCrossReferences(false);
		ctx.setUpdateRelatedFiles(false);
		ctx.addModification(element, ele -> ele.setReturnType(typeReferences.getTypeForName(Void.TYPE, ele)));
	});
}
 
Example 9
Source File: QuickfixCrossrefTestLanguageQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Fix(QuickfixCrossrefTestLanguageValidator.MULTIFIXABLE_ISSUE_2)
public void addDocumentation2(final Issue issue, IssueResolutionAcceptor acceptor) {
	acceptor.acceptMulti(issue, "Multi fix 2", "Multi fix 2", null, (Element eObj) -> {
		eObj.setDoc("not " + eObj.getDoc());
	});
}