Skip to content

Commit

Permalink
[ui] Fixing the ordering and the filtering functions of the outline.
Browse files Browse the repository at this point in the history
close #874

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Oct 11, 2018
1 parent 9bcb724 commit 1ca5735
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 48 deletions.
Expand Up @@ -21,10 +21,9 @@

package io.sarl.lang.ui.outline;

import static io.sarl.lang.sarl.SarlPackage.Literals.SARL_BEHAVIOR_UNIT;
import static io.sarl.lang.ui.outline.SARLOutlineNodeComparator.isBehaviorUnit;

import com.google.inject.Inject;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jface.action.Action;
import org.eclipse.xtext.ui.IImageHelper.IImageDescriptorHelper;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
Expand Down Expand Up @@ -52,16 +51,8 @@ public class SARLBehaviorUnitOutlineFilter extends AbstractFilterOutlineContribu
*/
public static final String ICON_BASENAME = "hide_behavior_units.png"; //$NON-NLS-1$

@Inject private IImageDescriptorHelper imageHelper;

/** Replies if the given type is a behavior unit.
*
* @param type the type to test.
* @return <code>true</code> if the given type is for a behavior unit; <code>false</code> otherwise.
*/
protected static boolean isBehaviorUnit(EClass type) {
return type == SARL_BEHAVIOR_UNIT;
}
@Inject
private IImageDescriptorHelper imageHelper;

@Override
protected boolean apply(IOutlineNode node) {
Expand Down
Expand Up @@ -21,10 +21,9 @@

package io.sarl.lang.ui.outline;

import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_FIELD;
import static io.sarl.lang.ui.outline.SARLOutlineNodeComparator.isField;

import com.google.inject.Inject;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jface.action.Action;
import org.eclipse.xtext.ui.IImageHelper.IImageDescriptorHelper;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
Expand Down Expand Up @@ -55,15 +54,6 @@ public class SARLFieldOutlineFilter extends AbstractFilterOutlineContribution {
@Inject
private IImageDescriptorHelper imageHelper;

/** Replies if the given type is for a SARL field.
*
* @param type the type to test.
* @return <code>true</code> if the given type is for SARL fields, <code>false</code> otherwise.
*/
protected static boolean isField(EClass type) {
return type == XTEND_FIELD;
}

@Override
protected boolean apply(IOutlineNode node) {
if (node instanceof EObjectNode) {
Expand Down
Expand Up @@ -21,12 +21,9 @@

package io.sarl.lang.ui.outline;

import static io.sarl.lang.sarl.SarlPackage.Literals.SARL_ACTION;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_CONSTRUCTOR;
import static org.eclipse.xtend.core.xtend.XtendPackage.Literals.XTEND_FUNCTION;
import static io.sarl.lang.ui.outline.SARLOutlineNodeComparator.isAction;

import com.google.inject.Inject;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jface.action.Action;
import org.eclipse.xtext.ui.IImageHelper.IImageDescriptorHelper;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
Expand Down Expand Up @@ -57,24 +54,13 @@ public class SARLOperationOutlineFilter extends AbstractFilterOutlineContributio
@Inject
private IImageDescriptorHelper imageHelper;

/** Replies if the given type is for a SARL operation.
*
* @param type the type to test.
* @return <code>true</code> if the given type is for a SARL operation; <code>false</code> otherwise.
*/
protected static boolean isOperation(EClass type) {
return type == SARL_ACTION
|| type == XTEND_FUNCTION
|| type == XTEND_CONSTRUCTOR;
}

@Override
protected boolean apply(IOutlineNode node) {
if (node instanceof EObjectNode) {
return !isOperation(((EObjectNode) node).getEClass());
return !isAction(((EObjectNode) node).getEClass());
}
if (node instanceof EStructuralFeatureNode) {
return !isOperation(((EStructuralFeatureNode) node).getEStructuralFeature().eClass());
return !isAction(((EStructuralFeatureNode) node).getEStructuralFeature().eClass());
}
return true;
}
Expand Down
Expand Up @@ -28,6 +28,9 @@
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.common.types.TypesPackage.Literals.JVM_CONSTRUCTOR;
import static org.eclipse.xtext.common.types.TypesPackage.Literals.JVM_FIELD;
import static org.eclipse.xtext.common.types.TypesPackage.Literals.JVM_OPERATION;
import static org.eclipse.xtext.xtype.XtypePackage.Literals.XIMPORT_SECTION;

import org.eclipse.emf.ecore.EClass;
Expand Down Expand Up @@ -83,6 +86,56 @@ public SARLOutlineNodeComparator() {
//
}

/** Replies if the given type corresponds to a field.
*
* @param type the type.
* @return {@code true} if the type corresponds to a SARL, Xtend or JVM field.
* @since 0.9
*/
public static boolean isField(EClass type) {
return XTEND_FIELD.isSuperTypeOf(type) || JVM_FIELD.isSuperTypeOf(type);
}

/** Replies if the given type corresponds to an action.
*
* @param type the type.
* @return {@code true} if the type corresponds to a SARL, Xtend or JVM action/method/operation.
* @since 0.9
*/
public static boolean isAction(EClass type) {
return XTEND_FUNCTION.isSuperTypeOf(type) || JVM_OPERATION.isSuperTypeOf(type);
}

/** Replies if the given type corresponds to a constructor.
*
* @param type the type.
* @return {@code true} if the type corresponds to a SARL, Xtend or JVM constructor.
* @since 0.9
*/
public static boolean isConstructor(EClass type) {
return XTEND_CONSTRUCTOR.isSuperTypeOf(type) || JVM_CONSTRUCTOR.isSuperTypeOf(type);
}

/** Replies if the given type corresponds to a behavior unit.
*
* @param type the type.
* @return {@code true} if the type corresponds to a SARL behavior unit.
* @since 0.9
*/
public static boolean isBehaviorUnit(EClass type) {
return SARL_BEHAVIOR_UNIT.isSuperTypeOf(type);
}

/** Replies if the given type corresponds to a capacity use.
*
* @param type the type.
* @return {@code true} if the type corresponds to a SARL capacity use.
* @since 0.9
*/
public static boolean isCapacityUses(EClass type) {
return SARL_CAPACITY_USES.isSuperTypeOf(type);
}

@SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:returncount",
"checkstyle:cyclomaticcomplexity"})
@Override
Expand All @@ -108,34 +161,31 @@ public int getCategory(IOutlineNode node) {
}
return INNER_TYPE_PRIORITY;
}
if (SARL_CAPACITY_USES.isSuperTypeOf(objectNodeType)) {
if (isCapacityUses(objectNodeType)) {
return CAPACITY_USE_PRIORITY;
}
if (SARL_REQUIRED_CAPACITY.isSuperTypeOf(objectNodeType)) {
return CAPACITY_REQUIREMENT_PRIORITY;
}
if (XTEND_FIELD.isSuperTypeOf(objectNodeType)) {
if (isField(objectNodeType)) {
if (isStatic(objectNode)) {
return STATIC_FIELD_PRIORITY;
}
return FIELD_PRIORITY;
}
if (XTEND_FUNCTION.isSuperTypeOf(objectNodeType)) {
if (isAction(objectNodeType)) {
if (isStatic(objectNode)) {
return STATIC_METHOD_PRIORITY;
}
return METHOD_PRIORITY;
}
if (XTEND_CONSTRUCTOR.isSuperTypeOf(objectNodeType)) {
if (isConstructor(objectNodeType)) {
if (isStatic(objectNode)) {
return STATIC_CONSTRUCTOR;
}
return CONSTRUCTOR_PRIORITY;
}
if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(objectNodeType)) {
return CONSTRUCTOR_PRIORITY;
}
if (SARL_BEHAVIOR_UNIT.isSuperTypeOf(objectNodeType)) {
if (isBehaviorUnit(objectNodeType)) {
return BEHAVIOR_UNIT_PRIORITY;
}
}
Expand Down

0 comments on commit 1ca5735

Please sign in to comment.