Skip to content

Commit

Permalink
[lang] Fixing the automatic annotation with @pure.
Browse files Browse the repository at this point in the history
close #943

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 18, 2019
1 parent 645ee6f commit e454e62
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 2 deletions.
Expand Up @@ -130,7 +130,7 @@ private static Pattern buildPurePattern(String[] patterns, String... additionalP
* @return {@code true} if the operation has a side effects.
*/
protected boolean isNamePatternForPureOperation(String name) {
return name != null && this.purePattern.matcher(name).find();
return name != null && this.purePattern.matcher(name).matches();
}

@Override
Expand All @@ -149,7 +149,7 @@ public boolean isNamePatternForPureOperation(XtendFunction operation) {
* @return {@code true} if the operation has a side effects.
*/
protected boolean isNamePatternForNotPureOperation(String name) {
return name != null && this.notPurePattern.matcher(name).find();
return name != null && this.notPurePattern.matcher(name).matches();
}

@Override
Expand Down
@@ -0,0 +1,129 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2019 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.tests.bugs.to00999;

import org.junit.Test;

import io.sarl.lang.SARLVersion;
import io.sarl.lang.sarl.SarlPackage;
import io.sarl.lang.sarl.SarlScript;
import io.sarl.tests.api.AbstractSarlTest;

/** Testing class for issue: Invalid @Pure annotation.
*
* <p>https://github.com/sarl/sarl/issues/943
*
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @see "https://github.com/sarl/sarl/issues/943"
*/
@SuppressWarnings("all")
public class Bug943 extends AbstractSarlTest {

/** Expression elements are inside the same resource as the expression.
*/
private static final String SARL_CODE_01 = multilineString(
"package io.sarl.lang.tests.bug943",
"abstract agent X {",
" var sreKernel : Object",
" protected def forgetTheKernel : void {",
" this.sreKernel = null",
" }",
"}");

private static final String JAVA_CODE_01 = multilineString(
"package io.sarl.lang.tests.bug943;",
"",
"import io.sarl.lang.annotation.SarlElementType;",
"import io.sarl.lang.annotation.SarlSpecification;",
"import io.sarl.lang.annotation.SyntheticMember;",
"import io.sarl.lang.core.Agent;",
"import io.sarl.lang.core.BuiltinCapacitiesProvider;",
"import io.sarl.lang.core.DynamicSkillProvider;",
"import java.util.UUID;",
"import javax.inject.Inject;",
"import org.eclipse.xtext.xbase.lib.Pure;",
"",
"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
"@SarlElementType(" + SarlPackage.SARL_AGENT + ")",
"@SuppressWarnings(\"all\")",
"public abstract class X extends Agent {",
" private Object sreKernel;",
" ",
" protected void forgetTheKernel() {",
" this.sreKernel = null;",
" }",
" ",
" @Override",
" @Pure",
" @SyntheticMember",
" public boolean equals(final Object obj) {",
" return super.equals(obj);",
" }",
" ",
" @Override",
" @Pure",
" @SyntheticMember",
" public int hashCode() {",
" int result = super.hashCode();",
" return result;",
" }",
" ",
" @SyntheticMember",
" public X(final UUID arg0, final UUID arg1) {",
" super(arg0, arg1);",
" }",
" ",
" @SyntheticMember",
" @Deprecated",
" @Inject",
" public X(final BuiltinCapacitiesProvider arg0, final UUID arg1, final UUID arg2) {",
" super(arg0, arg1, arg2);",
" }",
" ",
" @SyntheticMember",
" @Inject",
" public X(final UUID arg0, final UUID arg1, final DynamicSkillProvider arg2) {",
" super(arg0, arg1, arg2);",
" }",
"}",
"");

@Test
public void parsing01() throws Exception {
SarlScript mas = file(SARL_CODE_01);
final Validator validator = validate(mas);
validator.assertNoErrors();
}

@Test
public void compiling01() throws Exception {
getCompileHelper().compile(SARL_CODE_01, (it) -> {
String actual;
actual = it.getGeneratedCode("io.sarl.lang.tests.bug943.X");
assertEquals(JAVA_CODE_01, actual);
});
}

}

0 comments on commit e454e62

Please sign in to comment.