use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method addLocalDeclarations.
private void addLocalDeclarations(LocalDeclarationContainer container, ClassMirror classContainerMirror, AnnotatedMirror annotatedMirror) {
if (!needsLocalDeclarations())
return;
AnnotationMirror annotation = annotatedMirror.getAnnotation(CEYLON_LOCAL_DECLARATIONS_ANNOTATION);
if (annotation == null)
return;
List<String> values = getAnnotationStringValues(annotation, "value");
String parentClassName = classContainerMirror.getQualifiedName();
Package pkg = ModelUtil.getPackageContainer(container);
Module module = pkg.getModule();
for (String scope : values) {
// assemble the name with the parent
String name;
if (scope.startsWith("::")) {
// interface pulled to toplevel
name = pkg.getNameAsString() + "." + scope.substring(2);
} else {
name = parentClassName;
name += "$" + scope;
}
Declaration innerDecl = convertToDeclaration(module, (Declaration) container, name, DeclarationType.TYPE);
if (innerDecl == null)
throw new ModelResolutionException("Failed to load local type " + name + " for outer type " + container.getQualifiedNameString());
}
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method findLanguageModuleDeclarationForBootstrap.
private Declaration findLanguageModuleDeclarationForBootstrap(String name) {
// make sure we don't return anything for ceylon.language
if (name.equals(CEYLON_LANGUAGE))
return null;
// we're bootstrapping ceylon.language so we need to return the ProducedTypes straight from the model we're compiling
Module languageModule = modules.getLanguageModule();
int lastDot = name.lastIndexOf(".");
if (lastDot == -1)
return null;
String pkgName = name.substring(0, lastDot);
String simpleName = name.substring(lastDot + 1);
// Nothing is a special case with no real decl
if (name.equals("ceylon.language.Nothing"))
return typeFactory.getNothingDeclaration();
// find the right package
Package pkg = languageModule.getDirectPackage(pkgName);
if (pkg != null) {
Declaration member = pkg.getDirectMember(simpleName, null, false);
// if we get a value, we want its type
if (JvmBackendUtil.isValue(member) && ((Value) member).getTypeDeclaration().getName().equals(simpleName)) {
member = ((Value) member).getTypeDeclaration();
}
if (member != null)
return member;
}
throw new ModelResolutionException("Failed to look up given type in language module while bootstrapping: " + name);
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method makeInteropAnnotationConstructor.
public AnnotationProxyMethod makeInteropAnnotationConstructor(LazyInterface iface, AnnotationProxyClass klass, OutputElement oe, Scope scope) {
String ctorName = oe == null ? NamingBase.getJavaBeanName(iface.getName()) : NamingBase.getDisambigAnnoCtorName(iface, oe);
AnnotationProxyMethod ctor = new AnnotationProxyMethod(this, klass, oe);
ctor.setAnnotationTarget(oe);
ctor.setContainer(scope);
ctor.setScope(scope);
if (!(scope instanceof Package)) {
ctor.setStatic(true);
}
ctor.setAnnotation(true);
ctor.setName(ctorName);
ctor.setShared(iface.isShared());
Annotation annotationAnnotation2 = new Annotation();
annotationAnnotation2.setName("annotation");
ctor.getAnnotations().add(annotationAnnotation2);
ctor.setType(((TypeDeclaration) iface).getType());
ctor.setUnit(iface.getUnit());
return ctor;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method getDirectMember.
/**
* Looks for a direct member of type ClassOrInterface. We're not using Class.getDirectMember()
* because it skips object types and we want them.
*/
public static Declaration getDirectMember(Scope container, String name) {
if (name.isEmpty())
return null;
boolean wantsSetter = false;
if (name.startsWith(NamingBase.Suffix.$setter$.name())) {
wantsSetter = true;
name = name.substring(8);
}
if (Character.isDigit(name.charAt(0))) {
// this is a local type we have a different accessor for it
return ((LocalDeclarationContainer) container).getLocalDeclaration(name);
}
// which is too late
if (container instanceof Package) {
// don't use Package.getMembers() as it loads the whole package
Declaration result = container.getDirectMember(name, null, false);
return selectTypeOrSetter(result, wantsSetter);
} else {
// must be a Declaration
for (Declaration member : container.getMembers()) {
// avoid constructors with no name
if (member.getName() == null)
continue;
if (!member.getName().equals(name))
continue;
Declaration result = selectTypeOrSetter(member, wantsSetter);
if (result != null)
return result;
}
}
// not found
return null;
}
use of org.eclipse.ceylon.model.typechecker.model.Package in project ceylon by eclipse.
the class AbstractModelLoader method inspectForStats.
private int inspectForStats(Map<String, Declaration> cache, Map<Package, Stats> loadedByPackage) {
int loaded = 0;
for (Declaration decl : cache.values()) {
if (decl instanceof LazyElement) {
Package pkg = getPackage(decl);
if (pkg == null) {
logVerbose("[Model loader stats: declaration " + decl.getName() + " has no package. Skipping.]");
continue;
}
Stats stats = loadedByPackage.get(pkg);
if (stats == null) {
stats = new Stats();
loadedByPackage.put(pkg, stats);
}
stats.total++;
if (((LazyElement) decl).isLoaded()) {
loaded++;
stats.loaded++;
}
}
}
return loaded;
}
Aggregations