use of com.redhat.ceylon.model.typechecker.model.Scope 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.Scope in project ceylon-compiler by ceylon.
the class LinkRenderer method isInCurrentModule.
private boolean isInCurrentModule(Object obj) {
Module objModule = null;
if (obj instanceof Module) {
objModule = (Module) obj;
} else if (obj instanceof Scope) {
objModule = getPackage((Scope) obj).getModule();
} else if (obj instanceof Element) {
objModule = getPackage(((Element) obj).getScope()).getModule();
}
Module currentModule = ceylonDocTool.getCurrentModule();
if (currentModule != null && objModule != null) {
return currentModule.equals(objModule);
}
return false;
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class StatementTransformer method transform.
public JCTree transform(CustomTree.GuardedVariable that) {
BoxingStrategy boxingStrategy = CodegenUtil.getBoxingStrategy(that.getDeclarationModel());
Tree.Expression expr = that.getSpecifierExpression().getExpression();
Type fromType = expr.getTypeModel();
Value newValue = that.getDeclarationModel();
Type toType = newValue.getType();
Tree.ConditionList conditionList = that.getConditionList();
Tree.Condition condition = conditionList.getConditions().get(0);
JCExpression val = expressionGen().transformExpression(expr);
at(that);
if (condition instanceof Tree.IsCondition) {
if (!willEraseToObject(toType)) {
// Want raw type for instanceof since it can't be used with generic types
JCExpression rawToTypeExpr = makeJavaType(toType, JT_NO_PRIMITIVES | JT_RAW);
// Substitute variable with the correct type to use in the rest of the code block
val = make().TypeCast(rawToTypeExpr, val);
if (CodegenUtil.isUnBoxed(newValue) && canUnbox(toType)) {
val = unboxType(val, toType);
}
}
} else if (condition instanceof Tree.ExistsCondition) {
Type exprType = fromType;
if (isOptional(exprType)) {
exprType = typeFact().getDefiniteType(exprType);
}
val = expressionGen().applyErasureAndBoxing(val, exprType, CodegenUtil.hasTypeErased(expr), true, CodegenUtil.hasUntrustedType(expr), boxingStrategy, toType, 0);
} else if (condition instanceof Tree.NonemptyCondition) {
Type exprType = fromType;
if (isOptional(exprType)) {
exprType = typeFact().getDefiniteType(exprType);
}
val = expressionGen().applyErasureAndBoxing(val, exprType, false, true, BoxingStrategy.BOXED, toType, ExpressionTransformer.EXPR_DOWN_CAST);
}
SyntheticName alias = naming.alias(that.getIdentifier().getText());
Substitution subst = naming.addVariableSubst(newValue, alias.getName());
// FIXME: this is rubbish, but the same rubbish from assert. it's most likely wrong there too
Scope scope = that.getScope().getScope();
while (scope instanceof ConditionScope) {
scope = scope.getScope();
}
subst.scopeClose(scope);
JCExpression varType = makeJavaType(toType);
return make().VarDef(make().Modifiers(FINAL), alias.asName(), varType, val);
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class Naming method makeTypeDeclaration.
private <R> R makeTypeDeclaration(TypeDeclarationBuilder<R> declarationBuilder, final TypeDeclaration decl, DeclNameFlag... options) {
EnumSet<DeclNameFlag> flags = EnumSet.noneOf(DeclNameFlag.class);
flags.addAll(Arrays.asList(options));
if (flags.contains(DeclNameFlag.ANNOTATION) && !Decl.isAnnotationClass(decl)) {
throw new BugException(decl.getName());
}
if (flags.contains(DeclNameFlag.ANNOTATIONS) && !(Decl.isAnnotationClass(decl) || decl instanceof Class || gen().isSequencedAnnotation((Class) decl))) {
throw new BugException(decl.getName());
}
java.util.List<Scope> l = new java.util.ArrayList<Scope>();
Scope s = decl;
do {
l.add(s);
s = s.getContainer();
} while (!(s instanceof Package));
Collections.reverse(l);
if (flags.contains(DeclNameFlag.QUALIFIED) && (!decl.isAnonymous() || decl.isNamed())) {
final List<String> packageName;
if (!AbstractTransformer.isJavaArray(decl))
packageName = ((Package) s).getName();
else
packageName = COM_REDHAT_CEYLON_LANGUAGE_PACKAGE;
if (packageName.isEmpty() || !packageName.get(0).isEmpty()) {
declarationBuilder.select("");
}
for (int ii = 0; ii < packageName.size(); ii++) {
declarationBuilder.select(quoteIfJavaKeyword(packageName.get(ii)));
}
}
for (int ii = 0; ii < l.size(); ii++) {
Scope scope = l.get(ii);
final boolean last = ii == l.size() - 1;
appendTypeDeclaration(decl, flags, declarationBuilder, scope, last);
}
return declarationBuilder.result();
}
use of com.redhat.ceylon.model.typechecker.model.Scope in project ceylon-compiler by ceylon.
the class Naming method getTypeArgumentDescriptorName.
public String getTypeArgumentDescriptorName(TypeParameter tp) {
String name;
if (tp.isCaptured()) {
// must build unique name
StringBuilder sb = new StringBuilder();
LinkedList<Declaration> decls = new LinkedList<Declaration>();
Scope scope = tp;
while (scope != null && scope instanceof Package == false) {
if (scope instanceof Declaration)
decls.add((Declaration) scope);
scope = scope.getContainer();
}
Iterator<Declaration> iterator = decls.descendingIterator();
while (iterator.hasNext()) {
sb.append(iterator.next().getName());
if (iterator.hasNext())
sb.append("$");
}
name = sb.toString();
} else {
name = tp.getName();
}
return prefixName(Prefix.$reified$, name);
}
Aggregations