Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ public void test_getDefault() {
public void test_log_message() {
final String message = "Information message";
ILog log = DesignerPlugin.getDefault().getLog();
ILogListener logListener = new ILogListener() {
@Override
public void logging(IStatus status, String plugin) {
assertEquals(IStatus.INFO, status.getSeverity());
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
assertEquals(IStatus.INFO, status.getCode());
assertEquals(message, status.getMessage());
assertNull(status.getException());
}
ILogListener logListener = (status, plugin) -> {
assertEquals(IStatus.INFO, status.getSeverity());
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
assertEquals(IStatus.INFO, status.getCode());
assertEquals(message, status.getMessage());
assertNull(status.getException());
};
//
try {
Expand All @@ -79,14 +76,11 @@ public void logging(IStatus status, String plugin) {
public void test_log_Exception() {
final Exception exception = new Exception();
ILog log = DesignerPlugin.getDefault().getLog();
ILogListener logListener = new ILogListener() {
@Override
public void logging(IStatus status, String plugin) {
assertEquals(IStatus.ERROR, status.getSeverity());
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
assertEquals(IStatus.ERROR, status.getCode());
assertSame(exception, status.getException());
}
ILogListener logListener = (status, plugin) -> {
assertEquals(IStatus.ERROR, status.getSeverity());
assertEquals(DesignerPlugin.PLUGIN_ID, status.getPlugin());
assertEquals(IStatus.ERROR, status.getCode());
assertSame(exception, status.getException());
};
//
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -389,18 +387,15 @@ public static void waitForAutoBuild() {
*/
private void clearReadOnlyFlag() throws CoreException {
if (m_project.isOpen()) {
m_project.accept(new IResourceVisitor() {
@Override
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile file) {
ResourceAttributes resourceAttributes = file.getResourceAttributes();
if (resourceAttributes != null) {
resourceAttributes.setReadOnly(false);
file.setResourceAttributes(resourceAttributes);
}
m_project.accept(resource -> {
if (resource instanceof IFile file) {
ResourceAttributes resourceAttributes = file.getResourceAttributes();
if (resourceAttributes != null) {
resourceAttributes.setReadOnly(false);
file.setResourceAttributes(resourceAttributes);
}
return true;
}
return true;
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,14 +930,7 @@ public void test_visit_AnonymousClassDeclaration_withInvocation_doVisit(String r
@Test
public void test_findLastAssignment_variable() throws Exception {
String code = "void root() {int value = 0; System.out.println(value);}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
}
});
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
}

/**
Expand Down Expand Up @@ -1001,68 +994,33 @@ void root() {
@Test
public void test_findLastAssignment_variable_reassign() throws Exception {
String code = "void root() {int value = 0; value = 1; System.out.println(value);}";
check_findLastAssignment(code, 2, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return ((ExpressionStatement) statements[1]).getExpression();
}
});
check_findLastAssignment(code, 2, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[1]).getExpression());
}

@Test
public void test_findLastAssignment_variable_reassign2() throws Exception {
String code =
"void root() {int value; value = 0; System.out.println(value); value = 1; System.out.println(value);}";
check_findLastAssignment(code, 4, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return ((ExpressionStatement) statements[3]).getExpression();
}
});
check_findLastAssignment(code, 4, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[3]).getExpression());
}

@Test
public void test_findLastAssignment_variable_reassign_later() throws Exception {
String code = "void root() {int value = 0; System.out.println(value); value = 1;}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
}
});
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
}

@Test
public void test_findLastAssignment_variable_sameInDifferentMethod() throws Exception {
String code =
"void root() {int value = 0; foo(); System.out.println(value);} void foo() {int value = 1;}";
check_findLastAssignment(code, 2, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
}
});
check_findLastAssignment(code, 2, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
}

@Test
public void test_findLastAssignment_FieldDeclaration() throws Exception {
String code = "int value = 0; void root() {System.out.println(value);}";
check_findLastAssignment(code, 0, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
}
});
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
}

/**
Expand Down Expand Up @@ -1181,98 +1139,50 @@ public void test_findLastAssignment_FieldDeclaration_noValue() throws Exception
@Test
public void test_findLastAssignment_FieldDeclaration_variable_thisMethod() throws Exception {
String code = "int value = 0; void root() {int value = 1; System.out.println(value);}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0);
}
});
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) ((VariableDeclarationStatement) statements[0]).fragments().get(0));
}

@Test
public void test_findLastAssignment_FieldDeclaration_reassign_thisMethod() throws Exception {
String code = "int value = 0; void root() {value = 1; System.out.println(value);}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return ((ExpressionStatement) statements[0]).getExpression();
}
});
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> ((ExpressionStatement) statements[0]).getExpression());
}

@Test
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod() throws Exception {
String code =
"int value = 0; void root() {foo(); System.out.println(value);} void foo() {value = 1;}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
Statement statement =
(Statement) typeDeclaration.getMethods()[1].getBody().statements().get(0);
return ((ExpressionStatement) statement).getExpression();
}
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> {
Statement statement = (Statement) typeDeclaration.getMethods()[1].getBody().statements().get(0);
return ((ExpressionStatement) statement).getExpression();
});
}

@Test
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod2() throws Exception {
String code =
"int value = 0; void root() {System.out.println(value); foo();} void foo() {value = 1;}";
check_findLastAssignment(code, 0, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
}
});
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
}

@Test
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod3() throws Exception {
String code =
"int value = 0; void foo() {value = 1;} void root() {System.out.println(value); foo();}";
check_findLastAssignment(code, 0, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
}
});
check_findLastAssignment(code, 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
}

@Test
public void test_findLastAssignment_FieldDeclaration_reassign_otherMethod4() throws Exception {
String code =
"int value = 0; void root() {foo(); System.out.println(value);} void foo() {int value = 1;}";
check_findLastAssignment(code, 1, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) typeDeclaration.getFields()[0].fragments().get(0);
}
});
check_findLastAssignment(code, 1, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) typeDeclaration.getFields()[0].fragments().get(0));
}

@Test
public void test_findLastAssignment_parameters() throws Exception {
String code = "void root(int value) {System.out.println(value);}";
check_findLastAssignment(code, "root(int)", 0, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) methodDeclaration.parameters().get(0);
}
});
check_findLastAssignment(code, "root(int)", 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) methodDeclaration.parameters().get(0));
}

@Test
Expand Down Expand Up @@ -1320,14 +1230,7 @@ public void foo(int value) {
@Test
public void test_findLastAssignment_parameters_hide_field() throws Exception {
String code = "int value = 1; void root(int value) {System.out.println(value);}";
check_findLastAssignment(code, "root(int)", 0, new I_findLastAssignment() {
@Override
public ASTNode getExpected(TypeDeclaration typeDeclaration,
MethodDeclaration methodDeclaration,
Statement[] statements) {
return (ASTNode) methodDeclaration.parameters().get(0);
}
});
check_findLastAssignment(code, "root(int)", 0, (typeDeclaration, methodDeclaration, statements) -> (ASTNode) methodDeclaration.parameters().get(0));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ public void test_getChildrenTree() throws Exception {
parent.addChild(child_2);
parent.addChild(child_3);
// filter out "child_2" from "tree children"
parent.addBroadcastListener(new ObjectInfoChildTree() {
@Override
public void invoke(ObjectInfo object, boolean[] visible) throws Exception {
if (object == child_2) {
visible[0] = false;
}
parent.addBroadcastListener((ObjectInfoChildTree) (object, visible) -> {
if (object == child_2) {
visible[0] = false;
}
});
// check "tree children"
Expand All @@ -84,12 +81,9 @@ public void test_getChildrenTree_childrenBroadcast() throws Exception {
parent.addChild(child_2);
parent.addChild(child_3);
// move "child_1" to the end
parent.addBroadcastListener(new ObjectInfoChildrenTree() {
@Override
public void invoke(ObjectInfo p, List<ObjectInfo> children) throws Exception {
children.remove(child_1);
children.add(child_1);
}
parent.addBroadcastListener((ObjectInfoChildrenTree) (p, children) -> {
children.remove(child_1);
children.add(child_1);
});
// check "tree children"
List<ObjectInfo> children = parent.getPresentation().getChildrenTree();
Expand All @@ -109,12 +103,9 @@ public void test_getChildrenGraphical() throws Exception {
parent.addChild(child_2);
parent.addChild(child_3);
// filter out "child_2" from "graphical children"
parent.addBroadcastListener(new ObjectInfoChildGraphical() {
@Override
public void invoke(ObjectInfo object, boolean[] visible) throws Exception {
if (object == child_2) {
visible[0] = false;
}
parent.addBroadcastListener((ObjectInfoChildGraphical) (object, visible) -> {
if (object == child_2) {
visible[0] = false;
}
});
// check "graphical children"
Expand All @@ -139,12 +130,9 @@ public void test_getChildrenGraphical_childrenBroadcast() throws Exception {
parent.addChild(child_2);
parent.addChild(child_3);
// move "child_1" to the end
parent.addBroadcastListener(new ObjectInfoChildrenGraphical() {
@Override
public void invoke(List<ObjectInfo> children) throws Exception {
children.remove(child_1);
children.add(child_1);
}
parent.addBroadcastListener((ObjectInfoChildrenGraphical) children -> {
children.remove(child_1);
children.add(child_1);
});
// check "graphical children"
List<ObjectInfo> children = parent.getPresentation().getChildrenGraphical();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,11 @@ public void test_setVariableBroadcast() throws Exception {
}
//
final AtomicInteger count = new AtomicInteger();
button.addBroadcastListener(new JavaInfoSetVariable() {
@Override
public void invoke(JavaInfo javaInfo, VariableSupport oldVariable, VariableSupport newVariable)
throws Exception {
assertSame(button, javaInfo);
assertSame(expected_oldVariable, oldVariable);
assertSame(expected_newVariable, newVariable);
count.incrementAndGet();
}
button.addBroadcastListener((JavaInfoSetVariable) (javaInfo, oldVariable, newVariable) -> {
assertSame(button, javaInfo);
assertSame(expected_oldVariable, oldVariable);
assertSame(expected_newVariable, newVariable);
count.incrementAndGet();
});
button.setVariableSupport(expected_newVariable);
assertEquals(1, count.get());
Expand Down Expand Up @@ -1438,12 +1434,9 @@ public void test_getProperties_allProperties() throws Exception {
// initially "panel" has properties
Assertions.assertThat(panel.getProperties()).isNotEmpty();
// add allProperties() listener
panel.addBroadcastListener(new ObjectInfoAllProperties() {
@Override
public void invoke(ObjectInfo object, List<Property> properties) throws Exception {
if (object == panel) {
properties.clear();
}
panel.addBroadcastListener((ObjectInfoAllProperties) (object, properties) -> {
if (object == panel) {
properties.clear();
}
});
Assertions.assertThat(panel.getProperties()).isEmpty();
Expand Down
Loading
Loading