use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.
the class MethodOrValueReferenceVisitor method capture.
private void capture(Tree.Primary that, boolean methodSpecifier) {
if (that instanceof Tree.MemberOrTypeExpression) {
final Declaration decl = ((Tree.MemberOrTypeExpression) that).getDeclaration();
if (!(decl instanceof TypedDeclaration)) {
return;
}
TypedDeclaration d = (TypedDeclaration) decl;
if (Decl.equal(d, declaration) || (d.isNativeHeader() && d.getOverloads().contains(declaration))) {
d = declaration;
if (Decl.isParameter(d)) {
// a reference from a default argument
// expression of the same parameter
// list does not capture a parameter
Scope s = that.getScope();
boolean sameScope = d.getContainer().equals(s) || (s instanceof Declaration && (Decl.isParameter((Declaration) s) || (s instanceof Value && !((Value) s).isTransient())) && d.getContainer().equals(s.getScope()));
if (!sameScope || methodSpecifier || inLazySpecifierExpression) {
((FunctionOrValue) d).setCaptured(true);
}
// Accessing another instance's member passed to a class initializer
if (that instanceof Tree.QualifiedMemberExpression) {
if (d instanceof TypedDeclaration && ((TypedDeclaration) d).getOtherInstanceAccess()) {
((FunctionOrValue) d).setCaptured(true);
}
}
if (isCapturableMplParameter(d)) {
((FunctionOrValue) d).setCaptured(true);
}
} else if (Decl.isValue(d) || Decl.isGetter(d)) {
Value v = (Value) d;
v.setCaptured(true);
if (Decl.isObjectValue(d)) {
v.setSelfCaptured(isSelfCaptured(that, d));
}
if (v.getSetter() != null) {
v.getSetter().setCaptured(true);
}
} else if (d instanceof Function) {
((Function) d).setCaptured(true);
}
/*if (d.isVariable() && !d.isClassMember() && !d.isToplevel()) {
that.addError("access to variable local from capturing scope: " + declaration.getName());
}*/
}
}
}
use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.
the class ClassDoc method writeListOnSummary.
private void writeListOnSummary(String cssClass, String title, List<?> types) throws IOException {
if (!isEmpty(types)) {
open("div class='" + cssClass + " section'");
around("span class='title'", title);
boolean first = true;
for (Object type : types) {
if (!first) {
write(", ");
} else {
first = false;
}
if (type instanceof TypedDeclaration) {
TypedDeclaration decl = (TypedDeclaration) type;
linkRenderer().to(decl).useScope(klass).write();
} else if (type instanceof ClassOrInterface) {
ClassOrInterface coi = (ClassOrInterface) type;
linkRenderer().to(coi).useScope(klass).printAbbreviated(!isAbbreviatedType(coi)).write();
} else {
Type pt = (Type) type;
linkRenderer().to(pt).useScope(klass).printAbbreviated(!isAbbreviatedType(pt.getDeclaration())).write();
}
}
close("div");
}
}
use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.
the class Naming method getMethodNameInternal.
private static String getMethodNameInternal(TypedDeclaration decl) {
String name;
if (decl.isClassOrInterfaceMember() && decl instanceof Function) {
Declaration refined = decl.getRefinedDeclaration();
if (refined instanceof JavaMethod) {
return ((JavaMethod) refined).getRealName();
}
name = quoteMethodNameIfProperty((Function) decl);
} else {
name = decl.getName();
}
if (decl.isClassMember() && "readResolve".equals(name) && Strategy.addReadResolve((Class) decl.getContainer())) {
return quote(name);
}
if (decl.isClassMember() && "writeReplace".equals(name) && Strategy.useSerializationProxy((Class) decl.getContainer())) {
return quote(name);
}
// ERASURE
if (QUOTABLE_METHOD_NAMES.contains(name)) {
return quote(name);
} else {
return quoteIfJavaKeyword(name);
}
}
use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.
the class Naming method makeDefaultedParamMethod.
JCExpression makeDefaultedParamMethod(JCExpression qualifier, Parameter param) {
// TODO Can we merge this into makeName(..., NA_DPM) ?
if (!Strategy.hasDefaultParameterValueMethod(param)) {
throw new BugException();
}
Declaration decl = param.getDeclaration();
String methodName = getDefaultedParamMethodName(decl, param);
if (Strategy.defaultParameterMethodOnSelf(param.getModel())) {
// method not within interface
Declaration container = param.getDeclaration().getRefinedDeclaration();
if (!container.isToplevel()) {
container = (Declaration) container.getContainer();
}
JCExpression className = makeTypeDeclarationExpression(qualifier, (TypeDeclaration) container, DeclNameFlag.COMPANION);
return makeSelect(className, methodName);
} else if (Strategy.defaultParameterMethodOnOuter(param.getModel())) {
return makeQuotedQualIdent(qualifier, methodName);
} else if (Strategy.defaultParameterMethodStatic(param.getModel())) {
// top level method or class
if (qualifier != null) {
throw new BugException();
}
Declaration container = param.getDeclaration().getRefinedDeclaration();
if (!container.isToplevel()) {
container = (Declaration) container.getContainer();
}
if (container instanceof TypedDeclaration) {
return makeSelect(makeName((TypedDeclaration) container, NA_FQ | NA_WRAPPER), methodName);
} else {
return makeSelect(gen().makeJavaType(((TypeDeclaration) container).getType(), AbstractTransformer.JT_RAW), methodName);
}
} else {
// inner or local class or method, or method in an interface
return makeQuotedQualIdent(qualifier, methodName);
}
}
use of com.redhat.ceylon.model.typechecker.model.TypedDeclaration in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method getParameterTypeForValueType.
protected Type getParameterTypeForValueType(Reference producedReference, Parameter param) {
// we need to find the interface for this method
Type paramType = param.getModel().getReference().getFullType().getType();
Scope paramContainer = param.getModel().getContainer();
if (paramContainer instanceof TypedDeclaration) {
TypedDeclaration method = (TypedDeclaration) paramContainer;
if (method.getContainer() instanceof TypeDeclaration && !(method.getContainer() instanceof Constructor)) {
TypeDeclaration container = (TypeDeclaration) method.getContainer();
Type qualifyingType = producedReference.getQualifyingType();
Type supertype = qualifyingType.getSupertype(container);
return paramType.substitute(supertype);
}
}
return paramType;
}
Aggregations