/** * Semantic quickfix setting the override flag for a rule. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(FormatJavaValidator.OVERRIDE_MISSING_CODE) public void setOverride(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Set override", "Set override flag.", null, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() { @Override public java.lang.Void exec(final XtextResource state) { Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment()); rule.setOverride(true); return null; } }); } }); }
/** * Semantic quickfix removing the override flag for a rule. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(FormatJavaValidator.OVERRIDE_ILLEGAL_CODE) public void removeOverride(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Remove override", "Remove override.", null, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() { @Override public java.lang.Void exec(final XtextResource state) { Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment()); rule.setOverride(false); return null; } }); } }); }
/** * Fix catalog name. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.WRONG_FILE) public void fixCatalogName(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_CORRECT_CATALOG_NAME_LABEL, Messages.CheckQuickfixProvider_CORRECT_CATALOG_NAME_DESCN, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); IFile file = xtextDocument.getAdapter(IFile.class); if (file != null) { final String fileName = file.getName(); final String name = fileName.indexOf('.') > 0 ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName; xtextDocument.replace(issue.getOffset(), issue.getLength(), name); } } }); }
/** * Removes the guard statement occurring at offending position. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.GUARDS_COME_FIRST) @SuppressWarnings("unchecked") public void removeGuardStatement(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_GUARD_LABEL, Messages.CheckQuickfixProvider_REMOVE_GUARD_DESCN, NO_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { final XGuardExpression guard = EcoreUtil2.getContainerOfType(element, XGuardExpression.class); if (guard != null && guard.eContainingFeature().isMany()) { EList<? extends EObject> holder = (EList<? extends EObject>) guard.eContainer().eGet(guard.eContainingFeature()); if (holder != null && holder.contains(guard)) { holder.remove(guard); } } } }); }
/** * Fixes the severity range order by setting the lower severity level kind first and the severity of higher severity level last. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.ILLEGAL_SEVERITY_RANGE_ORDER) public void fixSeverityRangeOrder(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_FIX_SEVERITY_RANGE_ORDER_LABEL, Messages.CheckQuickfixProvider_FIX_SEVERITY_RANGE_ORDER_DESCN, NO_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { final Check check = EcoreUtil2.getContainerOfType(element, Check.class); if (check != null && check.getSeverityRange() != null) { final SeverityRange range = check.getSeverityRange(); SeverityKind oldMinSeverity = range.getMinSeverity(); range.setMinSeverity(range.getMaxSeverity()); range.setMaxSeverity(oldMinSeverity); } } }); }
/** * Fixes an illegally set default severity. The default severity must be within given severity range. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DEFAULT_SEVERITY_NOT_IN_RANGE) public void fixIllegalDefaultSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for (final String severityProposal : issue.getData()) { final String label = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_LABEL, severityProposal); final String descn = NLS.bind(Messages.CheckQuickfixProvider_DEFAULT_SEVERITY_FIX_DESCN, severityProposal); acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal); } }); } } }
/** * Fix severity by setting it to a legal value as is defined by severity range of referenced check. Legal * severities are passed as issue data (org.eclipse.xtext.validation.Issue#getData()). * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.SEVERITY_NOT_ALLOWED) public void fixSeverityToMaxSeverity(final Issue issue, final IssueResolutionAcceptor acceptor) { if (issue.getData() != null) { for (final String severityProposal : issue.getData()) { final String label = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_LABEL, severityProposal); final String descn = NLS.bind(Messages.CheckCfgQuickfixProvider_CORRECT_SEVERITY_DESCN, severityProposal); acceptor.accept(issue, label, descn, NO_IMAGE, new IModification() { public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(issue.getOffset(), issue.getLength(), severityProposal); } }); } } }
@Fix(IssueCodes.ARRAY_NOT_DECLARED) public void fixArrayNotDeclared(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Remove vector slices", "Removes vector slices from object", null, new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PinAssign) { ((PinAssign) element).setSlices(null); } else if (element instanceof PortAssign) { ((PortAssign) element).setSlices(null); } else if (element instanceof ConnectionAssign) { ((ConnectionAssign) element).setSlices(null); } else if (element instanceof ConnectionRef) { ((ConnectionRef) element).setSlices(null); } } }); }
@Fix(IssueCodes.REQUIRED_ATTRIBUTE_MISSING) public void fixMissingRequiredAttribute(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add missing required attribute", "Add missing '" + issue.getData()[0] + "' required attribute.", "Attr.gif", new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { Device device = (Device) element; Attr attr = PhdlFactory.eINSTANCE.createAttr(); attr.setName(issue.getData()[0].toUpperCase()); if (!issue.getData()[0].equals("REFPREFIX")) attr.setValue("my" + issue.getData()[0]); else attr.setValue("R"); device.getElements().add(attr); } }); }
@Fix(SadlJavaValidator.MISSING_ALIAS) public void addImportAlias(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add import model alias", "Add an alias for the imported model", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { String alias = null; if (element instanceof com.ge.research.sadl.sadl.Import) { String uri = ((com.ge.research.sadl.sadl.Import)element).getImportURI().trim(); if (uri.endsWith("/")) { uri = uri.substring(0, uri.length() - 1); } int ls = uri.lastIndexOf('/'); if (ls > 0) { alias = uri.substring(ls + 1); } } if (alias == null) { alias = "aliasName"; } ((com.ge.research.sadl.sadl.Import)element).setAlias(alias); } }); }
@Fix(SadlJavaValidator.AMBIGUOUS_NAME) public void addNSQualifier(final Issue issue, final IssueResolutionAcceptor acceptor) { String[] fixes = issue.getData(); Iterator<String> itr = Splitter.on(",").split(fixes[0]).iterator(); while (itr.hasNext()) { // loop over prefixes final String prefix = itr.next(); acceptor.accept(issue, prefix, "Add the namespace prefix '" + prefix + "' to disambiguate name", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { if (element instanceof ResourceByName) { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { int insertAt = issue.getOffset(); xtextDocument.replace(insertAt, issue.getLength(), prefix); } } } }); } }
public void addImportTemplateFix(final Issue issue, final IssueResolutionAcceptor acceptor, final String linkText) { boolean _notEquals = (!Objects.equal(linkText, null)); if (_notEquals) { final ISemanticModification _function = new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) throws Exception { if ((element instanceof de.unidue.ecg.characterScript.characterScript.Character)) { final Characters root = EcoreUtil2.<Characters>getContainerOfType(element, Characters.class); final Import import_ = CharacterScriptFactory.eINSTANCE.createImport(); import_.setImportedNamespace(linkText); EList<Import> _imports = root.getImports(); _imports.add(import_); } } }; acceptor.accept(issue, (("Add import for \'" + linkText) + "\'"), (("Add import for \'" + linkText) + "\'"), null, _function); } }
@Fix(EntitiesValidator.HIERARCHY_CYCLE) public void removeSuperType(final Issue issue, final IssueResolutionAcceptor acceptor) { StringConcatenation _builder = new StringConcatenation(); _builder.append("Remove supertype \'"); String[] _data = issue.getData(); String _get = _data[0]; _builder.append(_get, ""); _builder.append("\' "); final ISemanticModification _function = new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) throws Exception { ((Entity) element).setSuperType(null); } }; acceptor.accept(issue, "Remove supertype", _builder.toString(), "delete_obj.gif", _function); }
@Fix(Diagnostic.LINKING_DIAGNOSTIC) public void createMissingEntity(final Issue issue, final IssueResolutionAcceptor acceptor) { final ISemanticModification _function = new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) throws Exception { Entity _containerOfType = EcoreUtil2.<Entity>getContainerOfType(element, Entity.class); IXtextDocument _xtextDocument = context.getXtextDocument(); Integer _offset = issue.getOffset(); Integer _length = issue.getLength(); String _get = _xtextDocument.get((_offset).intValue(), (_length).intValue()); EntitiesModelUtil.addEntityAfter(_containerOfType, _get); } }; acceptor.accept(issue, "Create missing entity", "Create missing entity", "Entity.gif", _function); }
@Fix(EntitiesValidator.INVALID_ENTITY_NAME) public void capitalizeEntityNameFirstLetter(final Issue issue, final IssueResolutionAcceptor acceptor) { String[] _data = issue.getData(); String _get = _data[0]; String _plus = ("Capitalize first letter of \'" + _get); String _plus_1 = (_plus + "\'"); final IModification _function = new IModification() { @Override public void apply(final IModificationContext context) throws Exception { final IXtextDocument xtextDocument = context.getXtextDocument(); Integer _offset = issue.getOffset(); final String firstLetter = xtextDocument.get((_offset).intValue(), 1); Integer _offset_1 = issue.getOffset(); String _firstUpper = StringExtensions.toFirstUpper(firstLetter); xtextDocument.replace((_offset_1).intValue(), 1, _firstUpper); } }; acceptor.accept(issue, "Capitalize first letter", _plus_1, "Entity.gif", _function); }
@Fix(Diagnostic.LINKING_DIAGNOSTIC) public void createMissingEntity(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Create missing entity", // label "Create missing entity", // description "Entity.gif", // icon new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); String missingEntityName = xtextDocument.get(issue.getOffset(), issue.getLength()); Entity newEntity = EntitiesFactory.eINSTANCE.createEntity(); newEntity.setName(missingEntityName); Entity currentEntity = EcoreUtil2.getContainerOfType(element, Entity.class); Model model = (Model) currentEntity.eContainer(); model.getEntities().add(model.getEntities().indexOf(currentEntity)+1, newEntity); } } ); }
@Fix(IOIJavaValidator.SALARY_TOO_LOW) public void raiseSalary(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Raise Salary", "Raise Salary.", "", new IModification() { public void apply(IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); //String firstLetter = xtextDocument.get(issue.getOffset(), 1); xtextDocument.replace(issue.getOffset(), issue.getLength(), issue.getData()[0]); } }); }
@Fix(IOIJavaValidator.SALARY_TOO_HIGH) public void cutSalary(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Cut Salary", "Cut Salary.", "", new IModification() { public void apply(IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); //String firstLetter = xtextDocument.get(issue.getOffset(), 1); xtextDocument.replace(issue.getOffset(), issue.getLength(), issue.getData()[0]); } }); }
@Fix(RestauranteValidator.NOMBRE_MUY_LARGO) public void arreglarNombre(final Issue issue, final IssueResolutionAcceptor acceptor) { final IModification _function = (IModificationContext context) -> { final IXtextDocument xtextDocument = context.getXtextDocument(); final String nombreActual = xtextDocument.get((issue.getOffset()).intValue(), (issue.getLength()).intValue()); Integer _offset = issue.getOffset(); Integer _length = issue.getLength(); String _substring = nombreActual.substring(0, 18); String _plus = (_substring + "\'"); xtextDocument.replace((_offset).intValue(), (_length).intValue(), _plus); }; acceptor.accept(issue, "Reducir nombre", "Se limitar� el tama�o de nombre al m�ximo sugerido", "ingrediente.ico", _function); }
@Fix(RestauranteValidator.FECHA_INVALIDA) public void arreglarFecha(final Issue issue, final IssueResolutionAcceptor acceptor) { SimpleDateFormat formateadorFecha = new SimpleDateFormat("dd-MM-yyyy"); Calendar calendario = Calendar.getInstance(); final String fecha = formateadorFecha.format(calendario.getTime()); final IModification _function = (IModificationContext context) -> { final IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace((issue.getOffset()).intValue(), (issue.getLength()).intValue(), fecha); }; acceptor.accept(issue, "Actualizar fecha", "Se pondr� la fecha de hoy para corregir el problema", "fecha.png", _function); }
/** * Syntactic quickfix creating a rule. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(FormatJavaValidator.GRAMMAR_RULE_MISSING_CODE) public void addGrammarRule(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Create rule", "Create rule " + issue.getData()[0], null, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { final IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(xtextDocument.getLength(), 0, "\n" + issue.getData()[0] + " {\n\t\n}"); } }); }
/** * Returns a method predicate indicating whether a given method is an executable quickfix method. Both Check * quickfix methods and native quickfix methods are considered. * * @param issueCode * the issue code * @return the fix method predicate * @see com.avaloq.tools.ddk.check.runtime.quickfix.CoreFix CoreFix annotation * @see org.eclipse.xtext.ui.editor.quickfix.Fix Fix annotation */ @Override protected Predicate<Method> getFixMethodPredicate(final String issueCode) { return new Predicate<Method>() { @Override public boolean apply(final Method input) { CoreFix coreFixAnnotation = input.getAnnotation(CoreFix.class); Fix fixAnnotation = input.getAnnotation(Fix.class); if (coreFixAnnotation == null && fixAnnotation == null) { return false; // Definitely no candidate } final boolean typesMatch = Void.TYPE == input.getReturnType() && input.getParameterTypes().length == 2 && input.getParameterTypes()[0].isAssignableFrom(Issue.class); boolean result; if (coreFixAnnotation != null) { result = coreFixAnnotation != null && issueCode.equals(coreFixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(CoreIssueResolutionAcceptor.class); } else { result = fixAnnotation != null && issueCode.equals(fixAnnotation.value()) && typesMatch && input.getParameterTypes()[1].isAssignableFrom(IssueResolutionAcceptor.class); } return result; } }; }
/** * Replaces a guard by an if-expression. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.GUARDS_DEPRECATED) public void fixGuardStatement(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_GUARD_DEPRECATED_LABEL, Messages.CheckQuickfixProvider_GUARD_DEPRECATED_DESCN, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); String expr = xtextDocument.get(issue.getOffset(), issue.getLength()); expr = expr.replaceFirst("^guard(\\s*)", "if (!(") + ")) {return}"; xtextDocument.replace(issue.getOffset(), issue.getLength(), expr); } }); }
/** * Fixes the wrong package name. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.WRONG_PACKAGE) public void fixPackageName(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_CORRECT_PKG_NAME_LABEL, Messages.CheckQuickfixProvider_CORRECT_PKG_NAME_DESCN, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); final String packageName = resourceUtil.getNameOfContainingPackage(xtextDocument); if (packageName != null) { xtextDocument.replace(issue.getOffset(), issue.getLength(), packageName); } } }); }
/** * Adds an {@code issue} statement to a constraint. If the constraint already contains other expressions, {@code issue} is appended to the end. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.MISSING_ISSUE_EXPRESSION) public void addIssueExpression(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_ADD_ISSUE_EXPR_LABEL, Messages.CheckQuickfixProvider_ADD_ISSUE_EXPR_DESCN, NO_IMAGE, new IModification() { @Override public void apply(final IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); xtextDocument.replace(issue.getOffset() + issue.getLength() - 1, 0, ' ' + "issue" + ' '); } }); }
/** * Add explicit ID to a check, autogenerated from its label. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.MISSING_ID_ON_CHECK) public void addIdToCheck(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_ADD_ID_LABEL, NLS.bind(Messages.CheckQuickfixProvider_ADD_ID_DESCN, CHECK), NO_IMAGE, (final EObject element, final IModificationContext context) -> { final Check check = EcoreUtil2.getContainerOfType(element, Check.class); if (check != null) { final String label = check.getLabel(); final String id = CheckUtil.toIdentifier(label); check.setId(id); } }); }
/** * Fixes the circular dependency problem by removing the {@code with} clause. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.INCLUDED_CATALOGS_WITH_CIRCULAR_DEPENDENCIES) public void removeWithClause(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_WITH_LABEL, Messages.CheckQuickfixProvider_REMOVE_WITH_DESCN, NO_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { final CheckCatalog catalog = EcoreUtil2.getContainerOfType(element, CheckCatalog.class); if (catalog != null) { catalog.eUnset(CheckPackage.Literals.CHECK_CATALOG__INCLUDED_CATALOGS); } } }); }
/** * Removes the severity range declaration from the check. Final conflicts with severity range. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.SEVERITY_RANGES_FOR_FINAL_CHECK) public void removeSeverityRange(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckQuickfixProvider_REMOVE_SEVERITY_RANGE_LABEL, Messages.CheckQuickfixProvider_REMOVE_SEVERITY_RANGE_DESCN, NO_IMAGE, new ISemanticModification() { @Override public void apply(final EObject element, final IModificationContext context) { final Check check = EcoreUtil2.getContainerOfType(element, Check.class); if (check != null) { check.setSeverityRange(null); } } }); }
/** * 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); } }); }
/** * Removes a duplicate catalog configuration. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DUPLICATE_CATALOG_CONFIGURATION) public void removeDuplicateCatalogConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CATALOG_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CATALOG_DESCN, null, new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) { CheckConfiguration configuration = EcoreUtil2.getContainerOfType(element, CheckConfiguration.class); configuration.getLegacyCatalogConfigurations().remove(element); } }); }
/** * Removes a duplicate check configuration. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DUPLICATE_CHECK_CONFIGURATION) public void removeDuplicateCheckConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CHECK_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_CHECK_DESCN, null, new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) { ConfiguredCatalog catalog = EcoreUtil2.getContainerOfType(element, ConfiguredCatalog.class); catalog.getCheckConfigurations().remove(element); } }); }
/** * Removes a duplicate parameter configuration. * * @param issue * the issue * @param acceptor * the acceptor */ @Fix(IssueCodes.DUPLICATE_PARAMETER_CONFIGURATION) public void removeDuplicateParameterConfiguration(final Issue issue, final IssueResolutionAcceptor acceptor) { acceptor.accept(issue, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_PARAM_LABEL, Messages.CheckCfgQuickfixProvider_REMOVE_DUPLICATE_PARAM_DESCN, null, new ISemanticModification() { public void apply(final EObject element, final IModificationContext context) { ConfiguredCheck check = EcoreUtil2.getContainerOfType(element, ConfiguredCheck.class); check.getParameterConfigurations().remove(element); } }); }
/** * 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()); } }); }
/** * 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); } }); }
@Fix(SGenJavaValidator.CODE_REQUIRED_FEATURE) public void AddRequiredFeature(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add feature " + issue.getData()[0], "Adds the feature " + issue.getData()[0], null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { FeatureConfiguration config = getDefaultFeatureConfiguration(issue, element); if (config != null) { GeneratorEntry entry = (GeneratorEntry) element; entry.getFeatures().add(config); } } }); }
@Fix(IssueCodes.NOT_UPPERCASE) public void fixCase(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Convert to UPPERCASE", "Convert '" + issue.getData()[0] + "' to '" + issue.getData()[0].toUpperCase() + "'", "Upcase.gif", new IModification() { @Override public void apply(IModificationContext context) throws BadLocationException { IXtextDocument document = context.getXtextDocument(); String name = document.get(issue.getOffset(), issue.getLength()); document.replace(issue.getOffset(), issue.getLength(), name.toUpperCase()); } }); }
@Override public List<IssueResolution> getResolutions(Issue issue) { List<IssueResolution> resolutions = new ArrayList<>(super.getResolutions(issue)); Optional<EObject> element = getEObjectToBeFixedFromIssue(issue); if (element.isPresent()) { Collection<IAutomatedIssueResolutionFactory> issueResolutionFactories = findFactories(issue.getCode()); IssueResolutionAcceptor issueResolutionAcceptor = getIssueResolutionAcceptorProvider().get(); issueResolutionFactories.stream().filter(f -> f.resolvePossible(element.get())) .forEach(f -> createIssueResolution(f, issue, element.get(), issueResolutionAcceptor)); resolutions.addAll(issueResolutionAcceptor.getIssueResolutions()); } return resolutions; }
@Override protected Predicate<Method> getFixMethodPredicate(String issueCode) { return Predicates.or(super.getFixMethodPredicate(issueCode), new Predicate<Method>() { @Override public boolean apply(Method input) { SemanticFix annotation = input.getAnnotation(SemanticFix.class); boolean result = annotation != null && issueCode.equals(annotation.value()) && input.getParameterTypes().length == 3 && Void.TYPE == input.getReturnType() && input.getParameterTypes()[0].isAssignableFrom(Issue.class) && input.getParameterTypes()[1].isAssignableFrom(EObject.class) && input.getParameterTypes()[2].isAssignableFrom(IssueResolutionAcceptor.class); return result; } }); }
@Override protected List<IssueResolution> getResolutions(Issue issue, List<Method> fixMethods) { List<Method> originalMethods = fixMethods.stream().filter(m -> m.getAnnotation(Fix.class) != null) .collect(Collectors.toList()); List<IssueResolution> resolutions = new ArrayList<>(super.getResolutions(issue, originalMethods)); Optional<EObject> element = getEObjectToBeFixedFromIssue(issue); if (!element.isPresent()) { return resolutions; } List<Method> semanticMethods = fixMethods.stream().filter(m -> m.getAnnotation(SemanticFix.class) != null) .collect(Collectors.toList()); IssueResolutionAcceptor issueResolutionAcceptor = getIssueResolutionAcceptorProvider().get(); for (Method fixMethod : semanticMethods) { try { fixMethod.setAccessible(true); fixMethod.invoke(this, issue, element, issueResolutionAcceptor); } catch (Exception e) { LOGGER.error("Error executing fix method", e); } } List<IssueResolution> semanticResolutions = issueResolutionAcceptor.getIssueResolutions(); resolutions.addAll(semanticResolutions); return resolutions; }
private void createIssueResolution(IAutomatedIssueResolutionFactory factory, Issue issue, EObject element, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, factory.getResolutionName(element), factory.getIssueDescription(element), null, new ISemanticModification() { @Override public void apply(EObject ignoredElement, IModificationContext context) throws Exception { IAutomatedIssueResolution resolution = factory.create(element); if (resolution.resolvePossible()) { resolution.resolve(); ((XtextResource) element.eResource()).relink(); } } }); }