org.eclipse.xtext.xbase.validation.IssueCodes Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.validation.IssueCodes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XbaseValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testRedundantCases_03() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("switch i : 1 {"); _builder.newLine(); _builder.append("\t"); _builder.append("case 1,"); _builder.newLine(); _builder.append("\t"); _builder.append("default: 1"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertWarning(this.expression(_builder), XbasePackage.Literals.XCASE_PART, IssueCodes.REDUNDANT_CASE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #2
Source File: XbaseTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected void checkValidReturnExpression(XExpression returnValue, ITypeComputationState expressionState) { ITypeComputationResult result = expressionState.computeTypes(returnValue); LightweightTypeReference actualType = result.getActualExpressionType(); int conformanceFlags = result.getConformanceFlags(); if (actualType.isPrimitiveVoid() && (conformanceFlags & ConformanceFlags.NO_IMPLICIT_RETURN) != 0) { String message = "Invalid return's expression."; if (returnValue instanceof XReturnExpression) { // when the return's expression is directory a return // we provide a more detailed error message = "Return cannot be nested."; } expressionState.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.INVALID_RETURN, message, returnValue, null, -1, new String[] { })); } }
Example #3
Source File: XbaseValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testDuplicateCases_int_8() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("switch x : 1 {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("case x: \'\'"); _builder.newLine(); _builder.append("\t\t"); _builder.append("case x: \'1\'"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertError(this.expression(_builder), XbasePackage.Literals.XFEATURE_CALL, IssueCodes.DUPLICATE_CASE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #4
Source File: CapacityQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixInvalidCapacityType_5() { assertQuickFix(io.sarl.lang.validation.IssueCodes.INVALID_CAPACITY_TYPE, // // Code to fix: // multilineString("event E1", "capacity C1 { }", "capacity C2 { }", "agent A1 {", " requires E1, C1, C2", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("event E1", "capacity C1 { }", "capacity C2 { }", "agent A1 {", " requires C1, C2", "}")); }
Example #5
Source File: CapacityQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixUnusedAgentCapacity_0() { assertQuickFix(io.sarl.lang.validation.IssueCodes.UNUSED_AGENT_CAPACITY, // // Code to fix: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "capacity C3 { def myfct2 }", "agent A1 {", " uses C1, C2, C3", " def testfct { myfct; myfct2 }", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "capacity C3 { def myfct2 }", "agent A1 {", " uses C1, C3", " def testfct { myfct; myfct2 }", "}")); }
Example #6
Source File: EarlyExistParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void earlyExistFunction_inWhile_0() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import io.sarl.lang.annotation.EarlyExit", "class EarlyExitFunctionDefinitions {", " @EarlyExit", " static def killFunction2 {", " }", "}", "agent A1 {", " def caller {", " while (true) {", " EarlyExitFunctionDefinitions::killFunction2", " }", " println(\"Hello\")", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertError( XbasePackage.eINSTANCE.getXFeatureCall(), IssueCodes.UNREACHABLE_CODE, "Unreachable expression"); }
Example #7
Source File: LambdaValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testIncompatibleReturnType_01() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class C {"); _builder.newLine(); _builder.append("\t"); _builder.append("val I<Integer> f = [int k| \'\']"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("interface I<T> {"); _builder.newLine(); _builder.append("\t"); _builder.append("def T m(int u);"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertError(this.file(_builder.toString()), XbasePackage.Literals.XCLOSURE, IssueCodes.INCOMPATIBLE_TYPES, "Type mismatch: cannot convert from (int)=>String to I<Integer>"); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #8
Source File: ForbiddenCallTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void systemExit_behavior_behaviorUnit_extension() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import static extension java.lang.System.*", "event E1 { }", "behavior B1 {", "on E1 {", "0.exit", "}", "}" )); validate(getValidationHelper(), getInjector(), mas).assertError( XbasePackage.eINSTANCE.getXMemberFeatureCall(), IssueCodes.FORBIDDEN_REFERENCE, "Forbidden feature call: java.lang.System.exit(int)"); }
Example #9
Source File: RootResolvedTypes.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected AbstractDiagnostic createTypeDiagnostic(XExpression expression, LightweightTypeReference actualType, LightweightTypeReference expectedType) { if (!expectedType.isAny()) { String actualName = actualType.getSimpleName(); String expectedName = expectedType.getSimpleName(); if (actualName.equals(expectedName)) { if (expectedType.isAssignableFrom(actualType)) { return null; } } if (expression.eContainingFeature() == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__IMPLICIT_FIRST_ARGUMENT) { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert implicit first argument from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: cannot convert from %s to %s", actualType.getHumanReadableName(), expectedType.getHumanReadableName()), expression, null, -1, null); } } else { return new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.INCOMPATIBLE_TYPES, String.format( "Type mismatch: type %s is not applicable at this location", actualType.getHumanReadableName()), expression, null, -1, null); } }
Example #10
Source File: ValidationTests.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testDuplicatedProperty() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("entity E {"); _builder.newLine(); _builder.append("\t"); _builder.append("p : String"); _builder.newLine(); _builder.append("\t"); _builder.append("p : String"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String model = _builder.toString(); DomainModel _parse = this._parseHelper.parse(model); final Procedure1<DomainModel> _function = (DomainModel it) -> { this.assertNumberOfIssues(it, 2); this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.indexOf("p"), 1, "Duplicate property p"); this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.lastIndexOf("p"), 1, "Duplicate property p"); }; ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #11
Source File: CodeStyleValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testConstructorCallWithoutParenthesis() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t\t\t"); _builder.append("new String"); _builder.newLine(); _builder.append("\t\t"); _builder.append("}"); this.helper.assertWarning(this.expression(_builder), XbasePackage.Literals.XCONSTRUCTOR_CALL, IssueCodes.OPERATION_WITHOUT_PARENTHESES); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #12
Source File: ThreadTypeTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void inAgent_inFunction_01() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "agent A1 {", " def fct(x : int) : int {", " Thread::sleep(5)", " return x + 1", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXAbstractFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "sleep"); }
Example #13
Source File: ThreadTypeTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void inSkill_inFunction_01() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "skill S1 {", " def fct(x : int) : int {", " Thread::sleep(5)", " return x + 1", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXAbstractFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "sleep"); }
Example #14
Source File: XbaseValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnreachableCatchClause_3() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("try {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("} catch (java.io.IOException e) {"); _builder.newLine(); _builder.newLine(); _builder.append("} catch (java.io.FileNotFoundException e) {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("} catch (Exception e) {"); _builder.newLine(); _builder.append("\t"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertError(this.expression(_builder), TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE, IssueCodes.UNREACHABLE_CATCH_BLOCK); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #15
Source File: ThreadTypeTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void inBehavior_inFunction_03() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import static extension java.lang.Thread.*", "behavior B1 {", " def fct(x : int) : int {", " 5.sleep", " return x + 1", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXAbstractFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "sleep"); }
Example #16
Source File: DiscouragedSystemCallTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void systemSetOut_skill_constructor() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import io.sarl.lang.core.Agent", "capacity C1 { }", "skill S1 implements C1 {", " new (a : Agent) {", " super(a)", " System.setOut(null)", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXMemberFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "Discouraged feature call"); }
Example #17
Source File: DiscouragedSystemCallTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void systemSetOut_skill_constructor_staticImport() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import io.sarl.lang.core.Agent", "import static java.lang.System.*", "capacity C1 { }", "skill S1 implements C1 {", " new (a : Agent) {", " super(a)", " setOut(null)", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "Discouraged feature call"); }
Example #18
Source File: FiredEventsQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixInvalidFiringEventType_1() { assertQuickFix(io.sarl.lang.validation.IssueCodes.INVALID_FIRING_EVENT_TYPE, // // Code to fix: // multilineString("event E1", "event E2", "capacity C1 { }", "agent A1 {", " def myfct fires E1, C1, E2 { }", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("event E1", "event E2", "capacity C1 { }", "agent A1 {", " def myfct fires E1, E2 { }", "}")); }
Example #19
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void missedActionImplementation_2() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "capacity C1 {", " def myaction1(a : int=4)", "}", "capacity C2 {", " def myaction2(b : float=6, c : boolean)", "}", "skill S1 implements C1, C2 {", " def myaction1(x : float) { }", " def myaction2(y : float, z : boolean) { }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertError( SarlPackage.eINSTANCE.getSarlSkill(), org.eclipse.xtend.core.validation.IssueCodes.CLASS_MUST_BE_ABSTRACT, "The class S1 must be defined abstract because it does not implement myaction1(int)"); }
Example #20
Source File: CapacityQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixInvalidCapacityType_7() { assertQuickFix(io.sarl.lang.validation.IssueCodes.INVALID_CAPACITY_TYPE, // // Code to fix: // multilineString("event E1", "capacity C1 { }", "capacity C2 { }", "agent A1 {", " requires C1, C2, E1", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("event E1", "capacity C1 { }", "capacity C2 { }", "agent A1 {", " requires C1, C2", "}")); }
Example #21
Source File: XbaseValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testSwitchDeclaredParameter() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("switch Object x : \"lalala\" {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XExpression block = this.expression(_builder); this._validationTestHelper.assertNoErrors(block); this._validationTestHelper.assertWarning(block, TypesPackage.Literals.JVM_FORMAL_PARAMETER, IssueCodes.UNUSED_LOCAL_VARIABLE); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #22
Source File: CapacityQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixRedundantCapacityUse_5() { assertQuickFix(io.sarl.lang.validation.IssueCodes.REDUNDANT_CAPACITY_USE, // // Code to fix: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "agent A1 {", " uses C1, C2", " def testfct { myfct; iddle }", " uses C1, C2, C1", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "agent A1 {", " uses C1, C2", " def testfct { myfct; iddle }", " uses C2, C1", "}")); }
Example #23
Source File: XbaseValidationTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void testIncompleteCasesOnEnum_7() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); _builder.append("switch org.eclipse.xtext.xbase.tests.validation.Color x : org.eclipse.xtext.xbase.tests.validation.Color.RED {"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertWarning(this.expression(_builder), XbasePackage.Literals.XMEMBER_FEATURE_CALL, IssueCodes.INCOMPLETE_CASES_ON_ENUM); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #24
Source File: ValidationBug398302Test.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void test_01() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("class C {"); _builder.newLine(); _builder.append("\t"); _builder.append("def m() {"); _builder.newLine(); _builder.append("\t\t"); _builder.append("String.CASE_INSENSITIVE_ORDER = null"); _builder.newLine(); _builder.append("\t"); _builder.append("}"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final String s = _builder.toString(); final XtendFile file = this.parser.parse(s); final String fieldName = "CASE_INSENSITIVE_ORDER"; this.helper.assertError(file, XbasePackage.Literals.XASSIGNMENT, IssueCodes.ASSIGNMENT_TO_FINAL, s.indexOf(fieldName), fieldName.length()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #25
Source File: ForbiddenCallTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void systemExit_skill_constructor_staticImport() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "import io.sarl.lang.core.Agent", "import static java.lang.System.*", "capacity C1 { }", "event E1 { }", "skill S1 implements C1 {", "new (a : Agent) {", "super(a)", "exit(0)", "}", "}" )); validate(getValidationHelper(), getInjector(), mas).assertError( XbasePackage.eINSTANCE.getXFeatureCall(), IssueCodes.FORBIDDEN_REFERENCE, "Forbidden feature call: java.lang.System.exit(int)"); }
Example #26
Source File: ArgDefaultValueParsingTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void constructorCast_String2int() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "package io.sarl.test", "behavior B1 {", "new(arg0 : int=45, arg1 : int=\"S\", arg2 : int) {", "System.out.println(arg0)", "}", "}" )); validate(getValidationHelper(), getInjector(), mas).assertError( XbasePackage.eINSTANCE.getXStringLiteral(), IssueCodes.INCOMPATIBLE_TYPES, "Type mismatch: cannot convert from String to int"); }
Example #27
Source File: DiscouragedSystemCallTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void systemSetErr_skill_action() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "capacity C1 { }", "skill S1 implements C1 {", " def test {", " System.setErr(null)", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXMemberFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "Discouraged feature call"); }
Example #28
Source File: CapacityQuickfixTest.java From sarl with Apache License 2.0 | 6 votes |
/** */ @Test public void fixUnusedAgentCapacity_6() { assertQuickFix(io.sarl.lang.validation.IssueCodes.UNUSED_AGENT_CAPACITY, // // Code to fix: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "capacity C3 { def myfct2 }", "behavior B1 {", " uses C1, C2, C3", " def testfct { myfct; myfct2 }", "}"), // // Label and description: // "Remove", // // Expected fixed code: // multilineString("capacity C1 { def myfct }", "capacity C2 { def iddle }", "capacity C3 { def myfct2 }", "behavior B1 {", " uses C1, C3", " def testfct { myfct; myfct2 }", "}")); }
Example #29
Source File: ValidationTests.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testImportUnused_1() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("import java.util.List"); _builder.newLine(); _builder.append("entity X {"); _builder.newLine(); _builder.append("\t"); _builder.append("sb: java.util.List<String>"); _builder.newLine(); _builder.append("}"); _builder.newLine(); this._validationTestHelper.assertWarning(this._parseHelper.parse(_builder), XtypePackage.Literals.XIMPORT_DECLARATION, IssueCodes.IMPORT_UNUSED); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #30
Source File: ThreadTypeTest.java From sarl with Apache License 2.0 | 6 votes |
@Test @Tag("sarlValidation") public void inBehavior_inEventHandler_01() throws Exception { SarlScript mas = file(getParseHelper(), multilineString( "event Evt", "behavior B1 {", " on Evt {", " Thread::yield", " }", "}" )); validate(getValidationHelper(), getInjector(), mas).assertWarning( XbasePackage.eINSTANCE.getXAbstractFeatureCall(), IssueCodes.DISCOURAGED_REFERENCE, "yield"); }