Skip to content
Browse files

model loader: changes in API due to ceylon/ceylon-compiler#1052

  • Loading branch information...
1 parent b8c9290 commit d790e657176498d26829552a70a9fc88e084b136 @FroMage FroMage committed May 28, 2013
View
7 ...om.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/core/builder/CeylonBuilder.java
@@ -1216,9 +1216,10 @@ private Unit getJavaUnit(IProject project, IFile fileToUpdate) {
pu.validateRefinement(); //TODO: only needed for type hierarchy view in IDE!
}
- loader.loadPackage("com.redhat.ceylon.compiler.java.metadata", true);
- loader.loadPackage("ceylon.language", true);
- loader.loadPackage("ceylon.language.descriptor", true);
+ Module languageModule = loader.getLanguageModule();
+ loader.loadPackage(languageModule, "com.redhat.ceylon.compiler.java.metadata", true);
+ loader.loadPackage(languageModule, "ceylon.language", true);
+ loader.loadPackage(languageModule, "ceylon.language.descriptor", true);
loader.loadPackageDescriptors();
View
2 ...t.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/core/builder/JdtPhasedUnitsManager.java
@@ -73,7 +73,7 @@ public PhasedUnit getExternalSourcePhasedUnit(
allPhasedUnits.addAll(dependencies);
allPhasedUnits.addAll(sourceUnits);
- ClassMirror objectMirror = modelLoader.lookupClassMirror("ceylon.language.Object");
+ ClassMirror objectMirror = modelLoader.lookupClassMirror(modelLoader.getLanguageModule(), "ceylon.language.Object");
if (objectMirror instanceof SourceClass) {
Declaration objectClass = ((SourceClass) objectMirror).getModelDeclaration();
if (objectClass != null) {
View
3 ...lon.eclipse.ui/src/com/redhat/ceylon/eclipse/core/builder/JdtSourceFileObjectManager.java
@@ -49,7 +49,8 @@ public void loadFromSource(Tree.Declaration decl) {
// this happens when we have already registered a source
// file for this decl, so let's print out a helpful message
// see https://github.com/ceylon/ceylon-compiler/issues/250
- ClassMirror previousClass = modelLoader.lookupClassMirror(fqn);
+ // we can pass null here because the module is not currently used
+ ClassMirror previousClass = modelLoader.lookupClassMirror(null, fqn);
CeylonLog.instance(context).error("ceylon", "Duplicate declaration error: " +
fqn + " is declared twice: once in " + tree.getSourceFile() +
" and again in: " + CeylonBuilder.fileName(previousClass));
View
59 ...hat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/core/model/loader/JDTModelLoader.java
@@ -315,12 +315,13 @@ public synchronized LazyPackage findOrCreatePackage(Module module, String pkgNam
@Override
public void loadStandardModules() {
- // do not load the jdk modules unless imported explicitely
+ // do not load the other jdk modules unless imported explicitely, but the base one is required
/*
* We start by loading java.lang because we will need it no matter what.
*/
- loadPackage("java.lang", false);
+ Module jdkModule = findOrCreateModule(JAVA_BASE_MODULE_NAME);
+ loadPackage(jdkModule, "java.lang", false);
}
private String getToplevelQualifiedName(final String pkgName, String name) {
@@ -333,12 +334,11 @@ private String getToplevelQualifiedName(final String pkgName, String name) {
}
@Override
- public synchronized boolean loadPackage(String packageName, boolean loadDeclarations) {
+ public synchronized boolean loadPackage(Module module, String packageName, boolean loadDeclarations) {
packageName = Util.quoteJavaKeywords(packageName);
if(loadDeclarations && !loadedPackages.add(packageName)){
return true;
}
- Module module = lookupModuleInternal(packageName);
if (module instanceof JDTModule) {
JDTModule jdtModule = (JDTModule) module;
@@ -370,24 +370,25 @@ public synchronized boolean loadPackage(String packageName, boolean loadDeclarat
try {
// we have a few virtual types in java.lang that we need to load but they are not listed from class files
if(packageName.equals("java.lang")){
- convertToDeclaration(JAVA_LANG_ARRAYS, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_BOOLEAN_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_BYTE_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_SHORT_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_INT_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_LONG_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_FLOAT_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_DOUBLE_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_CHAR_ARRAY, DeclarationType.TYPE);
- convertToDeclaration(JAVA_LANG_OBJECT_ARRAY, DeclarationType.TYPE);
+ Module jdkBaseModule = getJDKBaseModule();
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_ARRAYS, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_BOOLEAN_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_BYTE_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_SHORT_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_INT_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_LONG_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_FLOAT_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_DOUBLE_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_CHAR_ARRAY, DeclarationType.TYPE);
+ convertToDeclaration(jdkBaseModule, JAVA_LANG_OBJECT_ARRAY, DeclarationType.TYPE);
}
for (IClassFile classFile : packageFragment.getClassFiles()) {
// skip removed class files
if(!classFile.exists())
continue;
IType type = classFile.getType();
if (type.exists() && ! type.isMember() && !sourceDeclarations.containsKey(getToplevelQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) { // only top-levels ar added in source declarations
- convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE);
+ convertToDeclaration(module, type.getFullyQualifiedName(), DeclarationType.VALUE);
}
}
for (org.eclipse.jdt.core.ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
@@ -396,7 +397,7 @@ public synchronized boolean loadPackage(String packageName, boolean loadDeclarat
continue;
for (IType type : compilationUnit.getTypes()) {
if (type.exists() && ! type.isMember() && !sourceDeclarations.containsKey(getToplevelQualifiedName(type.getPackageFragment().getElementName(), type.getTypeQualifiedName()))) {
- convertToDeclaration(type.getFullyQualifiedName(), DeclarationType.VALUE);
+ convertToDeclaration(module, type.getFullyQualifiedName(), DeclarationType.VALUE);
}
}
}
@@ -422,7 +423,7 @@ synchronized private LookupEnvironment getLookupEnvironment() {
}
@Override
- public synchronized ClassMirror lookupNewClassMirror(String name) {
+ public synchronized ClassMirror lookupNewClassMirror(Module module, String name) {
if (sourceDeclarations.containsKey(name)) {
return new SourceClass(sourceDeclarations.get(name));
}
@@ -516,13 +517,13 @@ private ClassMirror buildClassMirror(String name) {
@Override
- public synchronized Declaration convertToDeclaration(String typeName,
+ public synchronized Declaration convertToDeclaration(Module module, String typeName,
DeclarationType declarationType) {
if (sourceDeclarations.containsKey(typeName)) {
return sourceDeclarations.get(typeName).getModelDeclaration();
}
try {
- return super.convertToDeclaration(typeName, declarationType);
+ return super.convertToDeclaration(module, typeName, declarationType);
} catch(RuntimeException e) {
return null;
}
@@ -750,7 +751,8 @@ public synchronized void completeFromClasses() {
if (classMirror == null) {
continue;
}
- final Declaration binaryDeclaration = getOrCreateDeclaration(classMirror,
+ Module module = findModuleForClassMirror(classMirror);
+ final Declaration binaryDeclaration = getOrCreateDeclaration(module, classMirror,
DeclarationType.TYPE,
new ArrayList<Declaration>(), new boolean[1]);
@@ -836,5 +838,20 @@ public void visit(Tree.AnyMethod that) {
private boolean mustCompleteFromClasses(SourceDeclarationHolder d) {
return !d.isSourceToCompile() && d.getPhasedUnit().getUnit().getPackage().getQualifiedNameString().startsWith("ceylon.language");
}
-
+
+ public synchronized Package findPackage(String quotedPkgName) {
+ String pkgName = quotedPkgName.replace("$", "");
+ // in theory we only have one package with the same name per module in eclipse
+ for(Package pkg : packagesByName.values()){
+ if(pkg.getNameAsString().equals(pkgName))
+ return pkg;
+ }
+ return null;
+ }
+
+ @Override
+ protected Module findModuleForClassMirror(ClassMirror classMirror) {
+ String pkgName = getPackageNameForQualifiedClassName(classMirror);
+ return lookupModuleInternal(pkgName);
+ }
}
View
42 ...eylon.eclipse.ui.test/src/com/redhat/ceylon/eclipse/ui/test/ModelAndPhasedUnitsTests.java
@@ -25,9 +25,11 @@
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.junit.Test;
+import com.redhat.ceylon.compiler.loader.AbstractModelLoader;
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.Unit;
import com.redhat.ceylon.eclipse.core.model.CeylonUnit;
import com.redhat.ceylon.eclipse.core.model.CrossProjectSourceFile;
@@ -54,12 +56,12 @@
}
@SuppressWarnings("unchecked")
- private <T extends Unit> T checkDeclarationUnit(String declarationName,
+ private <T extends Unit> T checkDeclarationUnit(Module module, String declarationName,
Class<T> unitClass,
String fullPath,
String relativePath,
String fileName) {
- Declaration declaration = modelLoader.getDeclaration(declarationName, DeclarationType.VALUE);
+ Declaration declaration = modelLoader.getDeclaration(module, declarationName, DeclarationType.VALUE);
Assert.assertNotNull("No declaration for name = " + declarationName, declaration);
Unit unit = declaration.getUnit();
Assert.assertNotNull("Null Unit for declaration : " + declarationName, unit);
@@ -119,20 +121,22 @@ public void checkReferencedProjectPhasedUnits() throws CoreException, NoSuchFiel
CeylonUnit unit;
CeylonUnit unit2;
- unit = checkDeclarationUnit(moduleName + ".CeylonTopLevelClass_" + declarationSuffix,
+ Module module = modelLoader.findModule(moduleName, "1.0.0");
+
+ unit = checkDeclarationUnit(module, moduleName + ".CeylonTopLevelClass_" + declarationSuffix,
unitClass,
root + "/" + moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
"CeylonDeclarations_" + declarationSuffix + ".ceylon");
- unit2 = checkDeclarationUnit(moduleName + ".ceylonTopLevelObject_" + declarationSuffix,
+ unit2 = checkDeclarationUnit(module, moduleName + ".ceylonTopLevelObject_" + declarationSuffix,
unitClass,
root + "/" + moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
"CeylonDeclarations_" + declarationSuffix + ".ceylon");
Assert.assertTrue("Different units " + Arrays.asList(unit, unit2) + " for declarations in the same Unit", unit == unit2);
- unit2 = checkDeclarationUnit(moduleName + ".ceylonTopLevelMethod_" + declarationSuffix,
+ unit2 = checkDeclarationUnit(module, moduleName + ".ceylonTopLevelMethod_" + declarationSuffix,
unitClass,
root + "/" + moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
moduleName + "/CeylonDeclarations_" + declarationSuffix + ".ceylon",
@@ -227,7 +231,9 @@ public void checkJavaLibrayrUnits() throws CoreException {
}
}
- JavaClassFile javaClass = checkDeclarationUnit("java.util.logging.Logger",
+ Module module = modelLoader.findModule(AbstractModelLoader.JAVA_BASE_MODULE_NAME, AbstractModelLoader.JDK_MODULE_VERSION);
+
+ JavaClassFile javaClass = checkDeclarationUnit(module, "java.util.logging.Logger",
JavaClassFile.class,
jarName + "!/" + "java/util/logging/Logger.class",
"java/util/logging/Logger.class",
@@ -261,7 +267,8 @@ public void checkMainProjectJavaCeylonUnits() throws CoreException {
}
}
- JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit("mainModule.JavaCeylonTopLevelClass_Main_Ceylon_Project",
+ Module module = modelLoader.findModule("mainModule", "1.0.0");
+ JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "mainModule.JavaCeylonTopLevelClass_Main_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java",
"mainModule/JavaCeylonTopLevelClass_Main_Ceylon_Project.java",
@@ -271,7 +278,7 @@ public void checkMainProjectJavaCeylonUnits() throws CoreException {
Assert.assertNotNull("Root Folder Resource for Class should not be null :", javaClassCompilationUnit.getRootFolderResource());
Assert.assertNotNull("File Resource should for Class not be null :", javaClassCompilationUnit.getFileResource());
- JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit("mainModule.javaCeylonTopLevelObject_Main_Ceylon_Project",
+ JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module, "mainModule.javaCeylonTopLevelObject_Main_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java",
"mainModule/javaCeylonTopLevelObject_Main_Ceylon_Project_.java",
@@ -281,7 +288,7 @@ public void checkMainProjectJavaCeylonUnits() throws CoreException {
Assert.assertNotNull("Root Folder Resource for Object should not be null :", javaObjectCompilationUnit.getRootFolderResource());
Assert.assertNotNull("File Resource should for Object not be null :", javaObjectCompilationUnit.getFileResource());
- JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit("mainModule.javaCeylonTopLevelMethod_Main_Ceylon_Project_",
+ JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module, "mainModule.javaCeylonTopLevelMethod_Main_Ceylon_Project_",
JavaCompilationUnit.class,
rootPath + "/" + "mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java",
"mainModule/javaCeylonTopLevelMethod_Main_Ceylon_Project_.java",
@@ -311,7 +318,9 @@ public void checkMainProjectPureJavaUnits() throws CoreException {
}
}
- JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit("mainModule.JavaClassInCeylonModule_Main_Ceylon_Project",
+ Module module = modelLoader.findModule("mainModule", "1.0.0");
+
+ JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "mainModule.JavaClassInCeylonModule_Main_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
"mainModule/JavaClassInCeylonModule_Main_Ceylon_Project.java",
@@ -344,8 +353,9 @@ public void checkReferencedProjectJavaCeylonUnits() throws CoreException {
break;
}
}
-
- JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit("referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project",
+ Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");
+
+ JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaCeylonTopLevelClass_Referenced_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
"referencedCeylonProject/JavaCeylonTopLevelClass_Referenced_Ceylon_Project.java",
@@ -355,7 +365,7 @@ public void checkReferencedProjectJavaCeylonUnits() throws CoreException {
Assert.assertNotNull("Root Folder Resource for Class should not be null :", javaClassCompilationUnit.getRootFolderResource());
Assert.assertNotNull("File Resource should for Class not be null :", javaClassCompilationUnit.getFileResource());
- JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit("referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project",
+ JavaCompilationUnit javaObjectCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelObject_Referenced_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
"referencedCeylonProject/javaCeylonTopLevelObject_Referenced_Ceylon_Project_.java",
@@ -365,7 +375,7 @@ public void checkReferencedProjectJavaCeylonUnits() throws CoreException {
Assert.assertNotNull("Root Folder Resource for Object should not be null :", javaObjectCompilationUnit.getRootFolderResource());
Assert.assertNotNull("File Resource should for Object not be null :", javaObjectCompilationUnit.getFileResource());
- JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit("referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_",
+ JavaCompilationUnit javaMethodCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.javaCeylonTopLevelMethod_Referenced_Ceylon_Project_",
JavaCompilationUnit.class,
rootPath + "/" + "referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
"referencedCeylonProject/javaCeylonTopLevelMethod_Referenced_Ceylon_Project_.java",
@@ -395,7 +405,9 @@ public void checkReferencedProjectPureJavaUnits() throws CoreException {
}
}
- JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit("referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project",
+ Module module = modelLoader.findModule("referencedCeylonProject", "1.0.0");
+
+ JavaCompilationUnit javaClassCompilationUnit = checkDeclarationUnit(module, "referencedCeylonProject.JavaClassInCeylonModule_Referenced_Ceylon_Project",
JavaCompilationUnit.class,
rootPath + "/" + "referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
"referencedCeylonProject/JavaClassInCeylonModule_Referenced_Ceylon_Project.java",
View
5 ...redhat.ceylon.eclipse.ui.test/src/com/redhat/ceylon/eclipse/ui/test/ModelLoaderTests.java
@@ -27,11 +27,13 @@
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;
@@ -121,7 +123,8 @@ protected void verifyClassLoading(String ceylon) {
for(Entry<String, Declaration> entry : decls.entrySet()){
String quotedQualifiedName = entry.getKey().substring(1);
- Declaration modelDeclaration = modelLoader.getDeclaration(quotedQualifiedName,
+ 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

0 comments on commit d790e65

Please sign in to comment.
Something went wrong with that request. Please try again.