Skip to main content
summaryrefslogtreecommitdiffstats
blob: e9c94dad5aca796529cb1bef9cc2d36143366b51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 * 
 * Copyright 2004, 2014 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 * 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 * 
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.test.builder;

import junit.framework.Test;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.tests.builder.Problem;
import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.objectteams.otdt.tests.ClasspathUtil;


public class CompilationOrderTests extends OTBuilderTests {

	public static Test suite() {
		return buildTestSuite(CompilationOrderTests.class);
	}

	public CompilationOrderTests(String name) {
		super(name);
	}
	
	/* In batch-mode this causes a problem, 
	 * compilation order is different in workbench mode, though
     * (depends on class names?!).
	 * Original jacks test is removed.
	 */
	@SuppressWarnings("nls")
	public void test177otjd5f()  throws JavaModelException {
		System.out.println("***** test177otjd5f() *****");
		IPath projectPath = env.addProject("Project", "1.5"); 
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
		env.addExternalJar(projectPath, ClasspathUtil.getOTREPath(this.weavingScheme));

		// remove old package fragment root so that names don't collide
		env.removePackageFragmentRoot(projectPath, "");

		IPath root = env.addPackageFragmentRoot(projectPath, "src");
		env.setOutputFolder(projectPath, "bin");

		env.addClass(root, "p", "ATeam",
				"package p;	\n"+ 
		"public team class ATeam {	protected class R implements IConfined {} public IConfined getR() { return new R(); } }");

		env.addClass(root, "p", "M", 
			"package p;	\n"+ 
			"public class M {\n"+
			"   @SuppressWarnings(\"unused\")\n"+
			"   void foo() {\n"+
			"       final ATeam t = new ATeam();\n"+
			"       IConfined<@t> ic = t.getR();\n"+
			"   }\n"+
			"}");

		fullBuild(projectPath);
		expectingNoProblems();
	}

	/* (TODO(SH): test doesn't really fit into this class).
	 * Witness for an NPE in ExplicitConstructorCall.resolve():
	 * If o.o.Team cannot be found, receiverType could be null!
	 */
	@SuppressWarnings("nls")
	public void testMissingOTRE() throws JavaModelException {
		System.out.println("***** testMissingOTRE() *****");
		IPath projectPath = env.addProject("Project", "1.5"); 
		// don't abort when detecting the build path error
		// (otherwise other errors would be expunged).
		env.getJavaProject(projectPath).setOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.ERROR);
		env.addExternalJars(projectPath, Util.getJavaClassLibs());
		// don't: env.addExternalJar(projectPath, OTRE_JAR_PATH);

		// remove old package fragment root so that names don't collide
		env.removePackageFragmentRoot(projectPath, "");

		IPath root = env.addPackageFragmentRoot(projectPath, "src");
		env.setOutputFolder(projectPath, "bin");

		IPath ateam = env.addClass(root, "p", "ATeam",
				"package p;	\n"+ 
		"public team class ATeam {	ATeam() { super(); } }");

		fullBuild(projectPath);
		
		expectingProblemsFor(ateam);
		expectingOnlySpecificProblemsFor(ateam, 
				new Problem[] {
					new Problem("", "The type org.objectteams.Team cannot be resolved. It is indirectly referenced from required .class files", ateam, 30, 35, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR),
					new Problem("", "The constructor Team() is undefined", ateam, 48,56, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)
				});
	}
}

Back to the top