use of org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition in project ceylon by eclipse.
the class MemberEnter method visitTopLevel.
public void visitTopLevel(JCCompilationUnit tree) {
if (tree.starImportScope.elems != null) {
// we must have already processed this toplevel
return;
}
// toplevel package
if (checkClash && tree.pid != null) {
Symbol p = tree.packge;
while (p.owner != syms.rootPackage) {
// enter all class members of p
p.owner.complete();
if (syms.classes.get(p.getQualifiedName()) != null) {
log.error(tree.pos, "pkg.clashes.with.class.of.same.name", p);
}
p = p.owner;
}
}
// process package annotations
annotateLater(tree.packageAnnotations, env, tree.packge, null);
DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
Lint prevLint = chk.setLint(lint);
try {
// Import-on-demand java.lang.
importAll(tree.pos, reader.enterPackage(names.java_lang), env);
// Process all import clauses.
memberEnter(tree.defs, env);
} finally {
chk.setLint(prevLint);
deferredLintHandler.setPos(prevLintPos);
}
}
use of org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition in project ceylon by eclipse.
the class MemberEnter method visitVarDef.
public void visitVarDef(JCVariableDecl tree) {
Env<AttrContext> localEnv = env;
if ((tree.mods.flags & STATIC) != 0 || (env.info.scope.owner.flags() & INTERFACE) != 0) {
localEnv = env.dup(tree, env.info.dup());
localEnv.info.staticLevel++;
}
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
try {
if (TreeInfo.isEnumInit(tree)) {
attr.attribIdentAsEnumType(localEnv, (JCIdent) tree.vartype);
} else {
attr.attribType(tree.vartype, localEnv);
if (TreeInfo.isReceiverParam(tree))
checkReceiver(tree, localEnv);
}
} finally {
deferredLintHandler.setPos(prevLintPos);
}
if ((tree.mods.flags & VARARGS) != 0) {
// if we are entering a varargs parameter, we need to
// replace its type (a plain array type) with the more
// precise VarargsType --- we need to do it this way
// because varargs is represented in the tree as a
// modifier on the parameter declaration, and not as a
// distinct type of array node.
ArrayType atype = (ArrayType) tree.vartype.type.unannotatedType();
tree.vartype.type = atype.makeVarargs();
}
Scope enclScope = enter.enterScope(env);
VarSymbol v = new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
tree.sym = v;
if (tree.init != null) {
v.flags_field |= HASINIT;
if ((v.flags_field & FINAL) != 0 && needsLazyConstValue(tree.init)) {
Env<AttrContext> initEnv = getInitEnv(tree, env);
initEnv.info.enclVar = v;
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
}
}
if (chk.checkUnique(tree.pos(), v, enclScope)) {
chk.checkTransparentVar(tree.pos(), v, enclScope);
enclScope.enter(v);
}
annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
typeAnnotate(tree.vartype, env, v, tree.pos());
v.pos = tree.pos;
}
use of org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition in project ceylon by eclipse.
the class Check method checkOverride.
/**
* Check that a given method conforms with any method it overrides.
* @param tree The tree from which positions are extracted
* for errors.
* @param m The overriding method.
*/
void checkOverride(JCMethodDecl tree, MethodSymbol m) {
ClassSymbol origin = (ClassSymbol) m.owner;
if ((origin.flags() & ENUM) != 0 && names.finalize.equals(m.name))
if (m.overrides(syms.enumFinalFinalize, origin, types, false)) {
log.error(tree.pos(), "enum.no.finalize");
return;
}
for (Type t = origin.type; t.hasTag(CLASS); t = types.supertype(t)) {
if (t != origin.type) {
checkOverride(tree, t, origin, m);
}
for (Type t2 : types.interfaces(t)) {
checkOverride(tree, t2, origin, m);
}
}
if (m.attribute(syms.overrideType.tsym) != null && !isOverrider(m)) {
DiagnosticPosition pos = tree.pos();
for (JCAnnotation a : tree.getModifiers().annotations) {
if (a.annotationType.type.tsym == syms.overrideType.tsym) {
pos = a.pos();
break;
}
}
log.error(pos, "method.does.not.override.superclass");
}
}
use of org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition in project ceylon by eclipse.
the class Attr method visitTry.
public void visitTry(JCTry tree) {
// Create a new local environment with a local
Env<AttrContext> localEnv = env.dup(tree, env.info.dup(env.info.scope.dup()));
try {
boolean isTryWithResource = tree.resources.nonEmpty();
// Create a nested environment for attributing the try block if needed
Env<AttrContext> tryEnv = isTryWithResource ? env.dup(tree, localEnv.info.dup(localEnv.info.scope.dup())) : localEnv;
try {
// Attribute resource declarations
for (JCTree resource : tree.resources) {
CheckContext twrContext = new Check.NestedCheckContext(resultInfo.checkContext) {
@Override
public void report(DiagnosticPosition pos, JCDiagnostic details) {
chk.basicHandler.report(pos, diags.fragment("try.not.applicable.to.type", details));
}
};
ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext);
if (resource.hasTag(VARDEF)) {
attribStat(resource, tryEnv);
twrResult.check(resource, resource.type);
// check that resource type cannot throw InterruptedException
checkAutoCloseable(resource.pos(), localEnv, resource.type);
VarSymbol var = ((JCVariableDecl) resource).sym;
var.setData(ElementKind.RESOURCE_VARIABLE);
} else {
attribTree(resource, tryEnv, twrResult);
}
}
// Attribute body
attribStat(tree.body, tryEnv);
} finally {
if (isTryWithResource)
tryEnv.info.scope.leave();
}
// Attribute catch clauses
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
JCCatch c = l.head;
Env<AttrContext> catchEnv = localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup()));
try {
Type ctype = attribStat(c.param, catchEnv);
if (TreeInfo.isMultiCatch(c)) {
// multi-catch parameter is implicitly marked as final
c.param.sym.flags_field |= FINAL | UNION;
}
if (c.param.sym.kind == Kinds.VAR) {
c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
}
chk.checkType(c.param.vartype.pos(), chk.checkClassType(c.param.vartype.pos(), ctype), syms.throwableType);
attribStat(c.body, catchEnv);
} finally {
catchEnv.info.scope.leave();
}
}
// Attribute finalizer
if (tree.finalizer != null)
attribStat(tree.finalizer, localEnv);
result = null;
} finally {
localEnv.info.scope.leave();
}
}
use of org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition in project ceylon by eclipse.
the class Attr method attribClassBody.
/**
* Finish the attribution of a class.
*/
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
JCClassDecl tree = (JCClassDecl) env.tree;
Assert.check(c == tree.sym);
// Validate type parameters, supertype and interfaces.
attribStats(tree.typarams, env);
if (!c.isAnonymous()) {
// already checked if anonymous
chk.validate(tree.typarams, env);
chk.validate(tree.extending, env);
chk.validate(tree.implementing, env);
}
c.markAbstractIfNeeded(types);
// methods or unimplemented methods of an implemented interface.
if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) {
if (!relax)
chk.checkAllDefined(tree.pos(), c);
}
if ((c.flags() & Flags.ANNOTATION) != 0) {
if (tree.implementing.nonEmpty())
log.error(tree.implementing.head.pos(), "cant.extend.intf.annotation");
if (tree.typarams.nonEmpty())
log.error(tree.typarams.head.pos(), "intf.annotation.cant.have.type.params");
// If this annotation has a @Repeatable, validate
Attribute.Compound repeatable = c.attribute(syms.repeatableType.tsym);
if (repeatable != null) {
// get diagnostic position for error reporting
DiagnosticPosition cbPos = getDiagnosticPosition(tree, repeatable.type);
Assert.checkNonNull(cbPos);
chk.validateRepeatable(c, repeatable, cbPos);
}
} else {
// Check that all extended classes and interfaces
// are compatible (i.e. no two define methods with same arguments
// yet different return types). (JLS 8.4.6.3)
chk.checkCompatibleSupertypes(tree.pos(), c.type);
if (allowDefaultMethods) {
chk.checkDefaultMethodClashes(tree.pos(), c.type);
}
}
// Check that class does not import the same parameterized interface
// with two different argument lists.
chk.checkClassBounds(tree.pos(), c.type);
tree.type = c.type;
for (List<JCTypeParameter> l = tree.typarams; l.nonEmpty(); l = l.tail) {
Assert.checkNonNull(env.info.scope.lookup(l.head.name).scope);
}
// Check that a generic class doesn't extend Throwable
if (!sourceLanguage.isCeylon() && !c.type.allparams().isEmpty() && types.isSubtype(c.type, syms.throwableType))
log.error(tree.extending.pos(), "generic.throwable");
// Check that all methods which implement some
// method conform to the method they implement.
chk.checkImplementations(tree);
// check that a resource implementing AutoCloseable cannot throw InterruptedException
checkAutoCloseable(tree.pos(), env, c.type);
for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
// Attribute declaration
attribStat(l.head, env);
// Make an exception for static constants.
if (c.owner.kind != PCK && ((c.flags() & STATIC) == 0 || c.name == names.empty) && (TreeInfo.flags(l.head) & (STATIC | INTERFACE)) != 0) {
Symbol sym = null;
if (l.head.hasTag(VARDEF))
sym = ((JCVariableDecl) l.head).sym;
if (sym == null || sym.kind != VAR || ((VarSymbol) sym).getConstValue() == null)
log.error(l.head.pos(), "icls.cant.have.static.decl", c);
}
}
// Check for cycles among non-initial constructors.
chk.checkCyclicConstructors(tree);
// Check for cycles among annotation elements.
chk.checkNonCyclicElements(tree);
// Check for proper use of serialVersionUID
if (env.info.lint.isEnabled(LintCategory.SERIAL) && isSerializable(c.type) && (c.flags() & Flags.ENUM) == 0 && checkForSerial(c)) {
checkSerialVersionUID(tree, c);
}
if (allowTypeAnnos) {
// Correctly organize the postions of the type annotations
typeAnnotations.organizeTypeAnnotationsBodies(tree);
// Check type annotations applicability rules
validateTypeAnnotations(tree, false);
}
}
Aggregations