View | Details | Raw Unified | Return to bug 102778 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java (+88 lines)
Lines 106-111 Link Here
106
			.append("\"");
106
			.append("\"");
107
		org.eclipse.jdt.internal.compiler.batch.Main.compile(buffer.toString());
107
		org.eclipse.jdt.internal.compiler.batch.Main.compile(buffer.toString());
108
	}
108
	}
109
	public void compileAndDeploy15(String source, String className) {
110
		resetEnv(); // needed to reinitialize the caches
111
		File directory = new File(SOURCE_DIRECTORY);
112
		if (!directory.exists()) {
113
			if (!directory.mkdir()) {
114
				System.out.println("Could not create " + SOURCE_DIRECTORY);
115
				return;
116
			}
117
		}
118
		String fileName = SOURCE_DIRECTORY + File.separator + className + ".java";
119
		try {
120
			BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
121
			writer.write(source);
122
			writer.flush();
123
			writer.close();
124
		} catch(IOException e) {
125
			e.printStackTrace();
126
			return;
127
		}
128
		StringBuffer buffer = new StringBuffer();
129
		buffer
130
			.append("\"")
131
			.append(fileName)
132
			.append("\" -d \"")
133
			.append(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY)
134
			.append("\" -nowarn -1.5 -g -classpath \"")
135
			.append(Util.getJavaClassLibsAsString())
136
			.append(SOURCE_DIRECTORY)
137
			.append("\"");
138
		org.eclipse.jdt.internal.compiler.batch.Main.compile(buffer.toString());
139
	}
109
	/**
140
	/**
110
	 * Generate local variable attribute for these tests.
141
	 * Generate local variable attribute for these tests.
111
	 */
142
	 */
Lines 3780-3783 Link Here
3780
		"The final field System.out cannot be assigned|",
3811
		"The final field System.out cannot be assigned|",
3781
		buffer == null ? "none" : buffer.toString());
3812
		buffer == null ? "none" : buffer.toString());
3782
}
3813
}
3814
/**
3815
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=102778
3816
 */
3817
public void test063() {
3818
	if (!this.complianceLevel.equals(COMPLIANCE_1_5)) return;
3819
	try {
3820
		String sourceA63 =
3821
			"public class A63 {\n" +
3822
			"  public static void bar() {\n" +
3823
			"  }\n" +
3824
			"}";
3825
		compileAndDeploy15(sourceA63, "A63");
3826
3827
		String userCode = "new A63().bar();";
3828
		JDIStackFrame stackFrame =
3829
			new JDIStackFrame(this.jdiVM, this, userCode, "A63", "bar", -1);
3830
3831
		DebugRequestor requestor = new DebugRequestor();
3832
		char[] snippet = ("int[] tab = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" +
3833
				"int sum = 0;\n" +
3834
				"for (int i : tab) {\n" +
3835
				"	sum += i;\n" +
3836
				"}\n" +
3837
				"sum").toCharArray();
3838
		Map compilerOpts = getCompilerOptions();
3839
		compilerOpts.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
3840
		compilerOpts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
3841
		compilerOpts.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_2);
3842
3843
		try {
3844
			context.evaluate(
3845
				snippet,
3846
				stackFrame.localVariableTypeNames(),
3847
				stackFrame.localVariableNames(),
3848
				stackFrame.localVariableModifiers(),
3849
				stackFrame.declaringTypeName(),
3850
				stackFrame.isStatic(),
3851
				stackFrame.isConstructorCall(),
3852
				getEnv(),
3853
				compilerOpts,
3854
				requestor,
3855
				getProblemFactory());
3856
		} catch (InstallException e) {
3857
			assertTrue("No targetException " + e.getMessage(), false);
3858
		}
3859
		assertTrue(
3860
			"Should get one result but got " + (requestor.resultIndex + 1),
3861
			requestor.resultIndex == 0);
3862
		EvaluationResult result = requestor.results[0];
3863
		assertTrue("Code snippet should not have problems", !result.hasProblems());
3864
		assertTrue("Result should have a value", result.hasValue());
3865
		assertEquals("Value", "45".toCharArray(), result.getValueDisplayString());
3866
		assertEquals("Type", "int".toCharArray(), result.getValueTypeName());
3867
	} finally {
3868
		removeTempClass("A62");
3869
	}
3870
}
3783
}
3871
}

Return to bug 102778