Skip to content

Commit

Permalink
[lang][ui] Add detection of the potential field synchronization probl…
Browse files Browse the repository at this point in the history
…ems.

close #810

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Feb 15, 2018
1 parent 9d96829 commit f9f24fe
Show file tree
Hide file tree
Showing 15 changed files with 725 additions and 28 deletions.
2 changes: 1 addition & 1 deletion formatting-styles/latex/sarl-beamer-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-beamer-listing}[2018/02/04]
\ProvidesPackage{sarl-beamer-listing}[2018/02/15]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down
2 changes: 1 addition & 1 deletion formatting-styles/latex/sarl-colorized-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-colorized-listing}[2018/02/04]
\ProvidesPackage{sarl-colorized-listing}[2018/02/15]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down
2 changes: 1 addition & 1 deletion formatting-styles/latex/sarl-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-listing}[2018/02/04]
\ProvidesPackage{sarl-listing}[2018/02/15]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down
Expand Up @@ -552,6 +552,10 @@ Workflow {
to = "io.sarl.lang.compiler.SARLJvmGenerator"
functionName = "configureIGenerator2ExtraLanguageMainGenerator"
}
runtime = {
bind = "org.eclipse.xtext.xbase.validation.ReadAndWriteTracking"
to = "io.sarl.lang.jvmmodel.SARLReadAndWriteTracking"
}

ui = {
bind = "org.eclipse.xtext.generator.IOutputConfigurationProvider"
Expand Down
Expand Up @@ -59,6 +59,7 @@ private Messages() {
public static String SARLValidatorConfigurationBlock_15;
public static String SARLValidatorConfigurationBlock_16;
public static String SARLValidatorConfigurationBlock_17;
public static String SARLValidatorConfigurationBlock_18;
public static String SARLValidatorConfigurationBlock_6;
public static String SARLValidatorConfigurationBlock_7;
public static String SARLValidatorConfigurationBlock_8;
Expand Down
Expand Up @@ -101,6 +101,8 @@ protected void fillPotentialProgrammingProblemsSection(ComboBoxBuilder builder)
Messages.SARLValidatorConfigurationBlock_16);
builder.addComboBox(IssueCodes.DISCOURAGED_OCCURRENCE_READONLY_USE,
Messages.SARLValidatorConfigurationBlock_6);
builder.addComboBox(IssueCodes.POTENTIAL_FIELD_SYNCHRONIZATION_PROBLEM,
Messages.SARLValidatorConfigurationBlock_18);
}

@Override
Expand Down
Expand Up @@ -12,10 +12,11 @@ SARLValidatorConfigurationBlock_10=Redundant capacity use:
SARLValidatorConfigurationBlock_11=Unused capacity:
SARLValidatorConfigurationBlock_12=Discouraged function names:
SARLValidatorConfigurationBlock_13=Matching of package name and folder name:
SARLValidatorConfigurationBlock_14=Mark overridding methods with "override":
SARLValidatorConfigurationBlock_14=Mark overriding methods with "override":
SARLValidatorConfigurationBlock_15=Mark abstract methods with "abstract":
SARLValidatorConfigurationBlock_16=Return type specification is recommended:
SARLValidatorConfigurationBlock_17=Discouraged break keyword uses:
SARLValidatorConfigurationBlock_18=Potential field synchronization problem:
SARLValidatorConfigurationBlock_6=Use of occurrence in a not read-only context:
SARLValidatorConfigurationBlock_7=Use of SARL-specific annotations:
SARLValidatorConfigurationBlock_8=Manual @Inline definition:
Expand Up @@ -86,6 +86,7 @@
import io.sarl.lang.formatting2.SARLFormatter;
import io.sarl.lang.formatting2.SARLFormatterPreferenceKeys;
import io.sarl.lang.jvmmodel.SARLJvmModelInferrer;
import io.sarl.lang.jvmmodel.SARLReadAndWriteTracking;
import io.sarl.lang.jvmmodel.SarlJvmModelAssociations;
import io.sarl.lang.parser.antlr.SARLAntlrTokenFileProvider;
import io.sarl.lang.parser.antlr.SARLParser;
Expand Down Expand Up @@ -228,6 +229,7 @@
import org.eclipse.xtext.xbase.validation.EarlyExitValidator;
import org.eclipse.xtext.xbase.validation.FeatureNameValidator;
import org.eclipse.xtext.xbase.validation.ImplicitReturnFinder;
import org.eclipse.xtext.xbase.validation.ReadAndWriteTracking;

/**
* Manual modifications go to {@link SARLRuntimeModule}.
Expand Down Expand Up @@ -577,6 +579,11 @@ public Class<? extends FormatterPreferenceKeys> bindFormatterPreferenceKeys() {
return SARLFormatterPreferenceKeys.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings provided by SARL API]
public Class<? extends ReadAndWriteTracking> bindReadAndWriteTracking() {
return SARLReadAndWriteTracking.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings provided by SARL API]
public Class<? extends ExtendedEarlyExitComputer> bindExtendedEarlyExitComputer() {
return ExtendedSARLEarlyExitComputer.class;
Expand Down
@@ -0,0 +1,94 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 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.jvmmodel;

import javax.inject.Singleton;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.xbase.validation.ReadAndWriteTracking;

/** Track the initialization, read and write accesses to a field.
*
* <p>This implementation extends the Xbase one with the write accesses.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.7
*/
@Singleton
public class SARLReadAndWriteTracking extends ReadAndWriteTracking {

private static final Adapter ASSIGNMENT_MARKER = new Adapter() {
@Override
public Notifier getTarget() {
return null;
}

@Override
public boolean isAdapterForType(final Object type) {
return false;
}

@Override
public void notifyChanged(final Notification notification) {
//
}

@Override
public void setTarget(final Notifier newTarget) {
//
}
};

/** Mark the given object as an assigned object after its initialization.
*
* <p>The given object has its value changed by a assignment operation.
*
* @param object the written object.
* @return {@code true} if the write flag has changed.
*/
public boolean markAssignmentAccess(EObject object) {
assert object != null;
if (!isAssigned(object)) {
return object.eAdapters().add(ASSIGNMENT_MARKER);
}
return false;
}

/** Replies if the given object was marked as assigned within the current compilation unit.
*
* @param object the object to test.
* @return {@code true} if the object was written within the current compilation unit;
* {@code false} if is is not written within the current compilation unit.
*/
@SuppressWarnings("static-method")
public boolean isAssigned(final EObject object) {
assert object != null;
return object.eAdapters().contains(ASSIGNMENT_MARKER);
}

}
Expand Up @@ -204,6 +204,13 @@ public final class IssueCodes {
public static final String INVALID_DEFAULT_SKILL_ANNOTATION =
ISSUE_CODE_PREFIX + "invalid_default_skill_annotation"; //$NON-NLS-1$

/**
* A synchronization problem may be encountered on the field.
* @since 0.7
*/
public static final String POTENTIAL_FIELD_SYNCHRONIZATION_PROBLEM =
ISSUE_CODE_PREFIX + "potential_field_synchronization_problem"; //$NON-NLS-1$

private IssueCodes() {
//
}
Expand Down
Expand Up @@ -127,6 +127,7 @@ private Messages() {
public static String SARLValidator_89;
public static String SARLValidator_9;
public static String SARLValidator_90;
public static String SARLValidator_91;
public static String SARLSyntaxErrorMessageProvider_0;
public static String SARLSyntaxErrorMessageProvider_1;
}
Expand Up @@ -116,6 +116,10 @@ protected void initialize(IAcceptor<PreferenceKey> acceptor) {
acceptor.accept(create(
IssueCodes.DISCOURAGED_LOOP_BREAKING_KEYWORD_USE,
SeverityConverter.SEVERITY_WARNING));

acceptor.accept(create(
IssueCodes.POTENTIAL_FIELD_SYNCHRONIZATION_PROBLEM,
SeverityConverter.SEVERITY_WARNING));
}

}

0 comments on commit f9f24fe

Please sign in to comment.