use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class ClassOrPackageDoc method doc.
protected final void doc(String name, Declaration d) throws IOException {
String declarationName = Util.getDeclarationName(d);
boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
// put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
open("tr");
open("td id='" + name + "' nowrap");
writeIcon(d);
if (!(d instanceof Constructor)) {
around("code class='decl-label'", name);
close("td");
open("td");
}
writeLinkOneSelf(d);
if (alias) {
writeTagged(d);
writeAlias(d);
} else {
writeLinkSource(d);
writeTagged(d);
if (d instanceof Functional) {
writeParameterLinksIfRequired((Functional) d);
}
open("code class='signature'");
around("span class='modifiers'", getModifiers(d));
write(" ");
if (!ModelUtil.isConstructor(d)) {
if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
around("span class='void'", "void");
} else if (d instanceof TypedDeclaration) {
linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
} else {
linkRenderer().to(d).useScope(d).write();
}
}
write(" ");
open("span class='identifier'");
write(name);
close("span");
if (isConstantValue(d)) {
writeConstantValue((Value) d);
}
if (d instanceof Generic) {
Generic f = (Generic) d;
writeTypeParameters(f.getTypeParameters(), d);
}
if (d instanceof Functional) {
writeParameterList((Functional) d, d);
}
if (d instanceof Generic) {
Generic f = (Generic) d;
writeTypeParametersConstraints(f.getTypeParameters(), d);
}
if (d instanceof Value) {
Setter setter = ((Value) d).getSetter();
if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
tool.warningSetterDoc(d.getQualifiedNameString(), d);
}
}
close("code");
writeDescription(d);
}
close("td");
close("tr");
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class IndexApiDoc method collectDeclarations.
private List<Declaration> collectDeclarations() {
List<Declaration> declarations = new ArrayList<Declaration>();
for (Package pkg : tool.getPackages(module)) {
if (tool.shouldInclude(pkg)) {
List<Declaration> members = pkg.getMembers();
for (Declaration member : members) {
if (tool.shouldInclude(member)) {
if (member instanceof Value && ((Value) member).getTypeDeclaration().isAnonymous()) {
continue;
}
declarations.add(member);
}
}
}
}
Collections.sort(declarations, ReferenceableComparatorByName.INSTANCE);
return declarations;
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class ClassDoc method loadMembers.
private void loadMembers() {
constructors = new TreeMap<String, Declaration>();
methods = new TreeMap<String, Function>();
attributes = new TreeMap<String, TypedDeclaration>();
innerInterfaces = new TreeMap<String, Interface>();
innerClasses = new TreeMap<String, Class>();
innerExceptions = new TreeMap<String, Class>();
innerAliases = new TreeMap<String, TypeAlias>();
superClasses = getAncestors(klass);
superInterfaces = getSuperInterfaces(klass);
for (Declaration m : klass.getMembers()) {
if (tool.shouldInclude(m)) {
if (ModelUtil.isConstructor(m)) {
addTo(constructors, m);
} else if (m instanceof Value) {
addTo(attributes, (Value) m);
} else if (m instanceof Function) {
addTo(methods, (Function) m);
} else if (m instanceof Interface) {
addTo(innerInterfaces, (Interface) m);
} else if (m instanceof Class) {
Class c = (Class) m;
if (Util.isThrowable(c)) {
addTo(innerExceptions, c);
} else {
addTo(innerClasses, c);
}
} else if (m instanceof TypeAlias) {
addTo(innerAliases, (TypeAlias) m);
}
}
}
Collections.sort(superInterfaces, ReferenceableComparatorByName.INSTANCE);
loadInheritedMembers(attributeSpecification, superClasses, superclassInheritedMembers);
loadInheritedMembers(methodSpecification, superClasses, superclassInheritedMembers);
loadInheritedMembers(attributeSpecification, superInterfaces, interfaceInheritedMembers);
loadInheritedMembers(methodSpecification, superInterfaces, interfaceInheritedMembers);
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class CeylonTransformer method transformAttribute.
public List<JCTree> transformAttribute(TypedDeclaration declarationModel, String attrName, String attrClassName, final Tree.Declaration annotated, final Tree.Block block, final Tree.SpecifierOrInitializerExpression expression, final Tree.TypedDeclaration decl, final Tree.AttributeSetterDefinition setterDecl) {
// For everything else generate a getter/setter method
AttributeDefinitionBuilder builder = AttributeDefinitionBuilder.wrapped(this, attrClassName, null, attrName, declarationModel, declarationModel.isToplevel()).is(Flags.PUBLIC, declarationModel.isShared());
final JCExpression initialValue;
final HasErrorException expressionError;
if (expression != null) {
expressionError = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
if (expressionError != null) {
initialValue = make().Erroneous();
} else {
initialValue = transformValueInit(declarationModel, attrName, expression);
}
} else {
expressionError = null;
initialValue = transformValueInit(declarationModel, attrName, expression);
}
// For captured local variable Values, use a VariableBox
if (Decl.isBoxedVariable(declarationModel)) {
if (expressionError != null) {
return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
} else {
return List.<JCTree>of(makeVariableBoxDecl(initialValue, declarationModel));
}
}
// For late-bound getters we only generate a declaration
if (block == null && expression == null && !Decl.isToplevel(declarationModel)) {
JCExpression typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
JCTree.JCVariableDecl var = makeVar(attrClassName, typeExpr, null);
return List.<JCTree>of(var);
}
// Set the local declarations annotation
if (decl != null) {
List<JCAnnotation> scopeAnnotations;
if (Decl.isToplevel(declarationModel) && setterDecl != null) {
scopeAnnotations = makeAtLocalDeclarations(decl, setterDecl);
} else {
scopeAnnotations = makeAtLocalDeclarations(decl);
}
builder.classAnnotations(scopeAnnotations);
} else if (block != null) {
List<JCAnnotation> scopeAnnotations = makeAtLocalDeclarations(block);
builder.classAnnotations(scopeAnnotations);
}
// Remember the setter class if we generate a getter
if (Decl.isGetter(declarationModel) && declarationModel.isVariable() && Decl.isLocal(declarationModel)) {
// we must have a setter class
Setter setter = ((Value) declarationModel).getSetter();
if (setter != null) {
String setterClassName = Naming.getAttrClassName(setter, 0);
JCExpression setterClassNameExpr = naming.makeUnquotedIdent(setterClassName);
builder.setterClass(makeSelect(setterClassNameExpr, "class"));
}
}
if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
// For local setters
JCBlock setterBlock = makeSetterBlock(declarationModel, block, expression);
builder.setterBlock(setterBlock);
builder.skipGetter();
if (Decl.isLocal(decl)) {
// we need to find back the Setter model for local setters, because
// in transformAttribute(Tree.TypedDeclaration decl, Tree.AttributeSetterDefinition setterDecl)
// we turn the declaration model from the Setter to its single parameter
Setter setter = (Setter) declarationModel.getContainer();
String getterClassName = Naming.getAttrClassName(setter.getGetter(), 0);
JCExpression getterClassNameExpr = naming.makeUnquotedIdent(getterClassName);
builder.isSetter(makeSelect(getterClassNameExpr, "class"));
}
} else {
if (Decl.isValue(declarationModel)) {
// For local and toplevel value attributes
if (!declarationModel.isVariable() && !declarationModel.isLate()) {
builder.immutable();
}
} else {
// For local and toplevel getters
boolean prevSyntheticClassBody;
if (Decl.isLocal(declarationModel)) {
prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(true);
} else {
prevSyntheticClassBody = expressionGen().isWithinSyntheticClassBody();
}
JCBlock getterBlock = makeGetterBlock(declarationModel, block, expression);
prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
builder.getterBlock(getterBlock);
if (Decl.isLocal(declarationModel)) {
// For local getters
builder.immutable();
} else {
// For toplevel getters
if (setterDecl != null) {
JCBlock setterBlock = makeSetterBlock(setterDecl.getDeclarationModel(), setterDecl.getBlock(), setterDecl.getSpecifierExpression());
builder.setterBlock(setterBlock);
//builder.userAnnotationsSetter(expressionGen().transformAnnotations(true, OutputElement.METHOD, setterDecl));
builder.userAnnotationsSetter(expressionGen().transformAnnotations(OutputElement.SETTER, setterDecl));
} else {
builder.immutable();
}
}
}
}
if (annotated != null) {
builder.userAnnotations(expressionGen().transformAnnotations(OutputElement.GETTER, annotated));
}
if (Decl.isLocal(declarationModel)) {
if (expressionError != null) {
return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
}
builder.classAnnotations(makeAtLocalDeclaration(declarationModel.getQualifier(), false));
if (initialValue != null)
builder.valueConstructor();
JCExpression typeExpr;
if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
typeExpr = makeQuotedIdent(attrClassName);
} else {
typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
}
return builder.build().append(makeLocalIdentityInstance(typeExpr, attrClassName, attrClassName, declarationModel.isShared(), initialValue));
} else {
if (expressionError != null) {
builder.initialValueError(expressionError);
} else if (initialValue != null) {
builder.initialValue(initialValue);
}
builder.is(Flags.STATIC, true);
return builder.build();
}
}
use of com.redhat.ceylon.model.typechecker.model.Value in project ceylon-compiler by ceylon.
the class AnnotationModelVisitor method visit.
@Override
public void visit(Tree.BaseMemberExpression bme) {
if (annotationConstructor != null) {
Declaration declaration = bme.getDeclaration();
if (checkingInvocationPrimary && isAnnotationConstructor(bme.getDeclaration())) {
Function ctor = (Function) bme.getDeclaration();
instantiation.setPrimary(ctor);
if (ctor.getAnnotationConstructor() != null) {
instantiation.getConstructorParameters().addAll(((AnnotationInvocation) ctor.getAnnotationConstructor()).getConstructorParameters());
}
} else if (checkingArguments || checkingDefaults) {
if (declaration instanceof Value && ((Value) declaration).isParameter()) {
Value constructorParameter = (Value) declaration;
ParameterAnnotationTerm a = new ParameterAnnotationTerm();
a.setSpread(spread);
// XXX Is this right?
a.setSourceParameter(constructorParameter.getInitializerParameter());
this.term = a;
} else if (isBooleanTrue(declaration)) {
LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(true);
appendLiteralArgument(bme, argument);
} else if (isBooleanFalse(declaration)) {
LiteralAnnotationTerm argument = new BooleanLiteralAnnotationTerm(false);
appendLiteralArgument(bme, argument);
} else if (bme.getUnit().isEmptyType(bme.getTypeModel()) && bme.getUnit().isIterableType(bme.getTypeModel()) && elements == null) {
// If we're dealing with an iterable, empty means empty collection, not object
endCollection(startCollection(bme), bme);
} else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
LiteralAnnotationTerm argument = new ObjectLiteralAnnotationTerm(bme.getTypeModel());
appendLiteralArgument(bme, argument);
} else {
bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
}
} else {
bme.addError("compiler bug: unsupported base member expression in annotation constructor", Backend.Java);
}
}
}
Aggregations