Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable default module.ceylon (review only) #1022

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions Ceylon.g
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ moduleDescriptor returns [ModuleDescriptor moduleDescriptor]
{ $moduleDescriptor = new ModuleDescriptor($MODULE);
$moduleDescriptor.setAnnotationList($annotations.annotationList);
$moduleDescriptor.getCompilerAnnotations().addAll($compilerAnnotations.annotations); }
packagePath
{ $moduleDescriptor.setImportPath($packagePath.importPath); }
(
CHAR_LITERAL
{ $moduleDescriptor.setVersion(new QuotedLiteral($CHAR_LITERAL)); }
|
STRING_LITERAL
{ $moduleDescriptor.setVersion(new QuotedLiteral($STRING_LITERAL)); }
)
(
packagePath
{ $moduleDescriptor.setImportPath($packagePath.importPath); }
(
CHAR_LITERAL
{ $moduleDescriptor.setVersion(new QuotedLiteral($CHAR_LITERAL)); }
|
STRING_LITERAL
{ $moduleDescriptor.setVersion(new QuotedLiteral($STRING_LITERAL)); }
)
)?
importModuleList
{ $moduleDescriptor.setImportModuleList($importModuleList.importModuleList); }
;
Expand Down Expand Up @@ -134,7 +136,9 @@ packageDescriptor returns [PackageDescriptor packageDescriptor]
{ $packageDescriptor = new PackageDescriptor($PACKAGE);
$packageDescriptor.setAnnotationList($annotations.annotationList);
$packageDescriptor.getCompilerAnnotations().addAll($compilerAnnotations.annotations); }
packagePath
(
packagePath
)?
{ $packageDescriptor.setImportPath($packagePath.importPath);
expecting=SEMICOLON; }
SEMICOLON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
import static java.util.Arrays.asList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.antlr.runtime.CommonToken;

import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.ModuleImport;
import com.redhat.ceylon.compiler.typechecker.model.Package;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.ImportPath;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.QuotedLiteral;
import com.redhat.ceylon.compiler.typechecker.tree.Visitor;

/**
Expand Down Expand Up @@ -107,14 +111,25 @@ public void visit(Tree.ModuleDescriptor that) {
if (phase==Phase.SRC_MODULE) {
String version = getVersionString(that.getVersion());
ImportPath importPath = that.getImportPath();
List<String> name = getNameAsList(importPath);

boolean isDefaultModule = importPath == null;
List<String> name = isDefaultModule?
new ArrayList<String>() : getNameAsList(importPath);

if (isDefaultModule) {
importPath = new ImportPath(new CommonToken(6, Module.DEFAULT_MODULE_NAME));
that.setImportPath(importPath);
that.setVersion(new QuotedLiteral(new CommonToken(6, "unversioned")));
}

if (pkg.getNameAsString().isEmpty()) {
that.addError("module descriptor encountered in root source directory");
name.add(Module.DEFAULT_MODULE_NAME);
}
else if (name.isEmpty()) {

if (name.isEmpty()) {
that.addError("missing module name");
}
else if (name.get(0).equals(Module.DEFAULT_MODULE_NAME)) {
else if (!isDefaultModule && name.get(0).equals(Module.DEFAULT_MODULE_NAME)) {
importPath.addError("reserved module name: default");
}
else if (name.size()==1 && name.get(0).equals("ceylon")) {
Expand All @@ -134,7 +149,8 @@ else if (name.get(0).equals("java")||name.get(0).equals("javax")) {
mainModule.setVersion(version);
}
String nameString = formatPath(importPath.getIdentifiers());
if ( !pkg.getNameAsString().equals(nameString) ) {
if ( (isDefaultModule && !(Module.DEFAULT_MODULE_NAME.equals(nameString) && "".equals(pkg.getNameAsString())))
|| (!isDefaultModule && !pkg.getNameAsString().equals(nameString)) ) {
importPath
.addError("module name does not match descriptor location: " +
nameString + " should be " + pkg.getNameAsString(),
Expand Down Expand Up @@ -167,11 +183,22 @@ public void visit(Tree.PackageDescriptor that) {
super.visit(that);
if (phase==Phase.REMAINING) {
Tree.ImportPath importPath = that.getImportPath();
List<String> name = getNameAsList(importPath);

boolean isDefaultPackage = importPath == null;
List<String> name = isDefaultPackage?
new ArrayList<String>() : getNameAsList(importPath);

if (isDefaultPackage) {
importPath = new ImportPath(new CommonToken(6, ""));
that.setImportPath(importPath);
}

if (pkg.getNameAsString().isEmpty()) {
that.addError("package descriptor encountered in root source directory");
pkg.setName(Arrays.asList(""));
name.add("");
}
else if (name.isEmpty()) {

if (!isDefaultPackage && name.isEmpty()) {
that.addError("missing package name");
}
else if (name.get(0).equals(Module.DEFAULT_MODULE_NAME)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Scope getScope() {
}

public String getNameAsString() {
if (nameAsString == null){
if (nameAsString == null || nameAsString.isEmpty()){
nameAsString = formatPath(name);
}
return nameAsString;
Expand Down