use of com.redhat.ceylon.model.typechecker.model.Declaration 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.Declaration in project ceylon-compiler by ceylon.
the class CeylonDocTool method collectSubclasses.
private void collectSubclasses() throws IOException {
for (Module module : modules) {
for (Package pkg : getPackages(module)) {
for (Declaration decl : pkg.getMembers()) {
if (!shouldInclude(decl)) {
continue;
}
if (decl instanceof ClassOrInterface) {
ClassOrInterface c = (ClassOrInterface) decl;
// subclasses map
if (c instanceof Class) {
Type superclass = c.getExtendedType();
if (superclass != null) {
TypeDeclaration superdec = superclass.getDeclaration();
if (subclasses.get(superdec) == null) {
subclasses.put(superdec, new ArrayList<Class>());
}
subclasses.get(superdec).add((Class) c);
}
}
List<Type> satisfiedTypes = new ArrayList<Type>(c.getSatisfiedTypes());
if (satisfiedTypes != null && satisfiedTypes.isEmpty() == false) {
// satisfying classes or interfaces map
for (Type satisfiedType : satisfiedTypes) {
TypeDeclaration superdec = satisfiedType.getDeclaration();
if (satisfyingClassesOrInterfaces.get(superdec) == null) {
satisfyingClassesOrInterfaces.put(superdec, new ArrayList<ClassOrInterface>());
}
satisfyingClassesOrInterfaces.get(superdec).add(c);
}
}
}
}
}
}
}
use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.
the class CeylonDoc method writeBy.
protected final void writeBy(Object obj) throws IOException {
List<Annotation> annotations;
if (obj instanceof Declaration) {
annotations = ((Declaration) obj).getAnnotations();
} else if (obj instanceof Module) {
annotations = ((Module) obj).getAnnotations();
} else if (obj instanceof Package) {
annotations = ((Package) obj).getAnnotations();
} else {
throw new IllegalArgumentException();
}
List<String> authors = new ArrayList<>();
for (Annotation annotation : annotations) {
if (annotation.getName().equals("by")) {
for (String author : annotation.getPositionalArguments()) {
authors.add(author);
}
}
}
if (!authors.isEmpty()) {
open("div class='by section'");
around("span class='title'", "By: ");
around("span class='value'", Util.join(", ", authors));
close("div");
}
}
use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.
the class CeylonDocTool method warningMissingThrows.
protected void warningMissingThrows(Declaration d) {
if (ignoreMissingThrows) {
return;
}
final Scope scope = d.getScope();
final PhasedUnit unit = getUnit(d);
final Node node = getNode(d);
if (scope == null || unit == null || unit.getUnit() == null || node == null || !(d instanceof FunctionOrValue)) {
return;
}
List<Type> documentedExceptions = new ArrayList<Type>();
for (Annotation annotation : d.getAnnotations()) {
if (annotation.getName().equals("throws")) {
String exceptionName = annotation.getPositionalArguments().get(0);
Declaration exceptionDecl = scope.getMemberOrParameter(unit.getUnit(), exceptionName, null, false);
if (exceptionDecl instanceof TypeDeclaration) {
documentedExceptions.add(((TypeDeclaration) exceptionDecl).getType());
}
}
}
final List<Type> thrownExceptions = new ArrayList<Type>();
node.visitChildren(new Visitor() {
@Override
public void visit(Tree.Throw that) {
Expression expression = that.getExpression();
if (expression != null) {
thrownExceptions.add(expression.getTypeModel());
} else {
thrownExceptions.add(unit.getUnit().getExceptionType());
}
}
@Override
public void visit(Tree.Declaration that) {
// the end of searching
}
});
for (Type thrownException : thrownExceptions) {
boolean isDocumented = false;
for (Type documentedException : documentedExceptions) {
if (thrownException.isSubtypeOf(documentedException)) {
isDocumented = true;
break;
}
}
if (!isDocumented) {
log.warning(CeylondMessages.msg("warn.missingThrows", thrownException.asString(), getWhere(d), getPosition(getNode(d))));
}
}
}
use of com.redhat.ceylon.model.typechecker.model.Declaration in project ceylon-compiler by ceylon.
the class CeylonDocTool method doc.
private void doc(Module module) throws IOException {
Writer rootWriter = openWriter(getObjectFile(module));
try {
ModuleDoc moduleDoc = new ModuleDoc(this, rootWriter, module);
moduleDoc.generate();
for (Package pkg : getPackages(module)) {
if (pkg.getMembers().isEmpty()) {
continue;
}
// document the package
if (!isRootPackage(module, pkg)) {
Writer packageWriter = openWriter(getObjectFile(pkg));
try {
new PackageDoc(this, packageWriter, pkg).generate();
} finally {
packageWriter.close();
}
}
// document its members
for (Declaration decl : pkg.getMembers()) {
doc(decl);
}
if (pkg.getNameAsString().equals(AbstractModelLoader.CEYLON_LANGUAGE)) {
docNothingType(pkg);
}
}
} finally {
rootWriter.close();
}
}
Aggregations