This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ModelLoaderTests.java
159 lines (136 loc) · 6.7 KB
/
ModelLoaderTests.java
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*************************************************************************************
* Copyright (c) 2011 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* JBoss by Red Hat - Initial implementation.
************************************************************************************/
package com.redhat.ceylon.eclipse.ui.test;
import junit.framework.Assert;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.junit.BeforeClass;
import org.junit.Ignore;
import com.redhat.ceylon.compiler.java.codegen.Decl;
import com.redhat.ceylon.compiler.java.test.model.ModelLoaderTest;
import com.redhat.ceylon.compiler.java.test.model.RunnableTest;
import com.redhat.ceylon.compiler.loader.ModelLoader.DeclarationType;
import com.redhat.ceylon.compiler.typechecker.context.PhasedUnit;
import com.redhat.ceylon.compiler.typechecker.model.Declaration;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.Value;
import com.redhat.ceylon.eclipse.core.builder.CeylonBuilder;
import com.redhat.ceylon.eclipse.core.model.loader.JDTModelLoader;
/**
*
* @author david
*
*/
public class ModelLoaderTests extends ModelLoaderTest {
static private AssertionError compilationError = null;
static private IProject projectDeclarations = null;
static private IProject projectReferences = null;
@BeforeClass
public static void compileDeclarationsAndReferences() {
try {
IPath projectDescriptionPath = null;
IPath userDirPath = new Path(System.getProperty("user.dir"));
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
projectDescriptionPath = userDirPath.append("resources/model-loader-tests/declarations/.project");
projectDeclarations = Utils.importProject(workspace, "model-loader-tests", projectDescriptionPath);
}
catch(Exception e) {
Assert.fail("Import of the declarations project failed with the exception : \n" + e.toString());
}
try {
projectDeclarations.build(IncrementalProjectBuilder.FULL_BUILD, null);
IFile carFile = projectDeclarations.getFile("modules/declarations/1.0.0/declarations-1.0.0.car");
carFile.refreshLocal(0, null);
Assert.assertTrue("declarations Project should compile",
carFile.exists());
projectDeclarations.getFile("modules/declarations/1.0.0/declarations-1.0.0.src").getLocation().toFile().delete();
projectDeclarations.getFile("modules/declarations/1.0.0/declarations-1.0.0.src.sha1").getLocation().toFile().delete();
}
catch(Exception e) {
Assert.fail("Build of the declarations project failed with the exception : \n" + e.toString());
}
try {
projectDescriptionPath = userDirPath.append("resources/model-loader-tests/references/.project");
projectReferences = Utils.importProject(workspace, "model-loader-tests",
projectDescriptionPath);
}
catch(Exception e) {
Assert.fail("Build of the references project failed with the exception : \n" + e.toString());
}
try {
projectReferences.build(IncrementalProjectBuilder.FULL_BUILD, null);
IFile carFile = projectReferences.getFile("modules/references/1.0.0/references-1.0.0.car");
carFile.refreshLocal(0, null);
Assert.assertTrue("references Project should compile",
carFile.exists());
}
catch(Exception e) {
Assert.fail("Build of the references project failed with the exception : \n" + e.toString());
}
}
catch(AssertionError e) {
compilationError = e;
}
}
@Override
protected void verifyClassLoading(String ceylon) {
if (compilationError != null) {
throw compilationError;
}
PhasedUnit phasedUnit = CeylonBuilder.getProjectTypeChecker(projectDeclarations)
.getPhasedUnitFromRelativePath("declarations/" + ceylon);
final Map<String,Declaration> decls = new HashMap<String,Declaration>();
for(Declaration decl : phasedUnit.getUnit().getDeclarations()){
if(decl.isToplevel()){
decls.put(getQualifiedPrefixedName(decl), decl);
}
}
JDTModelLoader modelLoader = CeylonBuilder.getProjectModelLoader(projectReferences);
for(Entry<String, Declaration> entry : decls.entrySet()){
String quotedQualifiedName = entry.getKey().substring(1);
Module module = Decl.getModuleContainer(entry.getValue().getContainer());
Declaration modelDeclaration = modelLoader.getDeclaration(module, quotedQualifiedName,
entry.getValue() instanceof Value ? DeclarationType.VALUE : DeclarationType.TYPE);
Assert.assertNotNull(modelDeclaration);
// make sure we loaded them exactly the same
compareDeclarations(entry.getValue(), modelDeclaration);
}
}
@Override
protected void compareDeclarations(Declaration validDeclaration,
Declaration modelDeclaration) {
if (modelDeclaration.getUnit() != null &&
modelDeclaration.getUnit().getFilename() != null &&
modelDeclaration.getUnit().getFilename().endsWith(".ceylon")) {
return;
}
super.compareDeclarations(validDeclaration, modelDeclaration);
}
@Override
@Ignore
public void testTypeParserUsingSourceModel(){
}
@Override
protected void verifyClassLoading(String ceylon, RunnableTest test,
List<String> options) {
test.test(CeylonBuilder.getProjectModelLoader(projectReferences));
}
}