blob: 6e10bda0c55e13b59e63f14a326066cb43e9975d (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2010, 2017 Cloudsmith Inc. 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:
* Cloudsmith Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.p2.metadata.expression;
import org.eclipse.equinox.p2.metadata.expression.IExpressionVisitor;
/**
* The abstract baseclass for all N-ary expressions
*/
public abstract class NAry extends Expression {
public final Expression[] operands;
protected NAry(Expression[] operands) {
this.operands = operands;
}
@Override
public boolean accept(IExpressionVisitor visitor) {
if (super.accept(visitor))
for (int idx = 0; idx < operands.length; ++idx)
if (!operands[idx].accept(visitor))
return false;
return true;
}
@Override
public int compareTo(Expression e) {
int cmp = super.compareTo(e);
if (cmp == 0)
cmp = compare(operands, ((NAry) e).operands);
return cmp;
}
@Override
public boolean equals(Object o) {
return super.equals(o) && equals(operands, ((NAry) o).operands);
}
@Override
public abstract String getOperator();
@Override
public int hashCode() {
return hashCode(operands);
}
@Override
public void toString(StringBuffer bld, Variable rootVariable) {
appendOperand(bld, rootVariable, operands[0], getPriority());
for (int idx = 1; idx < operands.length; ++idx) {
bld.append(' ');
bld.append(getOperator());
bld.append(' ');
appendOperand(bld, rootVariable, operands[idx], getPriority());
}
}
@Override
int countAccessToEverything() {
int cnt = 0;
for (int idx = 0; idx < operands.length; ++idx)
cnt += operands[idx].countAccessToEverything();
return cnt;
}
}
|