Java Code Examples for com.sun.tools.javac.tree.TreeInfo#isDiamond()
The following examples show how to use
com.sun.tools.javac.tree.TreeInfo#isDiamond() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Check that usage of diamond operator is correct (i.e. diamond should not * be used with non-generic classes or in anonymous class creation expressions) */ Type checkDiamond(JCNewClass tree, Type t) { if (!TreeInfo.isDiamond(tree) || t.isErroneous()) { return checkClassType(tree.clazz.pos(), t, true); } else { if (tree.def != null && !allowDiamondWithAnonymousClassCreation) { log.error(DiagnosticFlag.SOURCE_LEVEL, tree.clazz.pos(), Errors.CantApplyDiamond1(t, Fragments.DiamondAndAnonClassNotSupportedInSource(source.name))); } if (t.tsym.type.getTypeArguments().isEmpty()) { log.error(tree.clazz.pos(), Errors.CantApplyDiamond1(t, Fragments.DiamondNonGeneric(t))); return types.createErrorType(t); } else if (tree.typeargs != null && tree.typeargs.nonEmpty()) { log.error(tree.clazz.pos(), Errors.CantApplyDiamond1(t, Fragments.DiamondAndExplicitParams(t))); return types.createErrorType(t); } else { return t; } } }
Example 2
Source File: ArgumentAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void visitNewClass(JCNewClass that) { if (TreeInfo.isDiamond(that)) { processArg(that, speculativeTree -> new ResolvedConstructorType(that, env, speculativeTree)); } else { //not a poly expression, just call Attr setResult(that, attr.attribTree(that, env, attr.unknownExprInfo)); } }
Example 3
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void checkRaw(JCTree tree, Env<AttrContext> env) { if (lint.isEnabled(LintCategory.RAW) && tree.type.hasTag(CLASS) && !TreeInfo.isDiamond(tree) && !withinAnonConstr(env) && tree.type.isRaw()) { log.warning(LintCategory.RAW, tree.pos(), Warnings.RawClassUse(tree.type, tree.type.tsym.type)); } }
Example 4
Source File: ArgumentAttr.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void visitNewClass(JCNewClass that) { if (TreeInfo.isDiamond(that)) { processArg(that, speculativeTree -> new ResolvedConstructorType(that, env, speculativeTree)); } else { //not a poly expression, just call Attr setResult(that, attr.attribTree(that, env, attr.unknownExprInfo)); } }
Example 5
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected DeferredAttr(Context context) { context.put(deferredAttrKey, this); attr = Attr.instance(context); argumentAttr = ArgumentAttr.instance(context); chk = Check.instance(context); diags = JCDiagnostic.Factory.instance(context); enter = Enter.instance(context); infer = Infer.instance(context); rs = Resolve.instance(context); log = Log.instance(context); syms = Symtab.instance(context); make = TreeMaker.instance(context); types = Types.instance(context); flow = Flow.instance(context); names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); typeEnvs = TypeEnvs.instance(context); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override void addDeferredAttrNode(DeferredType dt, ResultInfo ri, DeferredStuckPolicy deferredStuckPolicy) { Assert.error("Empty deferred context!"); } @Override void complete() { Assert.error("Empty deferred context!"); } @Override public String toString() { return "Empty deferred context!"; } }; // For speculative attribution, skip the class definition in <>. treeCopier = new TreeCopier<Void>(make) { @Override @DefinedBy(Api.COMPILER_TREE) public JCTree visitNewClass(NewClassTree node, Void p) { JCNewClass t = (JCNewClass) node; if (TreeInfo.isDiamond(t)) { JCExpression encl = copy(t.encl, p); List<JCExpression> typeargs = copy(t.typeargs, p); JCExpression clazz = copy(t.clazz, p); List<JCExpression> args = copy(t.args, p); JCClassDecl def = null; return make.at(t.pos).NewClass(encl, typeargs, clazz, args, def); } else { return super.visitNewClass(node, p); } } @Override @DefinedBy(Api.COMPILER_TREE) public JCTree visitMemberReference(MemberReferenceTree node, Void p) { JCMemberReference t = (JCMemberReference) node; JCExpression expr = copy(t.expr, p); List<JCExpression> typeargs = copy(t.typeargs, p); /** once the value for overloadKind is determined for a copy, it can be safely forwarded to * the copied tree, we want to profit from that */ JCMemberReference result = new JCMemberReference(t.mode, t.name, expr, typeargs) { @Override public void setOverloadKind(OverloadKind overloadKind) { super.setOverloadKind(overloadKind); if (t.getOverloadKind() == null) { t.setOverloadKind(overloadKind); } } }; result.pos = t.pos; return result; } }; deferredCopier = new TypeMapping<Void> () { @Override public Type visitType(Type t, Void v) { if (t.hasTag(DEFERRED)) { DeferredType dt = (DeferredType) t; return new DeferredType(treeCopier.copy(dt.tree), dt.env); } return t; } }; }
Example 6
Source File: Analyzer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override boolean match(JCNewClass tree) { return tree.clazz.hasTag(TYPEAPPLY) && !TreeInfo.isDiamond(tree) && (tree.def == null || allowDiamondWithAnonymousClassCreation); }
Example 7
Source File: Analyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override boolean match(JCNewClass tree) { return tree.clazz.hasTag(TYPEAPPLY) && !TreeInfo.isDiamond(tree) && (tree.def == null || allowDiamondWithAnonymousClassCreation); }
Example 8
Source File: Enter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** Create a fresh environment for class bodies. * This will create a fresh scope for local symbols of a class, referred * to by the environments info.scope field. * This scope will contain * - symbols for this and super * - symbols for any type parameters * In addition, it serves as an anchor for scopes of methods and initializers * which are nested in this scope via Scope.dup(). * This scope should not be confused with the members scope of a class. * * @param tree The class definition. * @param env The environment current outside of the class definition. */ public Env<AttrContext> classEnv(JCClassDecl tree, Env<AttrContext> env) { Env<AttrContext> localEnv = env.dup(tree, env.info.dup(WriteableScope.create(tree.sym))); localEnv.enclClass = tree; localEnv.outer = env; localEnv.info.isSelfCall = false; localEnv.info.lint = null; // leave this to be filled in by Attr, // when annotations have been processed localEnv.info.isAnonymousDiamond = TreeInfo.isDiamond(env.tree); return localEnv; }