/** * 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); } } }); }
@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(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); } } ); }
/** * 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); } } }); }
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(); } } }); }
@Fix(SadlJavaValidator.MISSING_MODEL_NAME) public void provideModelName(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Model Name", "Add a missing model name", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { URI modelURI = element.eResource().getURI(); String baseUri = proposalProvider.generateBaseUri(modelURI); ((ModelName)element).setBaseUri(baseUri); } }); }
@Fix(SadlJavaValidator.DUPLICATE_MODEL_NAME) public void replaceModelName(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Replace Model Name", "Replace a duplicate model name", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { URI modelURI = element.eResource().getURI(); String baseUri = proposalProvider.generateBaseUri(modelURI); ((ModelName)element).setBaseUri(baseUri); } }); }
@Fix(SadlJavaValidator.ADD_MODEL_VERSION) public void addModelVersion(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Model Version", "Add a model version with CVS tags", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { // this string can't be complete or Source Code Control may modify it String versionTemplate = "$"; versionTemplate += "Revision: "; versionTemplate += "$ Last modified on $"; versionTemplate += "Date: "; versionTemplate += "$"; ((ModelName)element).setVersion(versionTemplate); } }); }
@Fix(SadlJavaValidator.DOUBLE_ALIAS) public void removeImportAlias(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Remove import model alias", "Remove local alias for the model import", null, new ISemanticModification() { public void apply(EObject element, IModificationContext context) throws Exception { ((com.ge.research.sadl.sadl.Import)element).setAlias(null); } }); }
@Fix(SadlJavaValidator.OBJECTPROPERTY_NOT_DEFINED) public void addObjectPropertyDefinition(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Property", "Add missing object property definition to the model", null, new ISemanticModification() { public void apply(EObject rsrcId, IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { Object[] fixInfo = prepareMissingConceptFix(xtextDocument, rsrcId, issue); xtextDocument.replace(((Integer)fixInfo[1]).intValue(), 1, "." + System.getProperty("line.separator") + (fixInfo[0] != null ? fixInfo[0] : "New_Prop") + " describes .\n"); } } }); }
@Fix(SadlJavaValidator.DATATYPEPROPERTY_NOT_DEFINED) public void addDatatypePropertyDefinition(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Add Property", "Add missing data property definition to the model", null, new ISemanticModification() { public void apply(EObject rsrcId, IModificationContext context) throws BadLocationException { IXtextDocument xtextDocument = context.getXtextDocument(); if (xtextDocument instanceof XtextDocument) { Object[] fixInfo = prepareMissingConceptFix(xtextDocument, rsrcId, issue); xtextDocument.replace(((Integer)fixInfo[1]).intValue(), 1, "." + System.getProperty("line.separator") + (fixInfo[0] != null ? fixInfo[0] : "New_Prop") + " describes .\n"); } } }); }
@Fix(Diagnostic.LINKING_DIAGNOSTIC) public void characterUnknown(final Issue issue, final IssueResolutionAcceptor acceptor) { EClass _characterDefinition = DialogScriptPackage.eINSTANCE.getCharacterDefinition(); final String linkText = this.customLinkingDiagnosticMessageProvider.getLinkText(issue, _characterDefinition); 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 DialogLine)) { final Script root = EcoreUtil2.<Script>getContainerOfType(element, Script.class); final CharacterDefinition charaDef = DialogScriptFactory.eINSTANCE.createCharacterDefinition(); charaDef.setName(linkText); CharactersDefinition _charactersDefinition = root.getCharactersDefinition(); boolean _equals = Objects.equal(_charactersDefinition, null); if (_equals) { CharactersDefinition _createCharactersDefinition = DialogScriptFactory.eINSTANCE.createCharactersDefinition(); root.setCharactersDefinition(_createCharactersDefinition); } CharactersDefinition _charactersDefinition_1 = root.getCharactersDefinition(); EList<CharacterDefinition> _characters = _charactersDefinition_1.getCharacters(); _characters.add(charaDef); } } }; acceptor.accept(issue, (("Create character \'" + linkText) + "\'"), (("Create character \'" + linkText) + "\'"), null, _function); } }
@Fix(EntitiesValidator.HIERARCHY_CICLE) public void removeSuperType(final Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, "Remove supertype", // label "Remove supertype '" + issue.getData()[0] + "'", // description "delete_obj.gif", // icon new ISemanticModification() { public void apply(EObject element, IModificationContext context) { ((Entity) element).setSuperType(null); } } ); }
public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification) { SemanticModificationWrapper modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification); issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue), modificationWrapper)); }
/** * @since 2.4 */ public void accept(Issue issue, String label, String description, String image, ISemanticModification semanticModification, int relevance) { SemanticModificationWrapper modificationWrapper = new SemanticModificationWrapper(issue.getUriToProblem(), semanticModification); issueResolutions.add(new IssueResolution(label, description, image, modificationContextFactory.createModificationContext(issue), modificationWrapper, relevance)); }
@Fix(CharacterScriptValidator.MISSING_REQUIRED_DEFAULT) public void addRequiredDefault(final Issue issue, final IssueResolutionAcceptor acceptor) { String[] _data = issue.getData(); final String propName = _data[0]; 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 de.unidue.ecg.characterScript.characterScript.Character character = ((de.unidue.ecg.characterScript.characterScript.Character) element); final Template template = character.getTemplate(); boolean _notEquals = (!Objects.equal(template, null)); if (_notEquals) { boolean _matched = false; if (!_matched) { if (Objects.equal(propName,"full name")) { _matched=true; final FullName property = CharacterScriptFactory.eINSTANCE.createFullName(); property.setValue("XYZ"); property.setComment("[FIX ME!]"); EList<Property> _properties = character.getProperties(); _properties.add(property); } } if (!_matched) { if (Objects.equal(propName,"sex")) { _matched=true; final Sex property_1 = CharacterScriptFactory.eINSTANCE.createSex(); property_1.setValue(CharaSex.FEMALE); property_1.setComment("[FIX ME!]"); EList<Property> _properties_1 = character.getProperties(); _properties_1.add(property_1); } } if (!_matched) { if (Objects.equal(propName,"type")) { _matched=true; final Type property_2 = CharacterScriptFactory.eINSTANCE.createType(); property_2.setValue(CharaType.PC); property_2.setComment("[FIX ME!]"); EList<Property> _properties_2 = character.getProperties(); _properties_2.add(property_2); } } if (!_matched) { if (Objects.equal(propName,"age")) { _matched=true; final Age property_3 = CharacterScriptFactory.eINSTANCE.createAge(); property_3.setValue(0); property_3.setComment("[FIX ME!]"); EList<Property> _properties_3 = character.getProperties(); _properties_3.add(property_3); } } if (!_matched) { if (Objects.equal(propName,"description")) { _matched=true; final Description property_4 = CharacterScriptFactory.eINSTANCE.createDescription(); property_4.setValue("XYZ"); property_4.setComment("[FIX ME!]"); EList<Property> _properties_4 = character.getProperties(); _properties_4.add(property_4); } } } } } }; acceptor.accept(issue, (("Add missing attribute \'" + propName) + "\'"), (("Add missing attribute \'" + propName) + "\'"), null, _function); }