use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class ExpressionTransformer method transform.
public JCTree transform(Tree.PackageLiteral expr) {
at(expr);
Package pkg = (Package) expr.getImportPath().getModel();
return makePackageLiteralCall(pkg);
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class ExpressionTransformer method makeTopLevelValueOrFunctionDeclarationLiteral.
private JCExpression makeTopLevelValueOrFunctionDeclarationLiteral(Declaration declaration) {
// toplevel method or attribute: we need to fetch them from their module/package
Package pkg = ModelUtil.getPackageContainer(declaration.getContainer());
// get the package
JCExpression packageCall = makePackageLiteralCall(pkg);
// now get the toplevel
String getter = Decl.isMethod(declaration) ? "getFunction" : "getValue";
JCExpression toplevelCall = make().Apply(null, makeSelect(packageCall, getter), List.<JCExpression>of(ceylonLiteral(declaration.getName())));
return toplevelCall;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class CodegenUtil method getJavaNameOfDeclaration.
/**
* <p>Returns the fully qualified name java name of the given declaration,
* for example
* {@code ceylon.language.sum_.sum} or {@code my.package.Outer.Inner}.
* for any toplevel or externally visible Ceylon declaration.</p>
*
* <p>Used by the IDE to support finding/renaming Ceylon declarations
* called from Java.</p>
*/
public static String getJavaNameOfDeclaration(Declaration decl) {
Scope s = decl.getScope();
while (!(s instanceof Package)) {
if (!(s instanceof TypeDeclaration)) {
throw new IllegalArgumentException();
}
s = s.getContainer();
}
String result;
Naming n = new Naming(null, null);
if (decl instanceof TypeDeclaration) {
result = n.makeTypeDeclarationName((TypeDeclaration) decl, DeclNameFlag.QUALIFIED);
// remove initial .
result = result.substring(1);
if (decl.isAnonymous()) {
result += "." + Unfix.get_.toString();
}
} else if (decl instanceof TypedDeclaration) {
if (decl.isToplevel()) {
result = n.getName((TypedDeclaration) decl, Naming.NA_FQ | Naming.NA_WRAPPER | Naming.NA_MEMBER);
// remove initial .
result = result.substring(1);
} else {
Scope container = decl.getContainer();
if (container instanceof TypeDeclaration) {
String qualifier = getJavaNameOfDeclaration((TypeDeclaration) container);
result = qualifier + n.getName((TypedDeclaration) decl, Naming.NA_MEMBER);
} else {
throw new IllegalArgumentException();
}
}
} else {
throw new RuntimeException();
}
return result;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class Decl method getToplevelDeclarationContainer.
public static Declaration getToplevelDeclarationContainer(Declaration decl) {
while (decl != null) {
Scope container = decl.getContainer();
if (container instanceof Package || container instanceof ModuleImportList) {
return decl;
}
decl = getDeclarationScope(container);
}
return decl;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class CeylonDocTool method getObjectFile.
private File getObjectFile(Object modPgkOrDecl) throws IOException {
final File file;
if (modPgkOrDecl instanceof TypeDeclaration) {
TypeDeclaration type = (TypeDeclaration) modPgkOrDecl;
String filename = getFileName(type);
file = new File(getFolder(type), filename);
} else if (modPgkOrDecl instanceof Module) {
String filename = "index.html";
file = new File(getApiOutputFolder((Module) modPgkOrDecl), filename);
} else if (modPgkOrDecl instanceof Package) {
String filename = "index.html";
file = new File(getFolder((Package) modPgkOrDecl), filename);
} else {
throw new RuntimeException(CeylondMessages.msg("error.unexpected", modPgkOrDecl));
}
return file.getCanonicalFile();
}
Aggregations