Commit bbd636d4 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa

added quickfixes for implicit active declarations and forbidden

outputports
parent 4aa6eb7c
package de.cau.se.teetime.configuration.dsl.ui;
import org.eclipse.xtext.resource.SaveOptions;
import org.eclipse.xtext.ui.editor.model.edit.DefaultTextEditComposer;
public class ConfigTextEditComposer extends DefaultTextEditComposer {
@Override
protected SaveOptions getSaveOptions() {
return SaveOptions.newBuilder().format().getOptions();
}
}
......@@ -5,15 +5,20 @@ package de.cau.se.teetime.configuration.dsl.ui
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.ui.editor.model.XtextDocumentProvider
import org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer
/**
* Use this class to register components to be used within the Eclipse IDE.
*/
@FinalFieldsConstructor
class ConfigUiModule extends de.cau.se.teetime.configuration.dsl.ui.AbstractConfigUiModule {
class ConfigUiModule extends AbstractConfigUiModule {
def Class<? extends XtextDocumentProvider> bindDocumentProvider() {
return ConfigDocumentProvider;
}
def Class<? extends ITextEditComposer> bindITextEditComposer() {
return ConfigTextEditComposer;
}
}
......@@ -3,11 +3,19 @@
*/
package de.cau.se.teetime.configuration.dsl.ui.quickfix
import de.cau.se.teetime.configuration.dsl.config.Stage
import de.cau.se.teetime.configuration.dsl.validation.ConfigValidator
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext
import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider
import org.eclipse.xtext.ui.editor.quickfix.Fix
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
import org.eclipse.xtext.validation.Issue
/**
* Custom quickfixes.
*
*
* See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#quick-fixes
*/
class ConfigQuickfixProvider extends DefaultQuickfixProvider {
......@@ -21,4 +29,27 @@ class ConfigQuickfixProvider extends DefaultQuickfixProvider {
// xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase)
// ]
// }
@Fix(ConfigValidator::INCORRECT_MIDDLE_STAGE)
def removeOutputPort(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove OutputPort", "Remove the OutputPort and rely on the default Ports.",
"remove_correction.gif") [ context |
val xtextDocument = context.xtextDocument
xtextDocument.replace(issue.offset - 1, issue.length + 1, "")
]
}
@Fix(ConfigValidator::IMPLICIT_ACTIVE)
def addActiveKeyword(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(
issue,
"Add 'active' keyword", // label
"Stage will be executed in its own thread, solving concurrency issues.", // description
"add_obj.gif", // icon
new ISemanticModification() {
override apply(EObject element, IModificationContext context) {
(element as Stage).active = true;
}
}
);
}
}
......@@ -43,7 +43,7 @@ class ConfigFormatter extends AbstractFormatter2 {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
stage.getParameter.format;
stage.getArgumentList.format;
stage.append[newLine]
stage.surround[newLine]
}
// TODO: implement for Connection, ArgumentDeclarationList, Parameter
......
......@@ -3,8 +3,12 @@
*/
package de.cau.se.teetime.configuration.dsl.validation
import de.cau.se.teetime.configuration.dsl.config.ConfigPackage
import de.cau.se.teetime.configuration.dsl.config.Configuration
import de.cau.se.teetime.configuration.dsl.config.Connection
import de.cau.se.teetime.configuration.dsl.config.Stage
import de.cau.se.teetime.configuration.dsl.config.StageQualifier
import org.eclipse.xtext.EcoreUtil2
import org.eclipse.xtext.validation.Check
/**
......@@ -14,24 +18,51 @@ import org.eclipse.xtext.validation.Check
*/
class ConfigValidator extends AbstractConfigValidator {
// public static val INVALID_NAME = 'invalidName'
public static val INCORRECT_MIDDLE_STAGE = "incorrectMiddleStage"
public static val IMPLICIT_ACTIVE = "implicitActive"
// public static val INVALID_NAME = 'invalidName'
//
// @Check
// def checkGreetingStartsWithCapital(Greeting greeting) {
// if (!Character.isUpperCase(greeting.name.charAt(0))) {
// warning('Name should start with a capital',
// ConfigPackage.Literals.GREETING__NAME,
// INVALID_NAME)
// }
// }
@Check
def checkCorrectConnection(Connection con) {
if (con.middleStages.size > 0) {
for (StageQualifier pq : con.middleStages) {
if (pq.outputPortId != null) {
error("Nested connections only feasible with default ports", pq, null)
}
}
}
}
}
\ No newline at end of file
////
// @Check
// def checkGreetingStartsWithCapital(Stage greeting) {
// if (!Character.isUpperCase(greeting.name.charAt(0))) {
// warning('Name should start with a capital', ConfigPackage.Literals.STAGE__NAME, INVALID_NAME)
// }
// }
@Check
def checkCorrectConnection(Connection con) {
if (con.middleStages.size > 0) {
for (StageQualifier pq : con.middleStages) {
if (pq.outputPortId != null) {
error("Nested connections only feasible with default ports.", pq,
ConfigPackage.Literals.STAGE_QUALIFIER__OUTPUT_PORT_ID, INCORRECT_MIDDLE_STAGE)
}
}
}
}
// TODO: Should check Stage.getInputPorts.size == 0
@Check
def checkImplicitActive(Stage stage) {
if (!stage.active) {
val root = EcoreUtil2.getRootContainer(stage) as Configuration
val unactive = root.elements.filter(Connection).filter [
val middles = it.middleStages.filter [ middleStage |
middleStage.stageId == stage
]
!(!(it.finalStage.stageId == stage) && middles.empty)
]
if (unactive.empty) {
warning("Head stages without incoming connections should be declared active.", stage,
ConfigPackage.Literals.STAGE__NAME, IMPLICIT_ACTIVE)
}
}
}
def static getINCORRECT_MIDDLE_STAGE() {
INCORRECT_MIDDLE_STAGE
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment