com.sun.tools.javac.tree.JCTree.JCNewClass Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCNewClass. 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: TreeConverter.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private TreeNode convertNewClass(NewClassTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  ClassInstanceCreation newNode = new ClassInstanceCreation();
  Expression enclosingExpression = (Expression) convert(node.getEnclosingExpression(), path);
  ExecutableElement executable = (ExecutableElement) getElement(path);
  TypeMirror vargarsType = ((JCNewClass) node).varargsElement;
  // Case where the first parameter of the constructor of an inner class is the outer class (e.g.
  // new Outer().new Inner(...). Move the enclosing expression (e.g. new Outer()) as the first
  // argument. A varargs parameter could unintentionally trigger this condition because it could
  // map to zero arguments.
  if (executable.getParameters().size() - node.getArguments().size() == 1
      && vargarsType == null) {
    newNode.addArgument(enclosingExpression);
    enclosingExpression = null;
  }
  for (ExpressionTree arg : node.getArguments()) {
    newNode.addArgument((Expression) convert(arg, path));
  }
  return newNode
      .setExecutablePair(new ExecutablePair(executable))
      .setVarargsType(vargarsType)
      .setExpression(enclosingExpression)
      .setType(convertType(getTypeMirror(getTreePath(path, node.getIdentifier()))))
      .setAnonymousClassDeclaration((TypeDeclaration) convert(node.getClassBody(), path));
}
 
Example #2
Source File: TreeFinder.java    From annotation-tools with MIT License 6 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitNewClass(NewClassTree node, Insertion ins) {
  JCNewClass na = (JCNewClass) node;
  JCExpression className = na.clazz;
  // System.out.printf("classname %s (%s)%n", className, className.getClass());
  while (! (className.getKind() == Tree.Kind.IDENTIFIER)) { // IdentifierTree
    if (className instanceof JCAnnotatedType) {
      className = ((JCAnnotatedType) className).underlyingType;
    } else if (className instanceof JCTypeApply) {
      className = ((JCTypeApply) className).clazz;
    } else if (className instanceof JCFieldAccess) {
      // This occurs for fully qualified names, e.g. "new java.lang.Object()".
      // I'm not quite sure why the field "selected" is taken, but "name" would
      // be a type mismatch. It seems to work, see NewPackage test case.
      className = ((JCFieldAccess) className).selected;
    } else {
      throw new Error(String.format("unrecognized JCNewClass.clazz (%s): %s%n" +
              "   surrounding new class tree: %s%n", className.getClass(), className, node));
    }
    // System.out.printf("classname %s (%s)%n", className, className.getClass());
  }

  return visitIdentifier((IdentifierTree) className, ins);
}
 
Example #3
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void printEnumMember(JCVariableDecl tree) throws IOException {
	printAnnotations(tree.mods.annotations);
	print(tree.name);
	if (tree.init instanceof JCNewClass) {
		JCNewClass constructor = (JCNewClass) tree.init;
		if (constructor.args != null && constructor.args.nonEmpty()) {
			print("(");
			printExprs(constructor.args);
			print(")");
		}
		if (constructor.def != null && constructor.def.defs != null) {
			print(" ");
			printBlock(constructor.def.defs, constructor.def);
		}
	}
}
 
Example #4
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
void process(JCNewClass oldTree, JCNewClass newTree, boolean hasErrors) {
    if (!hasErrors) {
        List<Type> inferredArgs, explicitArgs;
        if (oldTree.def != null) {
            inferredArgs = newTree.def.implementing.nonEmpty()
                              ? newTree.def.implementing.get(0).type.getTypeArguments()
                              : newTree.def.extending.type.getTypeArguments();
            explicitArgs = oldTree.def.implementing.nonEmpty()
                              ? oldTree.def.implementing.get(0).type.getTypeArguments()
                              : oldTree.def.extending.type.getTypeArguments();
        } else {
            inferredArgs = newTree.type.getTypeArguments();
            explicitArgs = oldTree.type.getTypeArguments();
        }
        for (Type t : inferredArgs) {
            if (!types.isSameType(t, explicitArgs.head)) {
                return;
            }
            explicitArgs = explicitArgs.tail;
        }
        //exact match
        log.warning(oldTree.clazz, Warnings.DiamondRedundantArgs);
    }
}
 
Example #5
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(JCNewClass oldTree, JCNewClass newTree, boolean hasErrors) {
    if (!hasErrors) {
        List<Type> inferredArgs, explicitArgs;
        if (oldTree.def != null) {
            inferredArgs = newTree.def.implementing.nonEmpty()
                              ? newTree.def.implementing.get(0).type.getTypeArguments()
                              : newTree.def.extending.type.getTypeArguments();
            explicitArgs = oldTree.def.implementing.nonEmpty()
                              ? oldTree.def.implementing.get(0).type.getTypeArguments()
                              : oldTree.def.extending.type.getTypeArguments();
        } else {
            inferredArgs = newTree.type.getTypeArguments();
            explicitArgs = oldTree.type.getTypeArguments();
        }
        for (Type t : inferredArgs) {
            if (!types.isSameType(t, explicitArgs.head)) {
                return;
            }
            explicitArgs = explicitArgs.tail;
        }
        //exact match
        log.warning(oldTree.clazz, "diamond.redundant.args");
    }
}
 
Example #6
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Lambda body to use for a 'new'.
 */
private JCExpression expressionNew() {
    if (tree.kind == ReferenceKind.ARRAY_CTOR) {
        //create the array creation expression
        JCNewArray newArr = make.NewArray(
                make.Type(types.elemtype(tree.getQualifierExpression().type)),
                List.of(make.Ident(params.first())),
                null);
        newArr.type = tree.getQualifierExpression().type;
        return newArr;
    } else {
        //create the instance creation expression
        //note that method reference syntax does not allow an explicit
        //enclosing class (so the enclosing class is null)
        JCNewClass newClass = make.NewClass(null,
                List.nil(),
                make.Type(tree.getQualifierExpression().type),
                convertArgs(tree.sym, args.toList(), tree.varargsElement),
                null);
        newClass.constructor = tree.sym;
        newClass.constructorType = tree.sym.erasure(types);
        newClass.type = tree.getQualifierExpression().type;
        setVarargsIfNeeded(newClass, tree.varargsElement);
        return newClass;
    }
}
 
Example #7
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    TypeSymbol def = tree.type.tsym;
    boolean inReferencedClass = currentlyInClass(def);
    boolean isLocal = def.isLocal();
    if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) {
        TranslationContext<?> localContext = context();
        final TypeSymbol outerInstanceSymbol = tree.type.getEnclosingType().tsym;
        while (localContext != null  && !localContext.owner.isStatic()) {
            if (localContext.tree.hasTag(LAMBDA)) {
                if (outerInstanceSymbol != null) {
                    JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol);
                    if (block == null) break;
                }
                ((LambdaTranslationContext)localContext)
                        .addSymbol(outerInstanceSymbol, CAPTURED_THIS);
            }
            localContext = localContext.prev;
        }
    }
    if (context() != null && !inReferencedClass && isLocal) {
        LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context();
        captureLocalClassDefs(def, lambdaContext);
    }
    super.visitNewClass(tree);
}
 
Example #8
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** 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 #9
Source File: Corraller.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.of(make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
 
Example #10
Source File: UNewClass.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public JCNewClass inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().NewClass(
      (getEnclosingExpression() == null) ? null : getEnclosingExpression().inline(inliner),
      inliner.<JCExpression, UExpression>inlineList(getTypeArguments()),
      getIdentifier().inline(inliner),
      inliner.<JCExpression, UExpression>inlineList(getArguments()),
      (getClassBody() == null) ? null : getClassBody().inline(inliner));
}
 
Example #11
Source File: TypeAnnotations.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
    Symbol sym = tree.def.sym;
    TypeAnnotationPosition pos = new TypeAnnotationPosition();
    ListBuffer<Attribute.TypeCompound> newattrs =
        new ListBuffer<Attribute.TypeCompound>();

    for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
        newattrs.append(new Attribute.TypeCompound(old.type, old.values,
                                                   pos));
    }

    pos.type = TargetType.NEW;
    pos.pos = tree.pos;
    sym.owner.appendUniqueTypeAttributes(newattrs.toList());
}
 
Example #12
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitNewClass(JCNewClass tree) {
	try {
		if (tree.encl != null) {
			printExpr(tree.encl);
			print(".");
		}
		print("new ");
		if (!tree.typeargs.isEmpty()) {
			print("<");
			printExprs(tree.typeargs);
			print(">");
		}
		printExpr(tree.clazz);
		print("(");
		printExprs(tree.args);
		print(")");
		if (tree.def != null) {
			Name enclClassNamePrev = enclClassName;
			enclClassName =
					tree.def.name != null ? tree.def.name :
						tree.type != null && tree.type.tsym.name != tree.type.tsym.name.table.fromChars(new char[0], 0, 0) ? tree.type.tsym.name :
							null;
			if ((tree.def.mods.flags & Flags.ENUM) != 0) print("/*enum*/");
			printBlock(tree.def.defs, tree.def);
			enclClassName = enclClassNamePrev;
		}
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #13
Source File: TypeAnnotations.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example #14
Source File: TypeAnnotations.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
    Symbol sym = tree.def.sym;
    TypeAnnotationPosition pos = new TypeAnnotationPosition();
    ListBuffer<Attribute.TypeCompound> newattrs =
        new ListBuffer<Attribute.TypeCompound>();

    for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
        newattrs.append(new Attribute.TypeCompound(old.type, old.values,
                                                   pos));
    }

    pos.type = TargetType.NEW;
    pos.pos = tree.pos;
    sym.owner.appendUniqueTypeAttributes(newattrs.toList());
}
 
Example #15
Source File: TypeAnnotations.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example #16
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
JCLambda map (JCNewClass oldTree, JCNewClass newTree){
    JCMethodDecl md = (JCMethodDecl)decls(newTree.def).head;
    List<JCVariableDecl> params = md.params;
    JCBlock body = md.body;
    return make.Lambda(params, body);
}
 
Example #17
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
JCNewClass map(JCNewClass oldTree, JCNewClass newTree) {
    if (newTree.clazz.hasTag(TYPEAPPLY)) {
        ((JCTypeApply)newTree.clazz).arguments = List.nil();
    }
    return newTree;
}
 
Example #18
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
boolean match (JCNewClass tree){
    Type clazztype = tree.clazz.type;
    return tree.def != null &&
            clazztype.hasTag(CLASS) &&
            types.isFunctionalInterface(clazztype.tsym) &&
            decls(tree.def).length() == 1;
}
 
Example #19
Source File: ArgumentAttr.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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 #20
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public JCTree visitNewClass(NewClassTree node, Void aVoid) {
    JCNewClass oldNewClazz = (JCNewClass)node;
    JCNewClass newNewClazz = (JCNewClass)super.visitNewClass(node, aVoid);
    if (!oldNewClazz.args.isEmpty() && oldNewClazz.args.head.hasTag(NULLCHK)) {
        //workaround to Attr generating trees
        newNewClazz.encl = ((JCUnary)newNewClazz.args.head).arg;
        newNewClazz.args = newNewClazz.args.tail;
    }
    return newNewClazz;
}
 
Example #21
Source File: TypeAnnotations.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
    Symbol sym = tree.def.sym;
    TypeAnnotationPosition pos = new TypeAnnotationPosition();
    ListBuffer<Attribute.TypeCompound> newattrs =
        new ListBuffer<Attribute.TypeCompound>();

    for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
        newattrs.append(new Attribute.TypeCompound(old.type, old.values,
                                                   pos));
    }

    pos.type = TargetType.NEW;
    pos.pos = tree.pos;
    sym.owner.appendUniqueTypeAttributes(newattrs.toList());
}
 
Example #22
Source File: TypeAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos;

        if (classdecl.extending == tree.clazz) {
            pos = TypeAnnotationPosition.classExtends(tree.pos);
        } else if (classdecl.implementing.contains(tree.clazz)) {
            final int index = classdecl.implementing.indexOf(tree.clazz);
            pos = TypeAnnotationPosition.classExtends(index, tree.pos);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            throw new AssertionError("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    if (tree.def == null) {
        scan(tree.clazz);
    } // else super type will already have been scanned in the context of the anonymous class.
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example #23
Source File: TypeAnnotations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
    Symbol sym = tree.def.sym;
    final TypeAnnotationPosition pos =
        TypeAnnotationPosition.newObj(tree.pos);
    ListBuffer<Attribute.TypeCompound> newattrs = new ListBuffer<>();

    for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
        newattrs.append(new Attribute.TypeCompound(old.type, old.values,
                                                   pos));
    }

    sym.owner.appendUniqueTypeAttributes(newattrs.toList());
}
 
Example #24
Source File: TypeAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example #25
Source File: TypeAnnotations.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void copyNewClassAnnotationsToOwner(JCNewClass tree) {
    Symbol sym = tree.def.sym;
    TypeAnnotationPosition pos = new TypeAnnotationPosition();
    ListBuffer<Attribute.TypeCompound> newattrs =
        new ListBuffer<Attribute.TypeCompound>();

    for (Attribute.TypeCompound old : sym.getRawTypeAttributes()) {
        newattrs.append(new Attribute.TypeCompound(old.type, old.values,
                                                   pos));
    }

    pos.type = TargetType.NEW;
    pos.pos = tree.pos;
    sym.owner.appendUniqueTypeAttributes(newattrs.toList());
}
 
Example #26
Source File: PostFlowAnalysis.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    super.visitNewClass(tree);
    Symbol c = tree.constructor != null ? tree.constructor.owner : null;
    if (c != null && c != syms.noSymbol && c.hasOuterInstance()) {
        if (tree.encl == null && c.isLocal()) {
            checkThis(tree.pos(), c.type.getEnclosingType().tsym);
        }
    }
}
 
Example #27
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set varargsElement field on a given tree (must be either a new class tree
 * or a method call tree)
 */
private void setVarargsIfNeeded(JCTree tree, Type varargsElement) {
    if (varargsElement != null) {
        switch (tree.getTag()) {
            case APPLY: ((JCMethodInvocation)tree).varargsElement = varargsElement; break;
            case NEWCLASS: ((JCNewClass)tree).varargsElement = varargsElement; break;
            case TYPECAST: setVarargsIfNeeded(((JCTypeCast) tree).expr, varargsElement); break;
            default: throw new AssertionError();
        }
    }
}
 
Example #28
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Make an attributed class instance creation expression.
 *  @param ctype    The class type.
 *  @param args     The constructor arguments.
 *  @param cons     The constructor symbol
 */
JCNewClass makeNewClass(Type ctype, List<JCExpression> args, Symbol cons) {
    JCNewClass tree = make.NewClass(null,
        null, make.QualIdent(ctype.tsym), args, null);
    tree.constructor = cons;
    tree.type = ctype;
    return tree;
}
 
Example #29
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);
    // the anonymous class instantiation if any will be visited separately.
}
 
Example #30
Source File: TypeAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}