Java Code Examples for org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor#accept()
The following examples show how to use
org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor#accept() .
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: ActionAddModification.java From sarl with Apache License 2.0 | 6 votes |
/** Create the quick fix if needed. * * <p>The user data contains the name of the container type, and the name of the new action. * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) { final String[] data = issue.getData(); if (data != null && data.length > 1) { final String actionName = data[1]; final ActionAddModification modification = new ActionAddModification(actionName); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, MessageFormat.format(Messages.SARLQuickfixProvider_2, actionName), MessageFormat.format(Messages.SARLQuickfixProvider_3, actionName), JavaPluginImages.IMG_CORRECTION_ADD, modification, IProposalRelevance.ADD_UNIMPLEMENTED_METHODS); } }
Example 2
Source File: BslQuickFix.java From ru.capralow.dt.bslls.validator with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Fix("bsl-language-server") public void processBslLanguageServerDiagnostic(final Issue issue, final IssueResolutionAcceptor acceptor) { String[] issueData = issue.getData(); for (String issueLine : issueData) { if (issueLine.isEmpty()) continue; String[] issueList = issueLine.split("[|]"); //$NON-NLS-1$ String issueCommand = issueList[0]; String issueMessage = issueList[1]; Integer issueOffset = Integer.decode(issueList[2]); Integer issueLength = Integer.decode(issueList[3]); String issueNewText = issueList.length == 5 ? issueList[4] : ""; //$NON-NLS-1$ acceptor.accept(issue, issueCommand, issueMessage, (String)null, new AbstractExternalQuickfixProvider.ExternalQuickfixModification<>(issue, EObject.class, module -> new ReplaceEdit(issueOffset, issueLength, issueNewText))); } }
Example 3
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Fix(IssueCodes.MISSING_OVERRIDE) public void fixMissingOverride(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Change 'def' to 'override'", "Marks this function as 'override'", "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { replaceKeyword(grammarAccess.getMethodModifierAccess().findKeywords("def").get(0), "override", element, context.getXtextDocument()); if (element instanceof XtendFunction) { XtendFunction function = (XtendFunction) element; for (XAnnotation anno : Lists.reverse(function.getAnnotations())) { if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) { ICompositeNode node = NodeModelUtils.findActualNodeFor(anno); context.getXtextDocument().replace(node.getOffset(), node.getLength(), ""); } } } } }); }
Example 4
Source File: MemberRenameModification.java From sarl with Apache License 2.0 | 6 votes |
/** Create the quick fix if needed. * * <p>The user data ccontains the new names. * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) { for (final String newName : issue.getData()) { final String msg = MessageFormat.format( Messages.SARLQuickfixProvider_11, newName); final MemberRenameModification modification = new MemberRenameModification(newName); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, msg, MessageFormat.format(Messages.SARLQuickfixProvider_12, newName), JavaPluginImages.IMG_CORRECTION_RENAME, modification, IProposalRelevance.RENAME_REFACTORING); } }
Example 5
Source File: ReturnTypeReplaceModification.java From sarl with Apache License 2.0 | 6 votes |
/** Create the quick fix if needed. * * <p>User data contains the name of the expected type. * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) { final String[] data = issue.getData(); if (data != null && data.length > 0) { final String expectedType = data[0]; final ReturnTypeReplaceModification modification = new ReturnTypeReplaceModification(expectedType); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, MessageFormat.format(Messages.SARLQuickfixProvider_15, expectedType), Messages.SARLQuickfixProvider_16, JavaPluginImages.IMG_CORRECTION_CHANGE, modification, IProposalRelevance.CHANGE_RETURN_TYPE); } }
Example 6
Source File: XtextGrammarQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Fix(INVALID_PACKAGE_REFERENCE_INHERITED) public void fixImportedPackageFromSuperGrammar(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData().length == 1) acceptor.accept(issue, "Change to '" + issue.getData()[0] + "'", "Fix the bogus package import\n" + "import '" + issue.getData()[0] + "'", NULL_QUICKFIX_IMAGE, new IModification() { @Override public void apply(IModificationContext context) throws BadLocationException { String replaceString = valueConverterService.toString(issue.getData()[0], "STRING"); IXtextDocument document = context.getXtextDocument(); String delimiter = document.get(issue.getOffset(), 1); if (!replaceString.startsWith(delimiter)) { replaceString = delimiter + replaceString.substring(1, replaceString.length() - 1) + delimiter; } document.replace(issue.getOffset(), issue.getLength(), replaceString); } }); }
Example 7
Source File: CreateJavaTypeQuickfixes.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void newJavaInterfaceQuickfix(final String typeName, final String explicitPackage, final XtextResource resource, Issue issue, IssueResolutionAcceptor issueResolutionAcceptor) { String packageDescription = getPackageDescription(explicitPackage); issueResolutionAcceptor.accept(issue, "Create Java interface '" + typeName + "'" + packageDescription, "Opens the new Java interface wizard to create the type '" + typeName + "'" + packageDescription, "java_interface.gif", new IModification() { @Override public void apply(/* @Nullable */ IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { NewInterfaceWizardPage classWizardPage = new NewInterfaceWizardPage(); NewInterfaceCreationWizard wizard = new NewInterfaceCreationWizard(classWizardPage, true); WizardDialog dialog = createWizardDialog(wizard); configureWizardPage(classWizardPage, resource.getURI(), typeName, explicitPackage); dialog.open(); } }); } }); }
Example 8
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.WRONG_FILE) public void fixFileName(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null && issue.getData().length == 1) { final String expectedFileName = issue.getData()[0]; final IFile iFile = projectUtil.findFileStorage(issue.getUriToProblem(), true); final IPath pathToMoveTo = iFile.getParent().getFullPath().append(expectedFileName) .addFileExtension(iFile.getFileExtension()); if (!iFile.getWorkspace().getRoot().exists(pathToMoveTo)) { final String label = "Rename file to '" + expectedFileName + ".xtend'"; acceptor.accept(issue, label, label, "xtend_file.png", new IModification() { @Override public void apply(IModificationContext context) throws Exception { runAsyncInDisplayThread(new Runnable() { @Override public void run() { try { iFile.move(pathToMoveTo, IResource.KEEP_HISTORY, null); } catch (CoreException e) { logger.error(e); } } }); } }); } } }
Example 9
Source File: GamlQuickfixProvider.java From gama with GNU General Public License v3.0 | 5 votes |
@Fix (IGamlIssue.SHOULD_CAST) public void shouldCast(final Issue issue, final IssueResolutionAcceptor acceptor) { final String[] data = issue.getData(); if (data == null || data.length == 0) { return; } final String castingString = data[0]; acceptor.accept(issue, "Cast the expression to " + castingString + "...", "", "", new Surround(issue.getOffset(), issue.getLength(), castingString + "(", ")")); }
Example 10
Source File: CheckCfgQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Removes the configured values of a disabled check. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DISABLED_CHECK_NOT_CONFIGURED) public void removeConfiguredParamsOfDisabledCheck(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_CONFIGURED_PARAM_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_CONFIGURED_PARAM_DESCN, null, new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) { ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class); check.getParameterConfigurations().removeAll(check.getParameterConfigurations()); } }); }
Example 11
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.OPERATION_WITHOUT_PARENTHESES) public void fixMissingParentheses(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add parentheses", "Add parentheses", null, new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), issue.getOffset() + issue.getLength(), 0); appendable.append("()"); appendable.commitChanges(); } }); }
Example 12
Source File: CheckCfgQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Reset the severity of a configured check which is final to {@code default}. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.FINAL_CHECK_NOT_CONFIGURABLE) public void resetSeverityOfFinalCheck(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_OF_FINAL_CHECK_LABEL, Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_OF_FINAL_CHECK_DESCN, null, new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) { ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class); check.setSeverity(SeverityKind.DEFAULT); } }); }
Example 13
Source File: StatemachineQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Fix(StatemachineValidator.INVALID_NAME) public void convertNameToFirstLowerCase(Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); String firstLower = StringExtensions.toFirstLower(data[0]); String label = "Change to \'" + firstLower + "\'."; acceptor.accept(issue, label, label, "upcase.png", (IModification) (IModificationContext ctx) -> { IXtextDocument xtextDocument = ctx.getXtextDocument(); String firstLetter = xtextDocument.get(issue.getOffset(), 1); xtextDocument.replace(issue.getOffset(), 1, firstLetter.toLowerCase()); }); }
Example 14
Source File: GamlQuickfixProvider.java From gama with GNU General Public License v3.0 | 5 votes |
@Fix (IGamlIssue.NO_INIT) public void addInit(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add an init facet...", "", "", (IModification) context -> { final IXtextDocument doc = context.getXtextDocument(); doc.replace(issue.getOffset() + issue.getLength() + 1, 0, " <- " + issue.getData()[0] + " "); }); }
Example 15
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.MISSING_CONSTRUCTOR) public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for(int i=0; i<issue.getData().length; i+=2) { final URI constructorURI = URI.createURI(issue.getData()[i]); String javaSignature = issue.getData()[i+1]; String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('(')); acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { XtendClass clazz = (XtendClass) element; JvmGenericType inferredType = associations.getInferredType(clazz); ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType); ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(), insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {{ ensureEmptyLinesAround = true; baseIndentationLevel = 1; }}); EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true); if (constructor instanceof JvmConstructor) { superMemberImplementor.appendConstructorFromSuper( clazz, new ResolvedConstructor((JvmConstructor) constructor, features.getType()), appendable); } appendable.commitChanges(); } }); } } }
Example 16
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Fix(IssueCodes.OBSOLETE_ANNOTATION_OVERRIDE) public void fixObsoleteOverrideAnnotation(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Remove superfluous @Override", "Removes superfluous @Override annotation from this function", "fix_indent.gif", new IModification() { @Override public void apply(IModificationContext context) throws Exception { context.getXtextDocument().replace(issue.getOffset(), issue.getLength(), ""); } }); }
Example 17
Source File: SuperTypeRemoveModification.java From sarl with Apache License 2.0 | 5 votes |
/** Create the quick fix if needed. * * <p>No user data. * * @param provider the quick fix provider. * @param issue the issue to fix. * @param acceptor the quick fix acceptor. */ public static void accept(SARLQuickfixProvider provider, Issue issue, IssueResolutionAcceptor acceptor) { final SuperTypeRemoveModification modification = new SuperTypeRemoveModification(); modification.setIssue(issue); modification.setTools(provider); acceptor.accept(issue, Messages.SARLQuickfixProvider_0, Messages.SARLQuickfixProvider_17, JavaPluginImages.IMG_CORRECTION_REMOVE, modification, IProposalRelevance.REMOVE_REDUNDANT_SUPER_INTERFACE); }
Example 18
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@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); } }); }
Example 19
Source File: CheckQuickfixProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Removes a duplicate parameter definition. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DUPLICATE_PARAMETER_DEFINITION) public void removeDuplicateParameterDefinition(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_PARAM_DEF_LABEL, Messages.CheckQuickfixProvider_REMOVE_PARAM_DEF_DESCN, null, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { Check check = EcoreUtil2.getContainerOfType(element, Check.class); check.getFormalParameters().remove(element); } }); }
Example 20
Source File: XtendQuickfixProvider.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) { acceptor.accept(issue, label, label, "fix_indent.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { XtendTypeDeclaration clazz = (XtendTypeDeclaration) element; JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz); ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType); IXtextDocument document = context.getXtextDocument(); final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz); int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource()); final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation; ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0, new OptionalParameters() {{ ensureEmptyLinesAround = true; baseIndentationLevel = indentationToUse; }}); boolean isFirst = true; for (String operationUriAsString : operationUris) { URI operationURI = URI.createURI(operationUriAsString); EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true); if (overridden instanceof JvmOperation) { if(!isFirst) appendable.newLine().newLine(); isFirst = false; superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden), appendable); } } appendable.commitChanges(); } }); }