/** * 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); } } }); }
/** * 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(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(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}"); } }); }
/** * 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" + ' '); } }); }
/** * @since 2.4 */ public IssueResolution(String label, String description, String image, IModificationContext modificationContext, IModification modification, int relevance) { this.description = description; this.label = label; this.image = image; this.modificationContext = modificationContext; this.modification = modification; this.relevance = relevance; }
@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()); } }); }
@Fix(SadlJavaValidator.MISSING_HTTP_PREFIX) public void missingHttpPrefix(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Prefix", "Add 'http://' to the begining of the model name", null, new IModification() { public void apply(IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); String openingQuote = xtextDocument.get(issue.getOffset() + 1, 1); xtextDocument.replace(issue.getOffset() + 1, 1, openingQuote + "http://"); } }); }
@Fix(SadlJavaValidator.ADD_GLOBAL_ALIAS) public void addModelGlobalAlias(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Model Global Alias", "Add a global alias to the model", null, new IModification() { @Override public void apply(IModificationContext context) throws Exception { final IXtextDocument doc = context.getXtextDocument(); // assumption: that URI is in same line as 'uri' keyword // parse the line to create a ModelName String line = doc.get(issue.getOffset(), doc.getLineLength(issue.getLineNumber()-1)); IParseResult parseResult = parser.parse(parser.getGrammarAccess().getModelNameRule(), new StringReader(line)); ModelName name = (ModelName) parseResult.getRootASTElement(); // compute alias name URI uri = URI.createURI(name.getBaseUri()); String galias = (uri.segmentCount()>1) ? uri.lastSegment() : "aliasName"; // find insertion offset: Search for end of URI string int offset = line.indexOf(name.getBaseUri())+name.getBaseUri().length(); // is uri string surrounded by " or ' ? char stringDelimiter = line.substring(0,offset).indexOf('"')>0 ? '"' : '\''; // find position of end character offset = line.indexOf(stringDelimiter, offset)+1; doc.replace(offset, 0, " alias "+galias); } }); }
public void accept(Issue issue, String label, String description, String image, IModification modification) { issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue), modification)); }
/** * @since 2.4 */ public void accept(Issue issue, String label, String description, String image, IModification modification, int relevance) { issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue), modification, relevance)); }
public IssueResolution(String label, String description, String image, IModificationContext modificationContext, IModification modification) { this(label, description, image, modificationContext, modification, 0); }
/** * @since 2.2 */ public IModification getModification() { return modification; }
/** * Replaces the marked problem area (as derived by issue offset and length) with given replacement string. May be used * to remove obsolete modifiers. * * @param issue * the issue * @param acceptor * the acceptor * @param label * the label * @param descn * the description * @param replacement * the replacement */ private void doTextualTokenReplacement(final Issue issue, final IssueResolutionAcceptor acceptor, final String label, final String descn, final String replacement) { 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() + 1, replacement); } }); }