From 1ea982a96d7f69d600e47510accb75db7851f087 Mon Sep 17 00:00:00 2001 From: sougandhs Date: Wed, 4 Sep 2024 05:29:16 +0530 Subject: [PATCH] JUnit experimental | ASTEvalEngine - WIP --- .../META-INF/MANIFEST.MF | 2 +- org.eclipse.jdt.debug.tests/pom.xml | 2 +- .../testprograms/FileConditionSnippet2.java | 1 + .../jdt/debug/tests/AbstractDebugTest.java | 2 +- .../ConditionalBreakpointsWithFileClass.java | 40 ++++++++++++------- .../eval/ast/engine/ASTEvaluationEngine.java | 14 ++++--- .../ConditionalBreakpointHandler.java | 18 ++++++--- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF index d091a30d65..a6398191f7 100644 --- a/org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.debug.tests; singleton:=true -Bundle-Version: 3.12.500.qualifier +Bundle-Version: 3.12.600.qualifier Bundle-ClassPath: javadebugtests.jar Bundle-Activator: org.eclipse.jdt.debug.testplugin.JavaTestPlugin Bundle-Vendor: %providerName diff --git a/org.eclipse.jdt.debug.tests/pom.xml b/org.eclipse.jdt.debug.tests/pom.xml index 6fd71e5434..bfedb46d53 100644 --- a/org.eclipse.jdt.debug.tests/pom.xml +++ b/org.eclipse.jdt.debug.tests/pom.xml @@ -18,7 +18,7 @@ org.eclipse.jdt org.eclipse.jdt.debug.tests - 3.12.500-SNAPSHOT + 3.12.600-SNAPSHOT eclipse-test-plugin ${project.artifactId} diff --git a/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java b/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java index 5d4f722149..6099906d3c 100644 --- a/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java +++ b/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java @@ -6,5 +6,6 @@ public static void main(String[] ecs) { File parent = new File("parent"); File file = new File(parent,"test"); System.out.println("COMPLETED"); + System.out.println("COMPLETED"); } } \ No newline at end of file diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java index 9e03b8b4f9..b9474b5f00 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java @@ -184,7 +184,7 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation public static final String BOUND_JRE_PROJECT_NAME = "BoundJRE"; public static final String CLONE_SUFFIX = "Clone"; - final String[] LAUNCH_CONFIG_NAMES_1_4 = { "java.io.File", "LargeSourceFile", "LotsOfFields", + final String[] LAUNCH_CONFIG_NAMES_1_4 = { "LargeSourceFile", "LotsOfFields", "Breakpoints", "InstanceVariablesTests", "LocalVariablesTests", "LocalVariableTests2", "StaticVariablesTests", diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java index 13115e4f4c..180c1fa437 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java @@ -1,50 +1,60 @@ package org.eclipse.jdt.debug.tests.breakpoints; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.debug.core.IJavaLineBreakpoint; import org.eclipse.jdt.debug.core.IJavaThread; import org.eclipse.jdt.debug.tests.AbstractDebugTest; public class ConditionalBreakpointsWithFileClass extends AbstractDebugTest { + public ConditionalBreakpointsWithFileClass(String name) { super(name); } - public void testFileConditionalBreakpointForTrue() throws Exception { + @Override + protected IJavaProject getProjectContext() { + return get14Project(); + } + + public void testFileConditionalBreakpointforFalse() throws Exception { String typeName = "FileConditionSnippet2"; - IJavaLineBreakpoint bp2 = createLineBreakpoint(7, typeName); - IJavaLineBreakpoint bp = createConditionalLineBreakpoint(374, "java.io.File", "child.equals(\"test\")", true); + IJavaLineBreakpoint bp3 = createLineBreakpoint(8, typeName); + IJavaLineBreakpoint bp2 = createConditionalLineBreakpoint(364, "java.io.File", "false", true); IJavaThread mainThread = null; + try { + Thread.sleep(10); mainThread = launchToBreakpoint(typeName); - mainThread.getTopStackFrame().stepInto(); - Thread.sleep(100); - mainThread.resume(); - Thread.sleep(100); int hitLine = 0; assertTrue("Thread should be suspended", mainThread.isSuspended()); hitLine = mainThread.getStackFrames()[0].getLineNumber(); - assertEquals("Should've hit", 374, hitLine); + assertEquals("JENKINS FILE CLASS TESTING", 8, hitLine); + bp2.delete(); - bp.delete(); + bp3.delete(); } finally { terminateAndRemove(mainThread); removeAllBreakpoints(); } } - public void testFileConditionalBreakpointForFalse() throws Exception { + public void testFileConditionalBreakpointforTrue() throws Exception { String typeName = "FileConditionSnippet2"; - IJavaLineBreakpoint bp = createLineBreakpoint(8, typeName); - IJavaLineBreakpoint bp2 = createConditionalLineBreakpoint(374, "java.io.File", "child.equals(\"test2\")", true); + IJavaLineBreakpoint bp3 = createLineBreakpoint(8, typeName); + IJavaLineBreakpoint bp2 = createConditionalLineBreakpoint(364, "java.io.File", "true", true); IJavaThread mainThread = null; + try { + Thread.sleep(10); mainThread = launchToBreakpoint(typeName); int hitLine = 0; - hitLine = mainThread.getTopStackFrame().getLineNumber(); - assertEquals("Should've hit", 8, hitLine); + assertTrue("Thread should be suspended", mainThread.isSuspended()); + hitLine = mainThread.getStackFrames()[0].getLineNumber(); + assertEquals("JENKINS FILE CLASS TESTING", 364, hitLine); + bp2.delete(); - bp.delete(); + bp3.delete(); } finally { terminateAndRemove(mainThread); removeAllBreakpoints(); diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java index 87a872b594..c89e7b9de4 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java @@ -682,13 +682,16 @@ private ICompiledExpression createExpressionFromAST(String snippet, errorSequence.addError(problem.getMessage()); snippetError = true; } - if (problemId == IProblem.VoidMethodReturnsValue + if (problemId == IProblem.VoidMethodReturnsValue // WIP [do not merge] || problemId == IProblem.NotVisibleMethod || problemId == IProblem.NotVisibleConstructor || problemId == IProblem.NotVisibleField || problemId == IProblem.NotVisibleType - || problemId == IProblem.UnexpectedStaticModifierForMethod || problemId == IProblem.AmbiguousType) { - continue; + || problemId == IProblem.UnexpectedStaticModifierForMethod || problemId == IProblem.AmbiguousType + || problemId == IProblem.UninitializedBlankFinalField + || problemId == IProblem.ParsingErrorDeleteTokens || problemId == 1610612976) { // Need to refer to the correct problem ID + continue; // [WIP] + } if (problem.isError()) { if (codeSnippetStart <= errorOffset @@ -698,8 +701,9 @@ private ICompiledExpression createExpressionFromAST(String snippet, } else if (runMethodStart <= errorOffset && errorOffset <= runMethodEnd) { runMethodError = true; - DebugPlugin.log(new Status(IStatus.WARNING, DebugPlugin.getUniqueIdentifier(), "Compile error during code evaluation: " //$NON-NLS-1$ - + problem.getMessage())); + DebugPlugin.log(new Status(IStatus.WARNING, DebugPlugin.getUniqueIdentifier(), problemId + + " -> Compile error during code evaluation: Snip -> " + snippet //$NON-NLS-1$ + + problem.getMessage() + unit.toString())); } } } diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ConditionalBreakpointHandler.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ConditionalBreakpointHandler.java index 91656805d6..0143d80926 100644 --- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ConditionalBreakpointHandler.java +++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/ConditionalBreakpointHandler.java @@ -15,6 +15,8 @@ import java.text.MessageFormat; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -23,6 +25,7 @@ import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IValue; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.dom.Message; import org.eclipse.jdt.debug.core.IJavaBreakpoint; import org.eclipse.jdt.debug.core.IJavaBreakpointListener; @@ -217,12 +220,15 @@ public int breakpointHit(IJavaThread thread, IJavaBreakpoint breakpoint) { .getTopStackFrame(); IJavaProject project = lineBreakpoint.getJavaProject(frame); if (project == null) { - fireConditionHasErrors( - lineBreakpoint, - new Message[] { new Message( - JDIDebugBreakpointMessages.JavaLineBreakpoint_Unable_to_compile_conditional_breakpoint___missing_Java_project_context__1, - -1) }); - return SUSPEND; + IMarker marker = breakpoint.getMarker(); // my changes + if (marker != null) { + IResource res = marker.getResource(); + project = JavaCore.create(res.getProject()); + } else { + fireConditionHasErrors(lineBreakpoint, new Message[] { + new Message(JDIDebugBreakpointMessages.JavaLineBreakpoint_Unable_to_compile_conditional_breakpoint___missing_Java_project_context__1, -1) }); + return SUSPEND; + } } IJavaDebugTarget target = (IJavaDebugTarget) thread .getDebugTarget();