Commit 61565fa8 authored by Sudeep Kanav's avatar Sudeep Kanav
Browse files

YELLOW

parent df28d8ba
......@@ -13,6 +13,7 @@ Bundle-Vendor: fortiss GmbH
Export-Package: org.fortiss.af3.component.ui,
org.fortiss.af3.component.ui.behavior,
org.fortiss.af3.component.ui.editor,
org.fortiss.af3.component.ui.editor.code,
org.fortiss.af3.component.ui.editor.datastate,
org.fortiss.af3.component.ui.editpart,
org.fortiss.af3.component.ui.editpart.figure,
......
......@@ -82,7 +82,7 @@ import org.fortiss.tooling.kernel.ui.service.IActionService;
* @author doebber
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: E93A0A73AF5BEA3076CD917D10B6BAD0
* @ConQAT.Rating YELLOW Hash: C387087233F1263E3ED90AF93259D93A
*/
public class CodeSpecificationEditor extends EditorBase<CodeSpecification> {
......@@ -94,7 +94,7 @@ public class CodeSpecificationEditor extends EditorBase<CodeSpecification> {
private ScrolledForm scrldfrmCodeSpecification;
/** Stores the source viewer. */
private SourceViewer codeViewer;
protected SourceViewer codeViewer;
/** Stores the annotation model. */
private AnnotationModel annotationModel = new AnnotationModel();
......@@ -203,7 +203,7 @@ public class CodeSpecificationEditor extends EditorBase<CodeSpecification> {
* Creates the SourceViewerConfiguration containing the setup for both syntax highlighting and
* content assist.
*/
private SourceViewerConfiguration getSourceViewerConfig() {
protected SourceViewerConfiguration getSourceViewerConfig() {
return new CodeEditorConfiguration(this);
}
......@@ -300,7 +300,7 @@ public class CodeSpecificationEditor extends EditorBase<CodeSpecification> {
}
/** Performs the text to model binding. */
private void updateModel() {
protected void updateModel() {
IObservableValue modelObservable =
observeValue(getEditedObject(), CodePackage.Literals.CODE_SPECIFICATION__BODY);
performComplexTextBinding(dbc, codeViewer.getTextWidget(), modelObservable,
......
......@@ -25,6 +25,7 @@ import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.get
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveTypes;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getPrimitiveValues;
import static org.fortiss.af3.expression.ui.utils.ExpressionFieldAssistUtils.getUsefulExpressions;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstParentWithType;
import java.util.ArrayList;
import java.util.List;
......@@ -56,6 +57,7 @@ import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.ui.editor.CodeSpecificationEditor;
import org.fortiss.af3.component.ui.utils.CodeUtils;
import org.fortiss.tooling.base.ui.fieldassist.FieldAssistImageRegistry;
......@@ -66,12 +68,12 @@ import org.fortiss.tooling.base.ui.fieldassist.FieldAssistImageRegistry;
* @author doebber
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 47BF13F8614FFAADD61BD9EC28C0D506
* @ConQAT.Rating YELLOW Hash: 2E1C1B76848CB0AF834371DC66366C1C
*/
public class CodeEditorConfiguration extends SourceViewerConfiguration {
/** Stores the actual editor object. */
private CodeSpecificationEditor editor;
protected CodeSpecificationEditor editor;
/** Constructor. */
public CodeEditorConfiguration(CodeSpecificationEditor editor) {
......@@ -79,10 +81,25 @@ public class CodeEditorConfiguration extends SourceViewerConfiguration {
}
/** Color constant used to display code dark red. */
private Color DARK_RED = new Color(null, 128, 0, 0);
protected Color DARK_RED = new Color(null, 128, 0, 0);
/** Color constant used to display code dark blue. */
private Color DARK_BLUE = new Color(null, 0, 0, 128);
protected Color DARK_BLUE = new Color(null, 0, 0, 128);
/** Detector used to create the scanners. */
protected IWordDetector detector = new IWordDetector() {
/** {@inheritDoc} */
@Override
public boolean isWordStart(char c) {
return Character.isLetterOrDigit(c);
}
/** {@inheritDoc} */
@Override
public boolean isWordPart(char c) {
return Character.isLetterOrDigit(c) || c == '_';
}
};
/** {@inheritDoc} */
@Override
......@@ -165,9 +182,8 @@ public class CodeEditorConfiguration extends SourceViewerConfiguration {
viewer.getDocument().get(currentWordRegion.getOffset(),
currentWordRegion.getLength());
ArrayList<String> prop =
getInputPortNames(editor.getEditedObject().getComponent());
prop.addAll(getOutputPortNames(editor.getEditedObject().getComponent()));
ArrayList<String> prop = getInputPortNames(getAssociatedComponent());
prop.addAll(getOutputPortNames(getAssociatedComponent()));
prop.addAll(getFunctions(editor.getEditedObject()));
prop.addAll(getAllConstructors(editor.getEditedObject(), true));
prop.addAll(getPrimitiveValues());
......@@ -201,39 +217,45 @@ public class CodeEditorConfiguration extends SourceViewerConfiguration {
/** Returns the rule based scanner. */
private RuleBasedScanner getScannerForSyntaxHighlighting() {
ArrayList<WordRule> rules = new ArrayList<WordRule>();
List<WordRule> rules = getCommonRules();
rules.add(getRuleSpecificToEditor());
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setRules(rules.toArray(new IRule[0]));
return scanner;
}
IWordDetector detector = new IWordDetector() {
/** {@inheritDoc} */
@Override
public boolean isWordStart(char c) {
return Character.isLetterOrDigit(c);
}
/** Returns a list of rules common for the syntax highlighting. */
private List<WordRule> getCommonRules() {
ArrayList<WordRule> rules = new ArrayList<WordRule>();
/** {@inheritDoc} */
@Override
public boolean isWordPart(char c) {
return Character.isLetterOrDigit(c) || c == '_';
}
};
WordRule keywordsRule = new WordRule(detector);
rules.add(keywordsRule);
WordRule portsRule = new WordRule(detector);
rules.add(portsRule);
WordRule dataelementsRule = new WordRule(detector);
rules.add(dataelementsRule);
final IToken keywordToken = new Token(new TextAttribute(DARK_RED, null, SWT.BOLD));
final IToken portToken = new Token(new TextAttribute(null, null, SWT.BOLD));
final IToken dataElementToken = new Token(new TextAttribute(DARK_BLUE, null, SWT.ITALIC));
ArrayList<String> ports = getInputPortNames(editor.getEditedObject().getComponent());
ports.addAll(getOutputPortNames(editor.getEditedObject().getComponent()));
ArrayList<String> ports = getInputPortNames(getAssociatedComponent());
ports.addAll(getOutputPortNames(getAssociatedComponent()));
addWordsToRule(ports, portsRule, portToken);
ArrayList<String> dataelements = getFunctions(editor.getEditedObject());
dataelements.addAll(getAllConstructorsWithoutBrackets(editor.getEditedObject(), false));
addWordsToRule(dataelements, dataelementsRule, dataElementToken);
return rules;
}
/** Returns the component associated to the editor. */
private Component getAssociatedComponent() {
return getFirstParentWithType(editor.getEditedObject(), Component.class);
}
/** Returns a rule specific to the editor. */
protected WordRule getRuleSpecificToEditor() {
WordRule keywordsRule = new WordRule(detector);
final IToken keywordToken = new Token(new TextAttribute(DARK_RED, null, SWT.BOLD));
ArrayList<String> keywords = new ArrayList<String>();
keywords.addAll(getPrimitiveValues());
keywords.addAll(getPrimitiveTypes());
......@@ -242,14 +264,11 @@ public class CodeEditorConfiguration extends SourceViewerConfiguration {
keywords.add("return");
keywords.add("NoVal");
addWordsToRule(keywords, keywordsRule, keywordToken);
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setRules(rules.toArray(new IRule[0]));
return scanner;
return keywordsRule;
}
/** Adds the words to the rule with the given token. */
private void addWordsToRule(List<String> words, WordRule rule, IToken token) {
protected void addWordsToRule(List<String> words, WordRule rule, IToken token) {
for(String word : words) {
rule.addWord(word, token);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment