use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method makeThis.
private final JCVariableDecl makeThis() {
// first append $this
JCExpression defaultedParameterInstance;
// TODO Fix how we figure out the thisType, because it's doesn't
// handle type parameters correctly
// we used to use thisType = gen.getThisType(getPrimaryDeclaration());
final JCExpression thisType;
Reference target = ((Tree.MemberOrTypeExpression) getPrimary()).getTarget();
if (getPrimary() instanceof Tree.BaseMemberExpression && !gen.expressionGen().isWithinSyntheticClassBody()) {
if (Decl.withinClassOrInterface(getPrimaryDeclaration())) {
// a member method
thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
defaultedParameterInstance = gen.naming.makeThis();
} else {
// a local or toplevel function
thisType = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), Naming.NA_WRAPPER);
defaultedParameterInstance = gen.naming.makeName((TypedDeclaration) getPrimaryDeclaration(), Naming.NA_MEMBER);
}
} else if (getPrimary() instanceof Tree.BaseTypeExpression || getPrimary() instanceof Tree.QualifiedTypeExpression) {
TypeDeclaration declaration = (TypeDeclaration) ((Tree.MemberOrTypeExpression) getPrimary()).getDeclaration();
thisType = gen.makeJavaType(declaration.getType(), JT_COMPANION);
defaultedParameterInstance = gen.make().NewClass(null, null, gen.makeJavaType(declaration.getType(), JT_COMPANION), List.<JCExpression>nil(), null);
} else {
if (isOnValueType()) {
thisType = gen.makeJavaType(target.getQualifyingType());
} else {
thisType = gen.makeJavaType(target.getQualifyingType(), JT_NO_PRIMITIVES);
}
defaultedParameterInstance = callVarName.makeIdent();
}
JCVariableDecl thisDecl = gen.makeVar(varBaseName.suffixedBy(Suffix.$argthis$), thisType, defaultedParameterInstance);
return thisDecl;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class MethodDefinitionBuilder method isParamTypeLocalToMethod.
private boolean isParamTypeLocalToMethod(Parameter parameter, Type nonWideningType) {
// error recovery
if (nonWideningType == null)
return false;
if (parameter.getModel().getTypeErased()) {
return false;
}
Declaration method = parameter.getDeclaration();
TypeDeclaration paramTypeDecl = nonWideningType.getDeclaration();
if (paramTypeDecl instanceof TypeParameter && Decl.equalScopeDecl(paramTypeDecl.getContainer(), method)) {
return false;
}
Scope scope = paramTypeDecl.getContainer();
while (scope != null && !(scope instanceof Package)) {
if (Decl.equalScopeDecl(scope, method)) {
return true;
}
scope = scope.getContainer();
}
return false;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class TypeParserTests method testEmptyAbbrev.
@Test
public void testEmptyAbbrev() {
Type type = new TypeParser(MockLoader.instance).decodeType("[]", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Interface);
Assert.assertEquals("ceylon.language::Empty", declaration.getQualifiedNameString());
Assert.assertNull(type.getQualifyingType());
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class TypeParserTests method testTuple1OrMoreAbbrev.
@Test
public void testTuple1OrMoreAbbrev() {
Type type = new TypeParser(MockLoader.instance).decodeType("[a,b*]", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Class);
Assert.assertEquals("ceylon.language::Tuple", declaration.getQualifiedNameString());
Assert.assertEquals("[a, b*]", type.asString());
Assert.assertNull(type.getQualifyingType());
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class TypeParserTests method testTypeCallPackage.
@Test
public void testTypeCallPackage() {
Type type = new TypeParser(MockLoader.instance).decodeType("pkg::package", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Class);
Assert.assertEquals("pkg::package", printType(type));
Assert.assertNull(type.getQualifyingType());
}
Aggregations