Skip to content

Commit c7704f8

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of runtime/bundles/org.eclipse.core.expressions
1 parent 2d1c1e2 commit c7704f8

25 files changed

+170
-106
lines changed

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/AndExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public class AndExpression extends CompositeExpression {
2424

2525
@Override
2626
public boolean equals(final Object object) {
27-
if (!(object instanceof AndExpression))
27+
if (!(object instanceof final AndExpression that)) {
2828
return false;
29+
}
2930

30-
final AndExpression that= (AndExpression)object;
3131
return equals(this.fExpressions, that.fExpressions);
3232
}
3333

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/CompositeExpression.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,47 +35,54 @@ public abstract class CompositeExpression extends Expression {
3535
protected List<Expression> fExpressions;
3636

3737
public void add(Expression expression) {
38-
if (fExpressions == null)
38+
if (fExpressions == null) {
3939
fExpressions= new ArrayList<>(2);
40+
}
4041
fExpressions.add(expression);
4142
}
4243

4344
public Expression[] getChildren() {
44-
if (fExpressions == null)
45+
if (fExpressions == null) {
4546
return EMPTY_ARRAY;
47+
}
4648
return fExpressions.toArray(new Expression[fExpressions.size()]);
4749
}
4850

4951
protected EvaluationResult evaluateAnd(IEvaluationContext scope) throws CoreException {
50-
if (fExpressions == null)
52+
if (fExpressions == null) {
5153
return EvaluationResult.TRUE;
54+
}
5255
EvaluationResult result= EvaluationResult.TRUE;
5356
for (Expression expression : fExpressions) {
5457
result= result.and(expression.evaluate(scope));
5558
// keep iterating even if we have a not loaded found. It can be
5659
// that we find a false which will result in a better result.
57-
if (result == EvaluationResult.FALSE)
60+
if (result == EvaluationResult.FALSE) {
5861
return result;
62+
}
5963
}
6064
return result;
6165
}
6266

6367
protected EvaluationResult evaluateOr(IEvaluationContext scope) throws CoreException {
64-
if (fExpressions == null)
68+
if (fExpressions == null) {
6569
return EvaluationResult.TRUE;
70+
}
6671
EvaluationResult result= EvaluationResult.FALSE;
6772
for (Expression expression : fExpressions) {
6873
result= result.or(expression.evaluate(scope));
69-
if (result == EvaluationResult.TRUE)
74+
if (result == EvaluationResult.TRUE) {
7075
return result;
76+
}
7177
}
7278
return result;
7379
}
7480

7581
@Override
7682
public void collectExpressionInfo(ExpressionInfo info) {
77-
if (fExpressions == null)
83+
if (fExpressions == null) {
7884
return;
85+
}
7986
for (Expression expression : fExpressions) {
8087
expression.collectExpressionInfo(info);
8188
}

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/CountExpression.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ public CountExpression(String size) {
6262
}
6363

6464
private void initializeSize(String size) {
65-
if (size == null)
65+
if (size == null) {
6666
size = "*"; //$NON-NLS-1$
67-
if ("*".equals(size)) //$NON-NLS-1$
67+
}
68+
if ("*".equals(size)) { //$NON-NLS-1$
6869
fMode = ANY_NUMBER;
69-
else if ("?".equals(size)) //$NON-NLS-1$
70+
} else if ("?".equals(size)) { //$NON-NLS-1$
7071
fMode = NONE_OR_ONE;
71-
else if ("!".equals(size)) //$NON-NLS-1$
72+
} else if ("!".equals(size)) { //$NON-NLS-1$
7273
fMode = NONE;
73-
else if ("+".equals(size)) //$NON-NLS-1$
74+
} else if ("+".equals(size)) { //$NON-NLS-1$
7475
fMode = ONE_OR_MORE;
75-
else if (size.charAt(0) == '-' && size.charAt(size.length() - 1) == ')') {
76+
} else if (size.charAt(0) == '-' && size.charAt(size.length() - 1) == ')') {
7677
try {
7778
fMode = LESS_THAN;
7879
fSize = Integer.parseInt(size.substring(1, size.length() - 1));
@@ -118,8 +119,9 @@ public EvaluationResult evaluate(IEvaluationContext context) throws CoreExceptio
118119
size = collection.size();
119120
} else {
120121
ICountable countable = Expressions.getAsICountable(var, this);
121-
if (countable == null)
122+
if (countable == null) {
122123
return EvaluationResult.NOT_LOADED;
124+
}
123125
size = countable.count();
124126
}
125127
switch (fMode) {
@@ -154,10 +156,10 @@ public void collectExpressionInfo(ExpressionInfo info) {
154156

155157
@Override
156158
public boolean equals(final Object object) {
157-
if (!(object instanceof CountExpression))
159+
if (!(object instanceof final CountExpression that)) {
158160
return false;
161+
}
159162

160-
final CountExpression that = (CountExpression) object;
161163
return (this.fMode == that.fMode) && (this.fSize == that.fSize);
162164
}
163165

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/EqualsExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public void collectExpressionInfo(ExpressionInfo info) {
6262

6363
@Override
6464
public boolean equals(final Object object) {
65-
if (!(object instanceof EqualsExpression))
65+
if (!(object instanceof final EqualsExpression that)) {
6666
return false;
67+
}
6768

68-
final EqualsExpression that= (EqualsExpression)object;
6969
return this.fExpectedValue.equals(that.fExpectedValue);
7070
}
7171

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/EvaluationContext.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ public IEvaluationContext getParent() {
7777

7878
@Override
7979
public IEvaluationContext getRoot() {
80-
if (fParent == null)
80+
if (fParent == null) {
8181
return this;
82+
}
8283
return fParent.getRoot();
8384
}
8485

@@ -95,8 +96,9 @@ public void setAllowPluginActivation(boolean value) {
9596
@Override
9697
public boolean getAllowPluginActivation() {
9798
if (fAllowPluginActivation == null) {
98-
if (fParent != null)
99+
if (fParent != null) {
99100
return fParent.getAllowPluginActivation();
101+
}
100102
return false;
101103
}
102104
return fAllowPluginActivation.booleanValue();
@@ -106,16 +108,18 @@ public boolean getAllowPluginActivation() {
106108
public void addVariable(String name, Object value) {
107109
Assert.isNotNull(name);
108110
Assert.isNotNull(value);
109-
if (fVariables == null)
111+
if (fVariables == null) {
110112
fVariables= new HashMap<>();
113+
}
111114
fVariables.put(name, value);
112115
}
113116

114117
@Override
115118
public Object removeVariable(String name) {
116119
Assert.isNotNull(name);
117-
if (fVariables == null)
120+
if (fVariables == null) {
118121
return null;
122+
}
119123
return fVariables.remove(name);
120124
}
121125

@@ -126,10 +130,12 @@ public Object getVariable(String name) {
126130
if (fVariables != null) {
127131
result= fVariables.get(name);
128132
}
129-
if (result != null)
133+
if (result != null) {
130134
return result;
131-
if (fParent != null)
135+
}
136+
if (fParent != null) {
132137
return fParent.getVariable(name);
138+
}
133139
return null;
134140
}
135141

@@ -138,12 +144,14 @@ public Object resolveVariable(String name, Object[] args) throws CoreException {
138144
if (fVariableResolvers != null && fVariableResolvers.length > 0) {
139145
for (IVariableResolver resolver : fVariableResolvers) {
140146
Object variable= resolver.resolve(name, args);
141-
if (variable != null)
147+
if (variable != null) {
142148
return variable;
149+
}
143150
}
144151
}
145-
if (fParent != null)
152+
if (fParent != null) {
146153
return fParent.resolveVariable(name, args);
154+
}
147155
return null;
148156
}
149157
}

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/Expression.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,13 @@ protected int computeHashCode() {
237237

238238
@Override
239239
public int hashCode() {
240-
if (fHashCode != HASH_CODE_NOT_COMPUTED)
240+
if (fHashCode != HASH_CODE_NOT_COMPUTED) {
241241
return fHashCode;
242+
}
242243
fHashCode= computeHashCode();
243-
if (fHashCode == HASH_CODE_NOT_COMPUTED)
244+
if (fHashCode == HASH_CODE_NOT_COMPUTED) {
244245
fHashCode++;
246+
}
245247
return fHashCode;
246248
}
247249
}

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/ExpressionConverter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ public ExpressionConverter(ElementHandler[] handlers) {
8888
public Expression perform(IConfigurationElement root) throws CoreException {
8989
for (ElementHandler handler : fHandlers) {
9090
Expression result= handler.create(this, root);
91-
if (result != null)
91+
if (result != null) {
9292
return result;
93+
}
9394
}
9495
return null;
9596
}
@@ -112,8 +113,9 @@ public Expression perform(IConfigurationElement root) throws CoreException {
112113
public Expression perform(Element root) throws CoreException {
113114
for (ElementHandler handler : fHandlers) {
114115
Expression result= handler.create(this, root);
115-
if (result != null)
116+
if (result != null) {
116117
return result;
118+
}
117119
}
118120
return null;
119121
}
@@ -123,13 +125,14 @@ public Expression perform(Element root) throws CoreException {
123125
if (children != null) {
124126
for (IConfigurationElement configElement : children) {
125127
Expression child= perform(configElement);
126-
if (child == null)
128+
if (child == null) {
127129
throw new CoreException(new Status(IStatus.ERROR, ExpressionConverter.class,
128130
IStatus.ERROR,
129131
Messages.format(
130132
ExpressionMessages.Expression_unknown_element,
131133
getDebugPath(configElement)),
132134
null));
135+
}
133136
result.add(child);
134137
}
135138
}
@@ -140,16 +143,15 @@ private String getDebugPath(IConfigurationElement configurationElement) {
140143
buf.append(configurationElement.getName());
141144
Object parent= configurationElement.getParent();
142145
while (parent != null) {
143-
if (parent instanceof IConfigurationElement) {
146+
if (parent instanceof IConfigurationElement parent2) {
144147
buf.append(" > "); //$NON-NLS-1$
145-
IConfigurationElement parent2= (IConfigurationElement) parent;
146148
buf.append(parent2.getName());
147149
String id= parent2.getAttribute("id"); //$NON-NLS-1$
148-
if (id != null)
150+
if (id != null) {
149151
buf.append(" (id=").append(id).append(')'); //$NON-NLS-1$
152+
}
150153
parent= parent2.getParent();
151-
} else if (parent instanceof IExtension) {
152-
IExtension parent2= (IExtension) parent;
154+
} else if (parent instanceof IExtension parent2) {
153155
buf.append(" : "); //$NON-NLS-1$
154156
buf.append(parent2.getExtensionPointUniqueIdentifier());
155157
buf.append(" @ "); //$NON-NLS-1$
@@ -167,13 +169,14 @@ private String getDebugPath(IConfigurationElement configurationElement) {
167169
while (child != null) {
168170
if (child.getNodeType() == Node.ELEMENT_NODE) {
169171
Expression exp= perform((Element)child);
170-
if (exp == null)
172+
if (exp == null) {
171173
throw new CoreException(new Status(IStatus.ERROR, ExpressionConverter.class,
172174
IStatus.ERROR,
173175
Messages.format(
174176
ExpressionMessages.Expression_unknown_element,
175177
child.getNodeName()),
176178
null));
179+
}
177180
result.add(exp);
178181
}
179182
child = child.getNextSibling();

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/OrExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public EvaluationResult evaluate(IEvaluationContext context) throws CoreExceptio
2828

2929
@Override
3030
public boolean equals(final Object object) {
31-
if (!(object instanceof OrExpression))
31+
if (!(object instanceof final OrExpression that)) {
3232
return false;
33+
}
3334

34-
final OrExpression that= (OrExpression)object;
3535
return equals(this.fExpressions, that.fExpressions);
3636
}
3737
}

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/ReferenceExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public void collectExpressionInfo(ExpressionInfo info) {
8787

8888
@Override
8989
public boolean equals(final Object object) {
90-
if (!(object instanceof ReferenceExpression))
90+
if (!(object instanceof final ReferenceExpression that)) {
9191
return false;
92+
}
9293

93-
final ReferenceExpression that= (ReferenceExpression)object;
9494
return this.fDefinitionId.equals(that.fDefinitionId);
9595
}
9696

runtime/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/TestExpression.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ public EvaluationResult evaluate(IEvaluationContext context) throws CoreExceptio
9797
Object element= context.getDefaultVariable();
9898
if (System.class.equals(element)) {
9999
String str= System.getProperty(fProperty);
100-
if (str == null)
100+
if (str == null) {
101101
return EvaluationResult.FALSE;
102+
}
102103
return EvaluationResult.valueOf(str.equals(fArgs[0]));
103104
}
104105
Property property= fgTypeExtensionManager.getProperty(element, fNamespace, fProperty, context.getAllowPluginActivation() && fForcePluginActivation);
105-
if (!property.isInstantiated())
106+
if (!property.isInstantiated()) {
106107
return EvaluationResult.NOT_LOADED;
108+
}
107109
return EvaluationResult.valueOf(property.test(element, fArgs, fExpectedValue));
108110
}
109111

@@ -115,10 +117,10 @@ public void collectExpressionInfo(ExpressionInfo info) {
115117

116118
@Override
117119
public boolean equals(final Object object) {
118-
if (!(object instanceof TestExpression))
120+
if (!(object instanceof final TestExpression that)) {
119121
return false;
122+
}
120123

121-
final TestExpression that= (TestExpression)object;
122124
return this.fNamespace.equals(that.fNamespace) && this.fProperty.equals(that.fProperty)
123125
&& this.fForcePluginActivation == that.fForcePluginActivation
124126
&& equals(this.fArgs, that.fArgs) && equals(this.fExpectedValue, that.fExpectedValue);
@@ -147,8 +149,9 @@ public String toString() {
147149
} else {
148150
args.append(arg.toString());
149151
}
150-
if (i < fArgs.length - 1)
152+
if (i < fArgs.length - 1) {
151153
args.append(", "); //$NON-NLS-1$
154+
}
152155
}
153156
return "<test property=\"" + fProperty + "\"" +//$NON-NLS-1$ //$NON-NLS-2$
154157
(fArgs.length != 0 ? " args=\"" + args + "\"" : "") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

0 commit comments

Comments
 (0)