@Fix(DotJavaValidator.ATTRIBUTE__INVALID_VALUE__EDGE_STYLE) public void fixEdgeStyleAttributeValue(final Issue issue, IssueResolutionAcceptor acceptor) { for (String edgeStyle : DotProperties.EDGE_STYLE_VALUES) { // quote values if needed, otherwise use plain attribute value final String validValue = DotTerminalConverters.needsToBeQuoted(edgeStyle) ? DotTerminalConverters.quote(edgeStyle) : edgeStyle; acceptor.accept( issue, "Replace '" + issue.getData()[0] + "' with '" + validValue //$NON-NLS-1$ //$NON-NLS-2$ + "'.", //$NON-NLS-1$ "Use valid '" + validValue + "' instead of invalid '" //$NON-NLS-1$ //$NON-NLS-2$ + issue.getData()[0] + "' edge style.", //$NON-NLS-1$ null, new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { ((Attribute) element).setValue(validValue); } }); } }
@Fix(AdlJavaValidator.MISSING_PARAMETERS_ERROR_ID) public void addParameters(final Issue issue, IssueResolutionAcceptor acceptor) { String[] issueData = issue.getData(); acceptor.accept( issue, "Add parameters", "Add parameters to the reference of the definition " + issueData[0], null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { // TODO how to provide a template that allows to easily iterate over // parameter values DefinitionReference reference = (DefinitionReference) element; Definition referencedDefinition = (Definition) reference.getDefinition(); List<ParameterDecl> parameters = AdlModelHelper.getParameters(referencedDefinition); if (parameters != null && parameters.size() > 0) { IXtextDocument document = context.getXtextDocument(); int offset = issue.getOffset() + issue.getLength(); String paramString = "("; for (int i = 0; i < parameters.size() - 1; i++) { paramString += ", "; } paramString += ")"; document.replace(offset, 0, paramString); } } }); }
@Fix(IssueCodes.AMBIGUOUS_FEATURE_CALL) public void fixAmbiguousMethodCall(final Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); if (data == null || data.length == 0) { return; } for (String replacement : data) { String replaceLabel = "Change to '" + replacement + "'"; acceptor.accept( issue, replaceLabel, replaceLabel, null, new ReplaceModification(issue, replacement)); } }
@Fix(IssueCodes.FEATURE_NOT_VISIBLE) public void fixInvisibleFeature(final Issue issue, IssueResolutionAcceptor acceptor) { if (issue.getData() != null && issue.getData().length >= 1 && "subclass-context".equals(issue.getData()[0])) { String fixup; if (issue.getData().length == 1) fixup = "Add type cast."; else fixup = "Add cast to " + issue.getData()[1] + "."; acceptor.accept( issue, fixup, fixup, null, new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { if (!(element instanceof XAbstractFeatureCall)) return; XAbstractFeatureCall featureCall = (XAbstractFeatureCall) element; if (!(featureCall.getFeature() instanceof JvmMember)) return; JvmType declaringType = ((JvmMember) featureCall.getFeature()).getDeclaringType(); if (featureCall instanceof XMemberFeatureCall) { addTypeCastToExplicitReceiver( featureCall, context, declaringType, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET); } else if (featureCall instanceof XAssignment) { addTypeCastToExplicitReceiver( featureCall, context, declaringType, XbasePackage.Literals.XASSIGNMENT__ASSIGNABLE); } else if (featureCall instanceof XFeatureCall) { addTypeCastToImplicitReceiver((XFeatureCall) featureCall, context, declaringType); } } }); } }
@Fix(ModuleDiagnostics.ISSUE__MISSING_REQUIRED_ATTRIBUTE) public void addMissingAttribute(final Issue issue, IssueResolutionAcceptor acceptor) { String[] data = issue.getData(); if (data == null || data.length == 0) return; final String key = data[0]; acceptor.accept( issue, "Add entry for \"" + key + "\"", "Add missing entry for attribute \"" + key + "\"with template value", null, new ISemanticModification() { @Override public void apply(EObject element, IModificationContext context) throws Exception { IXtextDocument doc = context.getXtextDocument(); StringBuilder bld = new StringBuilder(); bld.append("\""); bld.append(key); bld.append("\": \""); context.getXtextDocument(); if ("version".equals(key)) bld.append("0.1.0"); else if ("version_requirement".equals(key)) bld.append(">=0.0.0"); else if ("author".equals(key)) bld.append(getModuleOwner()); else if ("name".equals(key)) { if ((element instanceof JsonMetadata)) { bld.append(getModuleOwner()); bld.append("-"); bld.append( ModuleName.safeName( doc.<IFile>getAdapter(IFile.class).getParent().getName(), false)); } } bld.append("\",\n "); doc.replace(issue.getOffset(), 0, bld.toString()); } }); }