/
SARLOutlineNodeComparator.java
130 lines (121 loc) · 4.52 KB
/
SARLOutlineNodeComparator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2015 Sebastian RODRIGUEZ, Nicolas GAUD, Stéphane GALLAND.
*
* 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.outline;
import static io.sarl.lang.sarl.SarlPackage.Literals.SARL_BEHAVIOR_UNIT;
import static io.sarl.lang.sarl.SarlPackage.Literals.SARL_CAPACITY_USES;
import static io.sarl.lang.sarl.SarlPackage.Literals.SARL_REQUIRED_CAPACITY;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_CONSTRUCTOR;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_FIELD;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_FILE__PACKAGE;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_FUNCTION;
import static org.eclipse.xtext.xtype.XtypePackage.Literals.XIMPORT_SECTION;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.xtend.core.xtend.XtendPackage;
import org.eclipse.xtext.common.types.TypesPackage;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
import org.eclipse.xtext.ui.editor.outline.actions.SortOutlineContribution.DefaultComparator;
import org.eclipse.xtext.ui.editor.outline.impl.EObjectNode;
import org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode;
/**
* Comparator of nodes in the SARL outline.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
public class SARLOutlineNodeComparator extends DefaultComparator {
private static final int SCRIPT_PRIORITY = 0;
private static final int IMPORT_PRIORITY = 10;
private static final int TOPELEMENT_PRIORITY = 20;
private static final int CAPACITY_USE_PRIORITY = 30;
private static final int CAPACITY_REQUIREMENT_PRIORITY = 40;
private static final int STATIC_INNER_TYPE_PRIORITY = 50;
private static final int INNER_TYPE_PRIORITY = 60;
private static final int STATIC_FIELD_PRIORITY = 70;
private static final int STATIC_METHOD_PRIORITY = 80;
private static final int FIELD_PRIORITY = 90;
private static final int CONSTRUCTOR_PRIORITY = 100;
private static final int BEHAVIOR_UNIT_PRIORITY = 110;
private static final int METHOD_PRIORITY = 120;
/**
*/
public SARLOutlineNodeComparator() {
//
}
@Override
public int getCategory(IOutlineNode node) {
if (node instanceof EStructuralFeatureNode) {
EStructuralFeature feature = ((EStructuralFeatureNode) node).getEStructuralFeature();
if (feature == XTEND_FILE__PACKAGE) {
return SCRIPT_PRIORITY;
}
return TOPELEMENT_PRIORITY;
}
if (node instanceof EObjectNode) {
EObjectNode objectNode = (EObjectNode) node;
EClass eClass = objectNode.getEClass();
if (XIMPORT_SECTION.isSuperTypeOf(eClass)) {
return IMPORT_PRIORITY;
}
if (XtendPackage.Literals.XTEND_TYPE_DECLARATION.isSuperTypeOf(eClass)
|| TypesPackage.Literals.JVM_DECLARED_TYPE.isSuperTypeOf(eClass)
|| TypesPackage.Literals.JVM_ENUMERATION_LITERAL.isSuperTypeOf(eClass)) {
if (isStatic(objectNode)) {
return STATIC_INNER_TYPE_PRIORITY;
}
return INNER_TYPE_PRIORITY;
}
if (SARL_CAPACITY_USES.isSuperTypeOf(eClass)) {
return CAPACITY_USE_PRIORITY;
}
if (SARL_REQUIRED_CAPACITY.isSuperTypeOf(eClass)) {
return CAPACITY_REQUIREMENT_PRIORITY;
}
if (XTEND_FIELD.isSuperTypeOf(eClass)) {
if (isStatic(objectNode)) {
return STATIC_FIELD_PRIORITY;
}
return FIELD_PRIORITY;
}
if (XTEND_FUNCTION.isSuperTypeOf(eClass)) {
if (isStatic(objectNode)) {
return STATIC_METHOD_PRIORITY;
}
return METHOD_PRIORITY;
}
if (XTEND_CONSTRUCTOR.isSuperTypeOf(eClass)) {
return CONSTRUCTOR_PRIORITY;
}
if (SARL_BEHAVIOR_UNIT.isSuperTypeOf(eClass)) {
return BEHAVIOR_UNIT_PRIORITY;
}
}
return Integer.MAX_VALUE;
}
private static boolean isStatic(EObjectNode eobjectNode) {
if (eobjectNode instanceof SARLEObjectNode) {
return ((SARLEObjectNode) eobjectNode).isStatic();
}
return false;
}
}