use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class BmeGenerator method generateStaticReference.
static void generateStaticReference(Node n, Declaration d, GenerateJsVisitor gen) {
Declaration orig = d instanceof TypedDeclaration ? ((TypedDeclaration) d).getOriginalDeclaration() : d;
ClassOrInterface coi = (ClassOrInterface) (orig == null ? d : orig).getContainer();
gen.qualify(n, coi);
gen.out(gen.getNames().name(coi), ".$st$.", gen.getNames().name(d));
if (d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
gen.out("()");
}
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class CeylonEnter method typeCheck.
private void typeCheck() {
final java.util.List<PhasedUnit> listOfUnits = phasedUnits.getPhasedUnits();
Module jdk = modelLoader.getJDKBaseModule();
Package javaLangPackage = jdk.getPackage("java.lang");
for (PhasedUnit pu : listOfUnits) {
pu.getUnit().setJavaLangPackage(javaLangPackage);
}
// Delegate to an external typechecker (e.g. the IDE build)
compilerDelegate.typeCheck(listOfUnits);
if (sp != null) {
sp.clearLine();
sp.log("Preparation phase");
}
int size = listOfUnits.size();
int i = 1;
// This phase is proper to the Java backend
ForcedCaptureVisitor fcv = new ForcedCaptureVisitor();
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(1, i++, size, pu);
Unit unit = pu.getUnit();
final CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(fcv);
for (Declaration d : unit.getDeclarations()) {
if (d instanceof TypedDeclaration && !(d instanceof Setter) && // skip already captured members
!d.isCaptured()) {
compilationUnit.visit(new MethodOrValueReferenceVisitor((TypedDeclaration) d));
}
}
}
EeVisitor eeVisitor = gen.getEeVisitor();
UnsupportedVisitor uv = new UnsupportedVisitor(eeVisitor);
JvmMissingNativeVisitor mnv = new JvmMissingNativeVisitor();
BoxingDeclarationVisitor boxingDeclarationVisitor = new CompilerBoxingDeclarationVisitor(gen);
BoxingVisitor boxingVisitor = new CompilerBoxingVisitor(gen);
SmallDeclarationVisitor smallDeclarationVisitor = new SmallDeclarationVisitor();
SmallVisitor smallVisitor = new SmallVisitor();
DeferredVisitor deferredVisitor = new DeferredVisitor();
AnnotationDeclarationVisitor adv = new AnnotationDeclarationVisitor(gen);
AnnotationModelVisitor amv = new AnnotationModelVisitor(gen);
DefiniteAssignmentVisitor dav = new DefiniteAssignmentVisitor();
TypeParameterCaptureVisitor tpCaptureVisitor = new TypeParameterCaptureVisitor();
InterfaceVisitor localInterfaceVisitor = new InterfaceVisitor();
// Extra phases for the compiler
// boxing visitor depends on boxing decl
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(2, i++, size, pu);
pu.getCompilationUnit().visit(eeVisitor);
pu.getCompilationUnit().visit(uv);
pu.getCompilationUnit().visit(adv);
}
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(3, i++, size, pu);
pu.getCompilationUnit().visit(boxingDeclarationVisitor);
pu.getCompilationUnit().visit(smallDeclarationVisitor);
pu.getCompilationUnit().visit(amv);
}
i = 1;
// the others can run at the same time
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(4, i++, size, pu);
CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(mnv);
compilationUnit.visit(boxingVisitor);
compilationUnit.visit(smallVisitor);
compilationUnit.visit(deferredVisitor);
compilationUnit.visit(dav);
compilationUnit.visit(tpCaptureVisitor);
compilationUnit.visit(localInterfaceVisitor);
}
i = 1;
for (PhasedUnit pu : listOfUnits) {
if (sp != null)
progressPreparation(5, i++, size, pu);
CompilationUnit compilationUnit = pu.getCompilationUnit();
compilationUnit.visit(new WarningSuppressionVisitor<Warning>(Warning.class, pu.getSuppressedWarnings()));
}
collectTreeErrors(true, true);
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.
private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
@SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
// we start at the package
Scope scope = pkg;
for (String name : path) {
scope = (Scope) getDirectMember(scope, name);
}
String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
if (companionClassName == null || companionClassName.isEmpty()) {
declaration.setCompanionClassNeeded(false);
return scope;
}
ClassMirror container;
Scope javaClassScope;
if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
javaClassScope = scope.getContainer();
else
javaClassScope = scope;
if (javaClassScope instanceof LazyInterface) {
container = ((LazyInterface) javaClassScope).companionClass;
} else if (javaClassScope instanceof LazyClass) {
container = ((LazyClass) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyValue) {
container = ((LazyValue) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyFunction) {
container = ((LazyFunction) javaClassScope).classMirror;
} else if (javaClassScope instanceof SetterWithLocalDeclarations) {
container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
} else {
throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
}
String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
if (companionClassMirror == null)
throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
((LazyInterface) declaration).companionClass = companionClassMirror;
return scope;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class JvmBackendUtil method getTopmostRefinedDeclaration.
public static Declaration getTopmostRefinedDeclaration(Declaration decl, Map<Function, Function> methodOverrides) {
if (decl instanceof FunctionOrValue && ((FunctionOrValue) decl).isParameter() && decl.getContainer() instanceof Class) {
// Parameters in a refined class are not considered refinements themselves
// We have in find the refined attribute
Class c = (Class) decl.getContainer();
boolean isAlias = c.isAlias();
boolean isActual = c.isActual();
// boxing and stuff
if (isAlias || isActual) {
Functional ctor = null;
int index = c.getParameterList().getParameters().indexOf(findParamForDecl(((TypedDeclaration) decl)));
// Note(Stef): not entirely sure about that one, what about aliases of actual classes?
while ((isAlias && c.isAlias()) || (isActual && c.isActual())) {
ctor = (isAlias && c.isAlias()) ? (Functional) ((ClassAlias) c).getConstructor() : c;
Type et = c.getExtendedType();
c = et != null && et.isClass() ? (Class) et.getDeclaration() : null;
// handle compile errors
if (c == null)
return null;
}
if (isActual) {
ctor = c;
}
// be safe
if (ctor == null || ctor.getParameterLists() == null || ctor.getParameterLists().isEmpty() || ctor.getFirstParameterList() == null || ctor.getFirstParameterList().getParameters() == null || ctor.getFirstParameterList().getParameters().size() <= index)
return null;
decl = ctor.getFirstParameterList().getParameters().get(index).getModel();
}
if (decl.isShared()) {
Declaration refinedDecl = c.getRefinedMember(decl.getName(), getSignature(decl), isVariadic(decl));
if (refinedDecl != null && !ModelUtil.equal(refinedDecl, decl)) {
return getTopmostRefinedDeclaration(refinedDecl, methodOverrides);
}
}
return decl;
} else if (decl instanceof FunctionOrValue && // a parameter
((FunctionOrValue) decl).isParameter() && (// that's not parameter of a functional parameter
(decl.getContainer() instanceof Function && !(((Function) decl.getContainer()).isParameter())) || // or is a parameter in a specification
decl.getContainer() instanceof Specification || (decl.getContainer() instanceof Function && ((Function) decl.getContainer()).isParameter() && createMethod((Function) decl.getContainer())))) {
// or is a class functional parameter
// Parameters in a refined method are not considered refinements themselves
// so we have to look up the corresponding parameter in the container's refined declaration
Functional func = (Functional) getParameterized((FunctionOrValue) decl);
if (func == null)
return decl;
Declaration kk = getTopmostRefinedDeclaration((Declaration) func, methodOverrides);
// error recovery
if (kk instanceof Functional == false)
return decl;
Functional refinedFunc = (Functional) kk;
// shortcut if the functional doesn't override anything
if (ModelUtil.equal((Declaration) refinedFunc, (Declaration) func)) {
return decl;
}
if (func.getParameterLists().size() != refinedFunc.getParameterLists().size()) {
// invalid input
return decl;
}
for (int ii = 0; ii < func.getParameterLists().size(); ii++) {
if (func.getParameterLists().get(ii).getParameters().size() != refinedFunc.getParameterLists().get(ii).getParameters().size()) {
// invalid input
return decl;
}
// find the index of the parameter in the declaration
int index = 0;
for (Parameter px : func.getParameterLists().get(ii).getParameters()) {
if (px.getModel() == null || px.getModel().equals(decl)) {
// And return the corresponding parameter from the refined declaration
return refinedFunc.getParameterLists().get(ii).getParameters().get(index).getModel();
}
index++;
}
continue;
}
} else if (methodOverrides != null && decl instanceof Function && ModelUtil.equal(decl.getRefinedDeclaration(), decl) && decl.getContainer() instanceof Specification && ((Specification) decl.getContainer()).getDeclaration() instanceof Function && ((Function) ((Specification) decl.getContainer()).getDeclaration()).isShortcutRefinement() && // hash lookup we do next to make sure it is really one of those cases
methodOverrides.containsKey(decl)) {
// special case for class X() extends T(){ m = function() => e; } which we inline
decl = methodOverrides.get(decl);
}
Declaration refinedDecl = decl.getRefinedDeclaration();
if (refinedDecl != null && !ModelUtil.equal(refinedDecl, decl))
return getTopmostRefinedDeclaration(refinedDecl);
return decl;
}
use of org.eclipse.ceylon.model.typechecker.model.TypedDeclaration in project ceylon by eclipse.
the class NamingBase method getSetterName.
public static String getSetterName(Declaration decl) {
// use the refined decl except when the current declaration is variable and the refined isn't
Declaration refinedDecl = decl.getRefinedDeclaration();
if (isValue(decl) && isValue(refinedDecl)) {
Value v = (Value) decl;
Value rv = (Value) refinedDecl;
if (!v.isVariable() || rv.isVariable()) {
decl = refinedDecl;
}
} else {
decl = refinedDecl;
}
if (decl instanceof FieldValue) {
return ((FieldValue) decl).getRealName();
}
if (decl instanceof JavaBeanValue && // one it will not. This is also used for late setters...
((JavaBeanValue) decl).getSetterName() != null) {
return ((JavaBeanValue) decl).getSetterName();
} else if (decl.isClassOrInterfaceMember() && !isLocalToInitializer(decl) || decl.isStatic()) {
String setterName = getSetterName(decl.getName());
if (decl.isMember() && !decl.isShared()) {
setterName = suffixName(Suffix.$priv$, setterName);
}
return setterName;
} else if (decl instanceof TypedDeclaration && isBoxedVariable((TypedDeclaration) decl)) {
return name(Unfix.ref);
} else {
return name(Unfix.set_);
}
}
Aggregations