Skip to content

Commit ececa15

Browse files
committed
Use lambda where possible and simplify expression
1 parent 297fea0 commit ececa15

58 files changed

Lines changed: 964 additions & 1926 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/DesignerPluginTest.java‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,12 @@ public void test_getDefault() {
5656
public void test_log_message() {
5757
final String message = "Information message";
5858
ILog log = DesignerPlugin.getDefault().getLog();
59-
ILogListener logListener = new ILogListener() {
60-
@Override
61-
public void logging(IStatus status, String plugin) {
62-
assertEquals(IStatus.INFO, status.getSeverity());
63-
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
64-
assertEquals(IStatus.INFO, status.getCode());
65-
assertEquals(message, status.getMessage());
66-
assertNull(status.getException());
67-
}
59+
ILogListener logListener = (status, plugin) -> {
60+
assertEquals(IStatus.INFO, status.getSeverity());
61+
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
62+
assertEquals(IStatus.INFO, status.getCode());
63+
assertEquals(message, status.getMessage());
64+
assertNull(status.getException());
6865
};
6966
//
7067
try {
@@ -79,14 +76,11 @@ public void logging(IStatus status, String plugin) {
7976
public void test_log_Exception() {
8077
final Exception exception = new Exception();
8178
ILog log = DesignerPlugin.getDefault().getLog();
82-
ILogListener logListener = new ILogListener() {
83-
@Override
84-
public void logging(IStatus status, String plugin) {
85-
assertEquals(IStatus.ERROR, status.getSeverity());
86-
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
87-
assertEquals(IStatus.ERROR, status.getCode());
88-
assertSame(exception, status.getException());
89-
}
79+
ILogListener logListener = (status, plugin) -> {
80+
assertEquals(IStatus.ERROR, status.getSeverity());
81+
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
82+
assertEquals(IStatus.ERROR, status.getCode());
83+
assertSame(exception, status.getException());
9084
};
9185
//
9286
try {

‎org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/TestProject.java‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.eclipse.core.resources.IFolder;
2020
import org.eclipse.core.resources.IProject;
2121
import org.eclipse.core.resources.IProjectDescription;
22-
import org.eclipse.core.resources.IResource;
23-
import org.eclipse.core.resources.IResourceVisitor;
2422
import org.eclipse.core.resources.IWorkspaceRoot;
2523
import org.eclipse.core.resources.ResourceAttributes;
2624
import org.eclipse.core.resources.ResourcesPlugin;
@@ -389,18 +387,15 @@ public static void waitForAutoBuild() {
389387
*/
390388
private void clearReadOnlyFlag() throws CoreException {
391389
if (m_project.isOpen()) {
392-
m_project.accept(new IResourceVisitor() {
393-
@Override
394-
public boolean visit(IResource resource) throws CoreException {
395-
if (resource instanceof IFile file) {
396-
ResourceAttributes resourceAttributes = file.getResourceAttributes();
397-
if (resourceAttributes != null) {
398-
resourceAttributes.setReadOnly(false);
399-
file.setResourceAttributes(resourceAttributes);
400-
}
390+
m_project.accept(resource -> {
391+
if (resource instanceof IFile file) {
392+
ResourceAttributes resourceAttributes = file.getResourceAttributes();
393+
if (resourceAttributes != null) {
394+
resourceAttributes.setReadOnly(false);
395+
file.setResourceAttributes(resourceAttributes);
401396
}
402-
return true;
403397
}
398+
return true;
404399
});
405400
}
406401
}

‎org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/eval/ExecutionFlowUtilsTest.java‎

Lines changed: 16 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,7 @@ public void test_visit_AnonymousClassDeclaration_withInvocation_doVisit(String r
930930
@Test
931931
public void test_findLastAssignment_variable() throws Exception {
932932
String code = "void root() {int value = 0; System.out.println(value);}";
933-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
934-
@Override
935-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
936-
MethodDeclaration methodDeclaration,
937-
Statement[] statements) {
938-
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
939-
}
940-
});
933+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
941934
}
942935

943936
/**
@@ -1001,68 +994,33 @@ void root() {
1001994
@Test
1002995
public void test_findLastAssignment_variable_reassign() throws Exception {
1003996
String code = "void root() {int value = 0; value = 1; System.out.println(value);}";
1004-
check_findLastAssignment(code, 2, new I_findLastAssignment() {
1005-
@Override
1006-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1007-
MethodDeclaration methodDeclaration,
1008-
Statement[] statements) {
1009-
return ((ExpressionStatement) statements[1]).getExpression();
1010-
}
1011-
});
997+
check_findLastAssignment(code, 2, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[1]).getExpression());
1012998
}
1013999

10141000
@Test
10151001
public void test_findLastAssignment_variable_reassign2() throws Exception {
10161002
String code =
10171003
"void root() {int value; value = 0; System.out.println(value); value = 1; System.out.println(value);}";
1018-
check_findLastAssignment(code, 4, new I_findLastAssignment() {
1019-
@Override
1020-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1021-
MethodDeclaration methodDeclaration,
1022-
Statement[] statements) {
1023-
return ((ExpressionStatement) statements[3]).getExpression();
1024-
}
1025-
});
1004+
check_findLastAssignment(code, 4, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[3]).getExpression());
10261005
}
10271006

10281007
@Test
10291008
public void test_findLastAssignment_variable_reassign_later() throws Exception {
10301009
String code = "void root() {int value = 0; System.out.println(value); value = 1;}";
1031-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
1032-
@Override
1033-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1034-
MethodDeclaration methodDeclaration,
1035-
Statement[] statements) {
1036-
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
1037-
}
1038-
});
1010+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
10391011
}
10401012

10411013
@Test
10421014
public void test_findLastAssignment_variable_sameInDifferentMethod() throws Exception {
10431015
String code =
10441016
"void root() {int value = 0; foo(); System.out.println(value);} void foo() {int value = 1;}";
1045-
check_findLastAssignment(code, 2, new I_findLastAssignment() {
1046-
@Override
1047-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1048-
MethodDeclaration methodDeclaration,
1049-
Statement[] statements) {
1050-
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
1051-
}
1052-
});
1017+
check_findLastAssignment(code, 2, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
10531018
}
10541019

10551020
@Test
10561021
public void test_findLastAssignment_FieldDeclaration() throws Exception {
10571022
String code = "int value = 0; void root() {System.out.println(value);}";
1058-
check_findLastAssignment(code, 0, new I_findLastAssignment() {
1059-
@Override
1060-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1061-
MethodDeclaration methodDeclaration,
1062-
Statement[] statements) {
1063-
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
1064-
}
1065-
});
1023+
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
10661024
}
10671025

10681026
/**
@@ -1181,98 +1139,50 @@ public void test_findLastAssignment_FieldDeclaration_noValue() throws Exception
11811139
@Test
11821140
public void test_findLastAssignment_FieldDeclaration_variable_thisMethod() throws Exception {
11831141
String code = "int value = 0; void root() {int value = 1; System.out.println(value);}";
1184-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
1185-
@Override
1186-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1187-
MethodDeclaration methodDeclaration,
1188-
Statement[] statements) {
1189-
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
1190-
}
1191-
});
1142+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
11921143
}
11931144

11941145
@Test
11951146
public void test_findLastAssignment_FieldDeclaration_reassign_thisMethod() throws Exception {
11961147
String code = "int value = 0; void root() {value = 1; System.out.println(value);}";
1197-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
1198-
@Override
1199-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1200-
MethodDeclaration methodDeclaration,
1201-
Statement[] statements) {
1202-
return ((ExpressionStatement) statements[0]).getExpression();
1203-
}
1204-
});
1148+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[0]).getExpression());
12051149
}
12061150

12071151
@Test
12081152
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod() throws Exception {
12091153
String code =
12101154
"int value = 0; void root() {foo(); System.out.println(value);} void foo() {value = 1;}";
1211-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
1212-
@Override
1213-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1214-
MethodDeclaration methodDeclaration,
1215-
Statement[] statements) {
1216-
Statement statement =
1217-
(Statement) typeDeclaration.getMethods()[1].getBody().statements().get(0);
1218-
return ((ExpressionStatement) statement).getExpression();
1219-
}
1155+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> {
1156+
Statement statement = (Statement) typeDeclaration.getMethods()[1].getBody().statements().get(0);
1157+
return ((ExpressionStatement) statement).getExpression();
12201158
});
12211159
}
12221160

12231161
@Test
12241162
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod2() throws Exception {
12251163
String code =
12261164
"int value = 0; void root() {System.out.println(value); foo();} void foo() {value = 1;}";
1227-
check_findLastAssignment(code, 0, new I_findLastAssignment() {
1228-
@Override
1229-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1230-
MethodDeclaration methodDeclaration,
1231-
Statement[] statements) {
1232-
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
1233-
}
1234-
});
1165+
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
12351166
}
12361167

12371168
@Test
12381169
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod3() throws Exception {
12391170
String code =
12401171
"int value = 0; void foo() {value = 1;} void root() {System.out.println(value); foo();}";
1241-
check_findLastAssignment(code, 0, new I_findLastAssignment() {
1242-
@Override
1243-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1244-
MethodDeclaration methodDeclaration,
1245-
Statement[] statements) {
1246-
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
1247-
}
1248-
});
1172+
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
12491173
}
12501174

12511175
@Test
12521176
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod4() throws Exception {
12531177
String code =
12541178
"int value = 0; void root() {foo(); System.out.println(value);} void foo() {int value = 1;}";
1255-
check_findLastAssignment(code, 1, new I_findLastAssignment() {
1256-
@Override
1257-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1258-
MethodDeclaration methodDeclaration,
1259-
Statement[] statements) {
1260-
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
1261-
}
1262-
});
1179+
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
12631180
}
12641181

12651182
@Test
12661183
public void test_findLastAssignment_parameters() throws Exception {
12671184
String code = "void root(int value) {System.out.println(value);}";
1268-
check_findLastAssignment(code, "root(int)", 0, new I_findLastAssignment() {
1269-
@Override
1270-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1271-
MethodDeclaration methodDeclaration,
1272-
Statement[] statements) {
1273-
return (ASTNode) methodDeclaration.parameters().get(0);
1274-
}
1275-
});
1185+
check_findLastAssignment(code, "root(int)", 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) methodDeclaration.parameters().get(0));
12761186
}
12771187

12781188
@Test
@@ -1320,14 +1230,7 @@ public void foo(int value) {
13201230
@Test
13211231
public void test_findLastAssignment_parameters_hide_field() throws Exception {
13221232
String code = "int value = 1; void root(int value) {System.out.println(value);}";
1323-
check_findLastAssignment(code, "root(int)", 0, new I_findLastAssignment() {
1324-
@Override
1325-
public ASTNode getExpected(TypeDeclaration typeDeclaration,
1326-
MethodDeclaration methodDeclaration,
1327-
Statement[] statements) {
1328-
return (ASTNode) methodDeclaration.parameters().get(0);
1329-
}
1330-
});
1233+
check_findLastAssignment(code, "root(int)", 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) methodDeclaration.parameters().get(0));
13311234
}
13321235

13331236
/**

‎org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/DefaultObjectPresentationTest.java‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ public void test_getChildrenTree() throws Exception {
5454
parent.addChild(child_2);
5555
parent.addChild(child_3);
5656
// filter out "child_2" from "tree children"
57-
parent.addBroadcastListener(new ObjectInfoChildTree() {
58-
@Override
59-
public void invoke(ObjectInfo object, boolean[] visible) throws Exception {
60-
if (object == child_2) {
61-
visible[0] = false;
62-
}
57+
parent.addBroadcastListener((ObjectInfoChildTree) (object, visible) -> {
58+
if (object == child_2) {
59+
visible[0] = false;
6360
}
6461
});
6562
// check "tree children"
@@ -84,12 +81,9 @@ public void test_getChildrenTree_childrenBroadcast() throws Exception {
8481
parent.addChild(child_2);
8582
parent.addChild(child_3);
8683
// move "child_1" to the end
87-
parent.addBroadcastListener(new ObjectInfoChildrenTree() {
88-
@Override
89-
public void invoke(ObjectInfo p, List<ObjectInfo> children) throws Exception {
90-
children.remove(child_1);
91-
children.add(child_1);
92-
}
84+
parent.addBroadcastListener((ObjectInfoChildrenTree) (p, children) -> {
85+
children.remove(child_1);
86+
children.add(child_1);
9387
});
9488
// check "tree children"
9589
List<ObjectInfo> children = parent.getPresentation().getChildrenTree();
@@ -109,12 +103,9 @@ public void test_getChildrenGraphical() throws Exception {
109103
parent.addChild(child_2);
110104
parent.addChild(child_3);
111105
// filter out "child_2" from "graphical children"
112-
parent.addBroadcastListener(new ObjectInfoChildGraphical() {
113-
@Override
114-
public void invoke(ObjectInfo object, boolean[] visible) throws Exception {
115-
if (object == child_2) {
116-
visible[0] = false;
117-
}
106+
parent.addBroadcastListener((ObjectInfoChildGraphical) (object, visible) -> {
107+
if (object == child_2) {
108+
visible[0] = false;
118109
}
119110
});
120111
// check "graphical children"
@@ -139,12 +130,9 @@ public void test_getChildrenGraphical_childrenBroadcast() throws Exception {
139130
parent.addChild(child_2);
140131
parent.addChild(child_3);
141132
// move "child_1" to the end
142-
parent.addBroadcastListener(new ObjectInfoChildrenGraphical() {
143-
@Override
144-
public void invoke(List<ObjectInfo> children) throws Exception {
145-
children.remove(child_1);
146-
children.add(child_1);
147-
}
133+
parent.addBroadcastListener((ObjectInfoChildrenGraphical) children -> {
134+
children.remove(child_1);
135+
children.add(child_1);
148136
});
149137
// check "graphical children"
150138
List<ObjectInfo> children = parent.getPresentation().getChildrenGraphical();

‎org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/model/JavaInfoTest.java‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,11 @@ public void test_setVariableBroadcast() throws Exception {
524524
}
525525
//
526526
final AtomicInteger count = new AtomicInteger();
527-
button.addBroadcastListener(new JavaInfoSetVariable() {
528-
@Override
529-
public void invoke(JavaInfo javaInfo, VariableSupport oldVariable, VariableSupport newVariable)
530-
throws Exception {
531-
assertSame(button, javaInfo);
532-
assertSame(expected_oldVariable, oldVariable);
533-
assertSame(expected_newVariable, newVariable);
534-
count.incrementAndGet();
535-
}
527+
button.addBroadcastListener((JavaInfoSetVariable) (javaInfo, oldVariable, newVariable) -> {
528+
assertSame(button, javaInfo);
529+
assertSame(expected_oldVariable, oldVariable);
530+
assertSame(expected_newVariable, newVariable);
531+
count.incrementAndGet();
536532
});
537533
button.setVariableSupport(expected_newVariable);
538534
assertEquals(1, count.get());
@@ -1438,12 +1434,9 @@ public void test_getProperties_allProperties() throws Exception {
14381434
// initially "panel" has properties
14391435
Assertions.assertThat(panel.getProperties()).isNotEmpty();
14401436
// add allProperties() listener
1441-
panel.addBroadcastListener(new ObjectInfoAllProperties() {
1442-
@Override
1443-
public void invoke(ObjectInfo object, List<Property> properties) throws Exception {
1444-
if (object == panel) {
1445-
properties.clear();
1446-
}
1437+
panel.addBroadcastListener((ObjectInfoAllProperties) (object, properties) -> {
1438+
if (object == panel) {
1439+
properties.clear();
14471440
}
14481441
});
14491442
Assertions.assertThat(panel.getProperties()).isEmpty();

0 commit comments

Comments
 (0)