Skip to content

Commit

Permalink
[ui] Add special highlighting for capacity methods.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Sep 20, 2018
1 parent ad0568f commit a0f5e00
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 152 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/08/17]
\ProvidesPackage{sarl-beamer-listing}[2018/09/17]
\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/08/17]
\ProvidesPackage{sarl-colorized-listing}[2018/09/17]
\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/08/17]
\ProvidesPackage{sarl-listing}[2018/09/17]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down
Expand Up @@ -658,6 +658,10 @@ Workflow {
to = "io.sarl.lang.ui.highlighting.SARLHighlightingCalculator"
functionName = "bindIdeSemanticHighlightingCalculator"
}
ui = {
bind = "org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration"
to = "io.sarl.lang.ui.highlighting.SARLHighlightingConfiguration"
}
ui = {
bind = "org.eclipse.xtext.tasks.ITaskTagProvider"
to = "io.sarl.lang.ui.tasks.SarlTaskTagProvider"
Expand Down Expand Up @@ -982,10 +986,6 @@ Workflow {
bind = "org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider"
to = "org.eclipse.xtend.ide.hover.XtendHoverProvider"
}
ui = {
bind = "org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration"
to = "org.eclipse.xtend.ide.highlighting.XtendHighlightingConfiguration"
}
ui = {
bind = "org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper"
to = "org.eclipse.xtend.ide.hyperlinking.XtendHyperlinkHelper"
Expand Down
3 changes: 1 addition & 2 deletions main/coreplugins/io.sarl.lang.ui/META-INF/MANIFEST.MF
Expand Up @@ -53,7 +53,6 @@ Export-Package: io.sarl.lang.ide,
io.sarl.lang.ui.quickfix.acceptors,
io.sarl.lang.ui.refactoring.rename,
io.sarl.lang.ui.tasks,
io.sarl.lang.ui.validation,
io.sarl.lang.validation
io.sarl.lang.ui.validation
Import-Package: org.apache.log4j,
org.eclipse.xtext.ui.codemining;resolution:=optional
Expand Up @@ -56,6 +56,7 @@
import io.sarl.lang.ui.extralanguage.preferences.PreferenceBasedFeatureNameConverterRuleReader;
import io.sarl.lang.ui.extralanguage.preferences.PreferenceBasedTypeConverterRuleReader;
import io.sarl.lang.ui.highlighting.SARLHighlightingCalculator;
import io.sarl.lang.ui.highlighting.SARLHighlightingConfiguration;
import io.sarl.lang.ui.hover.SARLHoverSerializer;
import io.sarl.lang.ui.hover.SARLHoverSignatureProvider;
import io.sarl.lang.ui.hover.SARLHoverUIStrings;
Expand Down Expand Up @@ -110,7 +111,6 @@
import org.eclipse.xtend.ide.editor.SingleLineCommentHelper;
import org.eclipse.xtend.ide.editor.XtendDoubleClickStrategyProvider;
import org.eclipse.xtend.ide.editor.XtendSourceViewerConfiguration;
import org.eclipse.xtend.ide.highlighting.XtendHighlightingConfiguration;
import org.eclipse.xtend.ide.hover.XtendAnnotationHover;
import org.eclipse.xtend.ide.hover.XtendHoverProvider;
import org.eclipse.xtend.ide.hover.XtendHoverSerializer;
Expand Down Expand Up @@ -684,6 +684,11 @@ public Class<? extends IQualifiedNameImageProvider> bindIQualifiedNameImageProvi
return SARLLabelProvider.class;
}

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

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings provided by SARL API]
public Class<? extends XtendFieldBuilder> bindXtendFieldBuilder() {
return SarlFieldBuilder.class;
Expand Down Expand Up @@ -760,11 +765,6 @@ public Class<? extends IProposalConflictHelper> bindIProposalConflictHelper() {
return FlexProposalConflictHelper.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
return XtendHighlightingConfiguration.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings required by extended Xtend API]
public Class<? extends IEObjectHoverProvider> bindIEObjectHoverProvider() {
return XtendHoverProvider.class;
Expand Down

This file was deleted.

Expand Up @@ -26,17 +26,27 @@
import javax.inject.Inject;

import org.eclipse.xtend.ide.common.highlighting.XtendHighlightingCalculator;
import org.eclipse.xtext.common.types.JvmDeclaredType;
import org.eclipse.xtext.common.types.JvmGenericType;
import org.eclipse.xtext.common.types.JvmIdentifiableElement;
import org.eclipse.xtext.common.types.JvmOperation;
import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor;
import org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration;
import org.eclipse.xtext.xbase.XAbstractFeatureCall;

import io.sarl.lang.services.SARLGrammarKeywordAccess;
import io.sarl.lang.typesystem.InheritanceHelper;

/**
* A base implementation of the semantic highlighting calculation.
*
* <p>Uses syntax highlighting from {@link XtendHighlightingCalculator} and
* adds SARL specific keywords, e.g. <code>occurrence</code>.
*
* <p>This calculator also highlight with a specific color the calls to the capacity methods.
*
* @author $Author: srodriguez$
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
Expand All @@ -46,11 +56,42 @@ public class SARLHighlightingCalculator extends XtendHighlightingCalculator {
@Inject
private SARLGrammarKeywordAccess grammarKeywordAccess;

@Inject
private InheritanceHelper inheritanceHelper;

@Override
protected Map<String, String> initializeHighlightedIdentifiers() {
final Map<String, String> result = super.initializeHighlightedIdentifiers();
result.put(this.grammarKeywordAccess.getOccurrenceKeyword(), DefaultHighlightingConfiguration.KEYWORD_ID);
return result;
}

@SuppressWarnings("checkstyle:all")
@Override
protected void computeFeatureCallHighlighting(XAbstractFeatureCall featureCall, IHighlightedPositionAcceptor acceptor) {
super.computeFeatureCallHighlighting(featureCall, acceptor);

JvmIdentifiableElement feature = featureCall.getFeature();
if (feature != null && !feature.eIsProxy() && feature instanceof JvmOperation && !featureCall.isOperation()) {
if (isCapacityMethodCall((JvmOperation) feature)) {
highlightFeatureCall(featureCall, acceptor, SARLHighlightingStyles.CAPACITY_METHOD_INVOCATION);
}
}
}

/** Replies if the given call is for a capacity function call.
*
* @param feature the feature to test.
* @return {@code true} if the feature is capacity(s method.
*/
protected boolean isCapacityMethodCall(JvmOperation feature) {
if (feature != null) {
final JvmDeclaredType container = feature.getDeclaringType();
if (container instanceof JvmGenericType) {
return this.inheritanceHelper.isSarlCapacity((JvmGenericType) container);
}
}
return false;
}

}
@@ -0,0 +1,63 @@
/*
* $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.ui.highlighting;

import org.eclipse.swt.SWT;
import org.eclipse.xtend.ide.highlighting.XtendHighlightingConfiguration;
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfigurationAcceptor;
import org.eclipse.xtext.ui.editor.utils.TextStyle;

/**
* The configuration for the SARL highlithing system.
*
* <p>This configuration supports the highlighting with a specific color the calls to the capacity methods.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public class SARLHighlightingConfiguration extends XtendHighlightingConfiguration {

@Override
public void configure(IHighlightingConfigurationAcceptor acceptor) {
super.configure(acceptor);
acceptor.acceptDefaultHighlighting(
SARLHighlightingStyles.CAPACITY_METHOD_INVOCATION,
"Capacity method invocations", //$NON-NLS-1$
capacityMethodInvocation());
}

/** Style for the capacity method extension.
*
* @return the style.
*/
@SuppressWarnings("checkstyle:magicnumber")
public TextStyle capacityMethodInvocation() {
final TextStyle textStyle = extensionMethodInvocation().copy();
//textStyle.setColor(new RGB(128, 36, 0));
textStyle.setStyle(SWT.ITALIC);
return textStyle;
}

}
@@ -0,0 +1,42 @@
/*
* $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.ui.highlighting;

import org.eclipse.xtend.ide.common.highlighting.XtendHighlightingStyles;

/**
* Highlighting styles for SARL.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
@SuppressWarnings("checkstyle:interfaceistype")
public interface SARLHighlightingStyles extends XtendHighlightingStyles {

/** Style for a call to a capacity's method.
*/
String CAPACITY_METHOD_INVOCATION = "sarl.capacity.method.invocation"; //$NON-NLS-1$

}

0 comments on commit a0f5e00

Please sign in to comment.