Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CountExpression.java155
2 files changed, 156 insertions, 3 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
index 7859b7fc2..875718c57 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CategoryPropertyTester.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Wind River Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2011-2022 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License 2.0 which accompanies this distribution, and is
* available at https://www.eclipse.org/legal/epl-2.0/
@@ -14,7 +14,6 @@ import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.ICountable;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.core.internal.expressions.CountExpression;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -38,7 +37,6 @@ import org.eclipse.ui.navigator.INavigatorContentService;
/**
* Category property tester.
*/
-@SuppressWarnings("restriction")
public class CategoryPropertyTester extends PropertyTester {
/* (non-Javadoc)
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CountExpression.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CountExpression.java
new file mode 100644
index 000000000..4d75d93db
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.views/src/org/eclipse/tcf/te/ui/views/internal/categories/CountExpression.java
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation.
+ * Ian Phillips - additional expressions support ( "-N)", "(N-" ).
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.views.internal.categories;
+
+import java.util.Collection;
+
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionInfo;
+import org.eclipse.core.expressions.ICountable;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.w3c.dom.Element;
+
+
+public class CountExpression extends Expression {
+
+ private static final int GREATER_THAN = 7; // (N-
+ private static final int LESS_THAN = 6; // -N)
+ private static final int ANY_NUMBER = 5; // *
+ private static final int EXACT = 4; // N
+ private static final int ONE_OR_MORE = 3; // +
+ private static final int NONE_OR_ONE = 2; // ?
+ private static final int NONE = 1; // !
+ private static final int UNKNOWN = 0;
+
+ /**
+ * The seed for the hash code for all count expressions.
+ */
+ private static final int HASH_INITIAL= CountExpression.class.getName().hashCode();
+
+ private int fMode;
+ private int fSize;
+
+ public CountExpression(IConfigurationElement configElement) {
+ String size = configElement.getAttribute(ATT_VALUE);
+ initializeSize(size);
+ }
+
+ public CountExpression(Element element) {
+ String size = element.getAttribute(ATT_VALUE);
+ initializeSize(size.length() > 0 ? size : null);
+ }
+
+ public CountExpression(String size) {
+ initializeSize(size);
+ }
+
+ private void initializeSize(String size) {
+ if (size == null)
+ size= "*"; //$NON-NLS-1$
+ if (size.equals("*")) //$NON-NLS-1$
+ fMode= ANY_NUMBER;
+ else if (size.equals("?")) //$NON-NLS-1$
+ fMode= NONE_OR_ONE;
+ else if (size.equals("!")) //$NON-NLS-1$
+ fMode= NONE;
+ else if (size.equals("+")) //$NON-NLS-1$
+ fMode= ONE_OR_MORE;
+ else if (size.charAt(0) == '-' && size.charAt(size.length() - 1) == ')') {
+ try {
+ fMode = LESS_THAN;
+ fSize = Integer.parseInt(size.substring(1, size.length() - 1));
+ } catch (NumberFormatException e) {
+ fMode= UNKNOWN;
+ }
+ } else if (size.charAt(0) == '(' && size.charAt(size.length() - 1) == '-') {
+ try {
+ fMode = GREATER_THAN;
+ fSize = Integer.parseInt(size.substring(1, size.length() - 1));
+ } catch (NumberFormatException e) {
+ fMode= UNKNOWN;
+ }
+ } else {
+ try {
+ fSize= Integer.parseInt(size);
+ fMode= EXACT;
+ } catch (NumberFormatException e) {
+ fMode= UNKNOWN;
+ }
+ }
+ }
+
+ public static ICountable getAsICountable(Object var, Expression expression) {
+ if (var instanceof ICountable) return (ICountable)var;
+ IAdapterManager manager = Platform.getAdapterManager();
+ ICountable result = (ICountable)manager.getAdapter(var, ICountable.class);
+ return result;
+ }
+
+ @Override
+ public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
+ Object var = context.getDefaultVariable();
+ int size;
+ if (var instanceof Collection) {
+ size = ((Collection<?>)var).size();
+ } else {
+ ICountable countable = getAsICountable(var, this);
+ if (countable == null)
+ return EvaluationResult.NOT_LOADED;
+ size = countable.count();
+ }
+ switch (fMode) {
+ case UNKNOWN:
+ return EvaluationResult.FALSE;
+ case NONE:
+ return EvaluationResult.valueOf(size == 0);
+ case NONE_OR_ONE:
+ return EvaluationResult.valueOf(size == 0 || size == 1);
+ case ONE_OR_MORE:
+ return EvaluationResult.valueOf(size >= 1);
+ case EXACT:
+ return EvaluationResult.valueOf(fSize == size);
+ case ANY_NUMBER:
+ return EvaluationResult.TRUE;
+ case LESS_THAN:
+ return EvaluationResult.valueOf(size < fSize);
+ case GREATER_THAN:
+ return EvaluationResult.valueOf(size > fSize);
+ }
+ return EvaluationResult.FALSE;
+ }
+
+ @Override
+ public void collectExpressionInfo(ExpressionInfo info) {
+ info.markDefaultVariableAccessed();
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ if (!(object instanceof CountExpression))
+ return false;
+
+ final CountExpression that = (CountExpression)object;
+ return (this.fMode == that.fMode) && (this.fSize == that.fSize);
+ }
+
+ @Override
+ protected int computeHashCode() {
+ return HASH_INITIAL * HASH_FACTOR + fMode
+ * HASH_FACTOR + fSize;
+ }
+}

Back to the top