Skip to content

Commit

Permalink
Check that any native annotations on an import don't conflict with …
Browse files Browse the repository at this point in the history
…the imported module itself (ceylon/ceylon-spec#499)
  • Loading branch information
quintesse committed May 8, 2015
1 parent b46d3df commit 4b30de7
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/com/redhat/ceylon/compiler/java/tools/LanguageCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package com.redhat.ceylon.compiler.java.tools;

import static com.redhat.ceylon.compiler.typechecker.tree.Util.formatPath;
import static com.redhat.ceylon.compiler.typechecker.tree.Util.getNativeBackend;
import static com.redhat.ceylon.compiler.typechecker.tree.Util.isForBackend;

import java.io.File;
Expand Down Expand Up @@ -85,6 +86,7 @@
import com.redhat.ceylon.compiler.typechecker.parser.RecognitionError;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.CompilationUnit;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportModule;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor;
import com.redhat.ceylon.compiler.typechecker.util.ModuleManagerFactory;
import com.redhat.ceylon.compiler.typechecker.util.NewlineFixingStringStream;
Expand Down Expand Up @@ -491,14 +493,15 @@ public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects)
}

private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
checkInvalidNativePUs();
checkInvalidNativeModules();
compilerDelegate.visitModules(phasedUnits);
Modules modules = ceylonContext.getModules();
// now make sure the phase units have their modules and packages set correctly
for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
Package pkg = pu.getPackage();
loadModuleFromSource(pkg, modules, moduleTrees, trees);
}
checkInvalidNativeImports();
// also make sure we have packages and modules set up for every Java file we compile
for(JCCompilationUnit cu : trees){
// skip Ceylon CUs
Expand Down Expand Up @@ -527,7 +530,7 @@ private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> tree
return trees;
}

private void checkInvalidNativePUs() {
private void checkInvalidNativeModules() {
for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
ModuleDescriptor md = pu.findModuleDescriptor();
if (md != null && !isForBackend(md.getAnnotationList(), Backend.Java, md.getUnit())) {
Expand All @@ -536,6 +539,24 @@ private void checkInvalidNativePUs() {
}
}

private void checkInvalidNativeImports() {
for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
ModuleDescriptor md = pu.findModuleDescriptor();
if (md != null) {
for (ImportModule im : md.getImportModuleList().getImportModules()) {
String be = getNativeBackend(im.getAnnotationList(), im.getUnit());
if (im.getImportPath() != null) {
Module m = (Module)im.getImportPath().getModel();
if (be != null && m.isNative() && !be.equals(m.getNative())) {
im.addError("native backend name conflicts with imported module: '\"" +
be + "\"' is not '\"" + m.getNative() + "\"'");
}
}
}
}
}
}

private void loadModuleFromSource(Package pkg, Modules modules, LinkedList<JCCompilationUnit> moduleTrees, List<JCCompilationUnit> parsedTrees) {
// skip it if we already resolved the package
if(pkg.getModule() != null){
Expand Down

0 comments on commit 4b30de7

Please sign in to comment.