Skip to content

Commit

Permalink
[lang] Output an error when System.exit is called.
Browse files Browse the repository at this point in the history
see #259

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 7, 2014
1 parent 31e4d0d commit 28d0e3c
Show file tree
Hide file tree
Showing 2 changed files with 456 additions and 0 deletions.
Expand Up @@ -75,6 +75,8 @@ import io.sarl.lang.signature.ActionKey
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.common.types.JvmTypeReference
import org.eclipse.emf.ecore.EAttribute
import org.eclipse.xtext.xbase.XMemberFeatureCall
import org.eclipse.xtext.xbase.XAbstractFeatureCall

/**
* Validator for the SARL elements.
Expand Down Expand Up @@ -162,6 +164,58 @@ class SARLValidator extends AbstractSARLValidator {
}
}
}

private def checkForbiddenFeatureCall(XAbstractFeatureCall expression) {
var id = expression.feature.qualifiedName
if (id == "java.lang.System.exit") {
error(
"Forbidden call to the exit function. The killing feature of the agent must be used.",
expression,
null,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE)
}
}

@Check(CheckType.FAST)
public def checkForbiddenCalls(XMemberFeatureCall expression) {
expression.checkForbiddenFeatureCall
}

@Check(CheckType.FAST)
public def checkForbiddenCalls(XFeatureCall expression) {
expression.checkForbiddenFeatureCall
}

// @Check(CheckType.FAST)
// public def checkDiscouragedCalls(XMemberFeatureCall expression) {
// if (!isIgnored(org.eclipse.xtext.xbase.validation.IssueCodes::DISCOURAGED_REFERENCE)) {
// }
// var id = expression.feature.identifier
// if (id.startsWith("java.lang.System")) {
// switch (id) {
// case "java.lang.System.exit": {
// false
// }
// case "java.lang.System.err", "java.lang.System.out",
// "java.lang.System.setErr", "java.lang.System.setOut",
// "java.lang.System.console": {
// false
// }
// case "java.lang.System.in",
// "java.lang.System.setIn": {
// false
// }
// default: {
// false
// }
// }
// // exit
// // console
// // inheritedChannel
//
// }
// }

/**
* @param feature
Expand Down

0 comments on commit 28d0e3c

Please sign in to comment.