use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor in project dsl-devkit by dsldevkit.
the class DefaultCheckQuickfixProvider method getResolutions.
/**
* Invokes quickfix methods and creates IssueResolution objects. Both "native" quickfix providers and Check
* quickfix providers are considered.
* <p>
* {@inheritDoc}
*/
@Override
protected List<IssueResolution> getResolutions(final Issue issue, final List<Method> fixMethods) {
final ICoreIssueResolutionAcceptor coreIssueResolutionAcceptor = coreIssueResolutionAcceptorProvider.get();
final IssueResolutionAcceptor defaultIssueResolutionAcceptor = issueResolutionAcceptorProvider.get();
for (Method fixMethod : fixMethods) {
try {
fixMethod.setAccessible(true);
if (Lists.newArrayList(getClass().getMethods()).contains(fixMethod)) {
if (fixMethod.getAnnotation(CoreFix.class) != null) {
fixMethod.invoke(this, issue, coreIssueResolutionAcceptor);
} else {
// Legacy code: executes native quickfixes
fixMethod.invoke(this, issue, defaultIssueResolutionAcceptor);
}
} else {
// the fix method
for (final ICoreQuickfixProvider p : getProviders()) {
if (Iterables.contains(methodsForProvider(p, issue.getCode()), fixMethod)) {
fixMethod.invoke(p, issue, coreIssueResolutionAcceptor);
}
}
}
// CHECKSTYLE:OFF
} catch (Exception e) {
// CHECKSTYLE:ON
// $NON-NLS-1$
LOGGER.error("Error executing fix method", e);
}
}
final Iterable<IssueResolution> allResolutions = Iterables.concat(Lists.transform(coreIssueResolutionAcceptor.getIssueResolutions(), new Function<CoreIssueResolution, IssueResolution>() {
@Override
public IssueResolution apply(final CoreIssueResolution from) {
return new IssueResolutionWrapper(from);
}
}), defaultIssueResolutionAcceptor.getIssueResolutions());
return Lists.newArrayList(allResolutions);
}
use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor in project xtext-eclipse by eclipse.
the class DeclarativeQuickfixProviderTest method testHasResolutions2.
@Test
public void testHasResolutions2() throws Exception {
AbstractDeclarativeQuickfixProvider provider = new AbstractDeclarativeQuickfixProvider() {
@Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE)
@Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE2)
public void signature(Issue i, IssueResolutionAcceptor acceptor) {
}
};
assertFalse(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE + 1));
assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE2));
}
use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor in project xtext-eclipse by eclipse.
the class DeclarativeQuickfixProviderTest method testHasResolutions3.
@Test
public void testHasResolutions3() throws Exception {
AbstractDeclarativeQuickfixProvider provider = new AbstractDeclarativeQuickfixProvider() {
@Fixes({ @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE), @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE2) })
public void signature(Issue i, IssueResolutionAcceptor acceptor) {
}
};
assertFalse(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE + 1));
assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE2));
}
use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor in project xtext-eclipse by eclipse.
the class DeclarativeQuickfixProviderTest method testHasResolutions.
@Test
public void testHasResolutions() throws Exception {
AbstractDeclarativeQuickfixProvider provider = new AbstractDeclarativeQuickfixProvider() {
@Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE)
public void signature(Issue i, IssueResolutionAcceptor acceptor) {
}
};
assertFalse(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE + 1));
assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
}
use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method removeUnusedPrivateMember.
@Fix(IssueCodes.UNUSED_PRIVATE_MEMBER)
public void removeUnusedPrivateMember(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 member.";
String description = "Remove the unused private member.";
String image = "delete_edit.png";
acceptor.accept(issue, label, description, image, new IModification() {
@Override
public void apply(IModificationContext context) throws Exception {
final IXtextDocument document = context.getXtextDocument();
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
final EObject element = state.getEObject(issue.getUriToProblem().fragment());
final ICompositeNode elementNode = NodeModelUtils.findActualNodeFor(element);
final Position elementPosition = new Position(elementNode.getOffset(), elementNode.getLength());
document.addPosition(elementPosition);
if (element instanceof XtendField) {
final JvmField field = associations.getJvmField((XtendField) element);
final List<Position> assignments = EcoreUtil2.eAllContentsAsList(element.eResource()).stream().filter(XAssignment.class::isInstance).map(XAssignment.class::cast).filter(assignment -> field == assignment.getFeature()).map(assignment -> {
final ICompositeNode assignmentNode = NodeModelUtils.findActualNodeFor(assignment);
final int offset = assignmentNode.getOffset();
final XExpression assignmentValue = assignment.getValue();
int length = assignmentNode.getLength();
if (expressionHelper.hasSideEffects(assignmentValue)) {
length -= NodeModelUtils.findActualNodeFor(assignmentValue).getLength();
}
return new Position(offset, length);
}).collect(Collectors.toList());
for (final Position assignment : assignments) {
document.addPosition(assignment);
}
for (final Position assignment : assignments) {
document.replace(assignment.getOffset(), assignment.getLength(), "");
}
}
document.replace(elementPosition.getOffset(), elementPosition.getLength(), "");
}
});
organizeImportsHandler.doOrganizeImports(document);
}
});
}
Aggregations