Skip to content

Commit 5e9376f

Browse files
eclipse-equinox-botlaeubi
authored andcommitted
Perform clean code of bundles/org.eclipse.equinox.p2.metadata
1 parent 378a829 commit 5e9376f

20 files changed

+35
-67
lines changed

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/License.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public boolean equals(Object obj) {
104104
if (obj == null) {
105105
return false;
106106
}
107-
if (obj instanceof ILicense) {
108-
ILicense other = (ILicense) obj;
107+
if (obj instanceof ILicense other) {
109108
if (other.getUUID().equals(getUUID())) {
110109
return true;
111110
}

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/OSGiVersion.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ public static boolean isValidOSGiQualifier(Comparable<?> e) {
5656
return true;
5757
}
5858

59-
if (!(e instanceof String)) {
59+
if (!(e instanceof String s)) {
6060
return false;
6161
}
6262

63-
String s = (String) e;
6463
int idx = s.length();
6564
boolean[] allowed = allowedOSGiChars;
6665
while (--idx >= 0) {
@@ -110,11 +109,10 @@ public OSGiVersion(int major, int minor, int micro, Comparable<? extends Object>
110109
@Override
111110
public int compareTo(Version v) {
112111
int result;
113-
if (!(v instanceof OSGiVersion)) {
112+
if (!(v instanceof OSGiVersion ov)) {
114113
BasicVersion ov = (BasicVersion) v;
115114
result = VersionVector.compare(getVector(), null, ov.getVector(), ov.getPad());
116115
} else {
117-
OSGiVersion ov = (OSGiVersion) v;
118116
result = major - ov.major;
119117
if (result == 0) {
120118
result = minor - ov.minor;
@@ -135,15 +133,13 @@ public boolean equals(Object object) {
135133
return true;
136134
}
137135

138-
if (!(object instanceof OSGiVersion)) {
139-
if (object instanceof BasicVersion) {
140-
BasicVersion ov = (BasicVersion) object;
136+
if (!(object instanceof OSGiVersion other)) {
137+
if (object instanceof BasicVersion ov) {
141138
return VersionVector.equals(getVector(), null, ov.getVector(), ov.getPad());
142139
}
143140
return false;
144141
}
145142

146-
OSGiVersion other = (OSGiVersion) object;
147143
return micro == other.micro && minor == other.minor && major == other.major && qualifier.equals(other.qualifier);
148144
}
149145

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/OmniVersion.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ public boolean equals(Object o) {
110110
return true;
111111
}
112112

113-
if (!(o instanceof BasicVersion)) {
113+
if (!(o instanceof BasicVersion ov)) {
114114
return false;
115115
}
116116

117-
BasicVersion ov = (BasicVersion) o;
118117
return VersionVector.equals(vector, padValue, ov.getVector(), ov.getPad());
119118
}
120119

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/RequirementChange.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ public boolean equals(Object obj) {
6969
if (obj == null) {
7070
return false;
7171
}
72-
if (!(obj instanceof IRequirementChange)) {
72+
if (!(obj instanceof final IRequirementChange other)) {
7373
return false;
7474
}
75-
final IRequirementChange other = (IRequirementChange) obj;
7675
if (applyOn == null) {
7776
if (other.applyOn() != null) {
7877
return false;

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/TouchpointData.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public boolean equals(Object obj) {
5050
if (obj == null) {
5151
return false;
5252
}
53-
if (!(obj instanceof ITouchpointData)) {
53+
if (!(obj instanceof final ITouchpointData other)) {
5454
return false;
5555
}
56-
final ITouchpointData other = (ITouchpointData) obj;
5756
if (instructions == null) {
5857
if (other.getInstructions() != null) {
5958
return false;

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/TouchpointInstruction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ public boolean equals(Object obj) {
112112
if (obj == null) {
113113
return false;
114114
}
115-
if (!(obj instanceof ITouchpointInstruction)) {
115+
if (!(obj instanceof ITouchpointInstruction other)) {
116116
return false;
117117
}
118-
ITouchpointInstruction other = (ITouchpointInstruction) obj;
119118
if (body == null) {
120119
if (other.getBody() != null) {
121120
return false;

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/TouchpointType.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ public boolean equals(Object obj) {
3838
if (super.equals(obj)) {
3939
return true;
4040
}
41-
if (obj == null || !(obj instanceof ITouchpointType)) {
41+
if (obj == null || !(obj instanceof ITouchpointType other)) {
4242
return false;
4343
}
44-
ITouchpointType other = (ITouchpointType) obj;
4544
return id.equals(other.getId()) && version.equals(other.getVersion());
4645
}
4746

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionFormatParser.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ public boolean equals(Object o) {
205205
if (o == this) {
206206
return true;
207207
}
208-
if (!(o instanceof Qualifier)) {
208+
if (!(o instanceof Qualifier oq)) {
209209
return false;
210210
}
211-
Qualifier oq = (Qualifier) o;
212211
return min == oq.min && max == oq.max;
213212
}
214213

@@ -267,9 +266,8 @@ boolean parse(Fragment[] fragments, int fragIdx, List<Comparable<?>> segments, S
267266
}
268267
}
269268
} else {
270-
if (fragment instanceof StringFragment) {
269+
if (fragment instanceof StringFragment stringFrag) {
271270
// Check for translations if we default to for MINS or MAXS
272-
StringFragment stringFrag = (StringFragment) fragment;
273271
Comparable<?> opposite = stringFrag.getOppositeDefaultValue();
274272
if (opposite != null) {
275273
idx = segments.size() - 1;
@@ -1166,8 +1164,7 @@ Comparable<?> getOppositeDefaultValue() {
11661164
}
11671165

11681166
public boolean isOppositeTranslation(Object val) {
1169-
if (val instanceof String) {
1170-
String str = (String) val;
1167+
if (val instanceof String str) {
11711168
int idx = oppositeTranslationRepeat;
11721169
if (str.length() == idx) {
11731170
while (--idx >= 0) {

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/VersionVector.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ static int compareSegments(Comparable<?> a, Comparable<?> b) {
252252
}
253253

254254
if (a instanceof VersionVector) {
255-
return (b instanceof VersionVector) ? ((VersionVector) a).compareTo((VersionVector) b) : 1;
255+
return (b instanceof VersionVector v) ? ((VersionVector) a).compareTo(v) : 1;
256256
}
257257
if (b instanceof VersionVector) {
258258
return -1;
259259
}
260260

261261
if (a instanceof EnumDefinition.EnumSegment) {
262-
return (b instanceof EnumDefinition.EnumSegment) ? ((EnumDefinition.EnumSegment) a).compareTo((EnumDefinition.EnumSegment) b) : 1;
262+
return (b instanceof EnumDefinition.EnumSegment e) ? ((EnumDefinition.EnumSegment) a).compareTo(e) : 1;
263263
}
264264
if (b instanceof EnumDefinition.EnumSegment) {
265265
return -1;
@@ -292,11 +292,10 @@ public boolean equals(Object o) {
292292
return true;
293293
}
294294

295-
if (!(o instanceof VersionVector)) {
295+
if (!(o instanceof VersionVector ov)) {
296296
return false;
297297
}
298298

299-
VersionVector ov = (VersionVector) o;
300299
return equals(vector, padValue, ov.vector, ov.padValue);
301300
}
302301

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/At.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ protected At(Expression lhs, Expression rhs) {
3232
@Override
3333
public Object evaluate(org.eclipse.equinox.p2.metadata.expression.IEvaluationContext context) {
3434
Object lval;
35-
if (lhs instanceof DynamicMember) {
36-
DynamicMember lm = (DynamicMember) lhs;
35+
if (lhs instanceof DynamicMember lm) {
3736
Object instance = lm.operand.evaluate(context);
3837
if (instance instanceof IInstallableUnit) {
3938
String name = lm.getName();

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Binary.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public void toString(StringBuilder bld, Variable rootVariable) {
8484
* LDAP filter binary expression
8585
*/
8686
void appendLDAPAttribute(StringBuilder buf) {
87-
if (lhs instanceof DynamicMember) {
88-
DynamicMember attr = (DynamicMember) lhs;
87+
if (lhs instanceof DynamicMember attr) {
8988
if (attr.operand instanceof Variable) {
9089
buf.append(attr.getName());
9190
return;

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Expression.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,12 @@ private static class MembersFinder implements IExpressionVisitor {
361361

362362
@Override
363363
public boolean visit(IExpression expression) {
364-
if (expression instanceof Matches) {
364+
if (expression instanceof Matches matches) {
365365
if (IInstallableUnit.class.isAssignableFrom(elementClass)) {
366366
// This one is a bit special since an
367367
// IInstallableUnit ~= IRequirement often
368368
// means that we can reuse the requirement
369369
// expression.
370-
Matches matches = (Matches) expression;
371370
if (matches.lhs == operand) {
372371
if (members == null) {
373372
members = new ArrayList<>();
@@ -382,8 +381,7 @@ public boolean visit(IExpression expression) {
382381
return false;
383382
}
384383

385-
if (expression instanceof Member) {
386-
Member member = (Member) expression;
384+
if (expression instanceof Member member) {
387385
if (member.getOperand() == operand) {
388386
String name = member.getName();
389387
if (members == null) {

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/ExpressionFactory.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,10 @@ public IExpression normalize(List<? extends IExpression> operands, int expressio
299299

300300
@Override
301301
public IExpression not(IExpression operand) {
302-
if (operand instanceof Equals) {
303-
Equals eq = (Equals) operand;
302+
if (operand instanceof Equals eq) {
304303
return new Equals(eq.lhs, eq.rhs, !eq.negate);
305304
}
306-
if (operand instanceof Compare) {
307-
Compare cmp = (Compare) operand;
305+
if (operand instanceof Compare cmp) {
308306
return new Compare(cmp.lhs, cmp.rhs, !cmp.compareLess, !cmp.equalOK);
309307
}
310308
if (operand instanceof Not) {

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Latest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ final class Latest extends UnaryCollectionFilter {
3131
@Override
3232
public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
3333
HashMap<String, IVersionedId> greatestIUVersion;
34-
if (operand instanceof Select) {
34+
if (operand instanceof Select select) {
3535
// Inline element evaluation here so that we don't build a map that is
3636
// larger then it has to be
37-
Select select = (Select) operand;
3837
Iterator<?> iterator = select.operand.evaluateAsIterator(context);
3938
if (!iterator.hasNext()) {
4039
return Collections.EMPTY_SET.iterator();
@@ -77,11 +76,10 @@ public Iterator<?> evaluateAsIterator(IEvaluationContext context) {
7776
greatestIUVersion = new HashMap<>();
7877
while (iterator.hasNext()) {
7978
Object next = iterator.next();
80-
if (!(next instanceof IVersionedId)) {
79+
if (!(next instanceof IVersionedId versionedID)) {
8180
continue;
8281
}
8382

84-
IVersionedId versionedID = (IVersionedId) next;
8583
String id = versionedID.getId();
8684

8785
IVersionedId prev = greatestIUVersion.put(id, versionedID);

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Matches.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ protected boolean match(Object lval, Object rval) {
7979
return false;
8080
}
8181

82-
if (rval instanceof IRequirement) {
83-
IRequirement requirement = (IRequirement) rval;
82+
if (rval instanceof IRequirement requirement) {
8483
if (lval instanceof IInstallableUnit) {
8584
return Boolean.valueOf(((IInstallableUnit) lval).satisfies(requirement));
8685
}
87-
} else if (rval instanceof VersionRange) {
88-
VersionRange range = (VersionRange) rval;
86+
} else if (rval instanceof VersionRange range) {
8987
if (lval instanceof Version) {
9088
return Boolean.valueOf(range.isIncluded((Version) lval));
9189
}
@@ -134,8 +132,7 @@ protected boolean match(Object lval, Object rval) {
134132
if (lval instanceof Character || lval instanceof Number || lval instanceof Boolean) {
135133
return ((LDAPApproximation) rval).isMatch(lval.toString());
136134
}
137-
} else if (rval instanceof Class<?>) {
138-
Class<?> rclass = (Class<?>) rval;
135+
} else if (rval instanceof Class<?> rclass) {
139136
return lval instanceof Class<?> ? rclass.isAssignableFrom((Class<?>) lval) : rclass.isInstance(lval);
140137
}
141138
throw new IllegalArgumentException(

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/Pipe.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ public Object getManagedProperty(Object client, String memberName, Object key) {
4747
if (indexProvider != null) {
4848
return indexProvider.getManagedProperty(client, memberName, key);
4949
}
50-
if (client instanceof IInstallableUnit && memberName.equals(InstallableUnit.MEMBER_TRANSLATED_PROPERTIES)) {
51-
IInstallableUnit iu = (IInstallableUnit) client;
52-
return key instanceof KeyWithLocale ? iu.getProperty(((KeyWithLocale) key).getKey()) : iu.getProperty(key.toString());
50+
if (client instanceof IInstallableUnit iu && memberName.equals(InstallableUnit.MEMBER_TRANSLATED_PROPERTIES)) {
51+
return key instanceof KeyWithLocale k ? iu.getProperty(k.getKey()) : iu.getProperty(key.toString());
5352
}
5453
return null;
5554
}
@@ -121,8 +120,7 @@ private static Expression normalizeBoolean(IExpressionFactory factory, ArrayList
121120
private static Expression makePipeableOfBooleans(IExpressionFactory factory, ArrayList<Expression> booleans) {
122121
Expression boolExpr = normalizeBoolean(factory, booleans);
123122
Object[] params = null;
124-
if (boolExpr instanceof MatchExpression<?>) {
125-
MatchExpression<?> matchExpr = (MatchExpression<?>) boolExpr;
123+
if (boolExpr instanceof MatchExpression<?> matchExpr) {
126124
boolExpr = (Expression) matchExpr.getPredicate();
127125
params = matchExpr.getParameters();
128126
if (params.length == 0) {

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/expression/UnaryCollectionFilter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public Object evaluate(IEvaluationContext context) {
3333

3434
@Override
3535
public void toString(StringBuilder bld, Variable rootVariable) {
36-
if (operand instanceof Select) {
37-
Select select = (Select) operand;
36+
if (operand instanceof Select select) {
3837
CollectionFilter.appendProlog(bld, rootVariable, select.operand, getOperator());
3938
appendOperand(bld, rootVariable, select.lambda, getPriority());
4039
} else {

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/index/Index.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
public abstract class Index<T> implements IIndex<T> {
2323

2424
protected static boolean isIndexedMember(IExpression expr, IExpression variable, String memberName) {
25-
if (expr instanceof Member) {
26-
Member member = (Member) expr;
25+
if (expr instanceof Member member) {
2726
return member.getOperand() == variable && member.getName().equals(memberName);
2827
}
2928
return false;

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/metadata/VersionedId.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ public boolean equals(Object obj) {
9595
return true;
9696
}
9797

98-
if (!(obj instanceof VersionedId)) {
98+
if (!(obj instanceof VersionedId vname)) {
9999
return false;
100100
}
101101

102-
VersionedId vname = (VersionedId) obj;
103102
return id.equals(vname.id) && version.equals(vname.version);
104103
}
105104

bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/query/ExpressionQuery.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ public static <T> IContextExpression<T> createExpression(IQuery<T> query) {
8383
}
8484
parameters = new Object[0];
8585
} else {
86-
if (expr instanceof MatchExpression<?>) {
87-
MatchExpression<?> matchExpr = (MatchExpression<?>) expr;
86+
if (expr instanceof MatchExpression<?> matchExpr) {
8887
parameters = matchExpr.getParameters();
8988
expr = factory.select(ExpressionFactory.EVERYTHING, factory.lambda(ExpressionFactory.THIS, matchExpr.operand));
90-
} else if (expr instanceof ContextExpression<?>) {
91-
ContextExpression<?> contextExpr = (ContextExpression<?>) expr;
89+
} else if (expr instanceof ContextExpression<?> contextExpr) {
9290
parameters = contextExpr.getParameters();
9391
expr = contextExpr.operand;
9492
} else {

0 commit comments

Comments
 (0)