Package com.sun.tools.javac.tree.JCTree

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


  @Override
  public boolean matches(NewClassTree newClassTree, VisitorState state) {
    /* TODO(user): Don't catch NullPointerException.  Need to do this right now
     * for internal use, but remember to remove later. */
    try {
      JCNewClass newClass = (JCNewClass) newClassTree;
      String thisClassName = newClass.constructor.getEnclosingElement().toString();
      com.sun.tools.javac.util.List<Type> thisParameterTypes =
          newClass.constructor.type.getParameterTypes();
      List<String> thisParameterTypesAsStrings = new ArrayList<>(thisParameterTypes.length());
      for (Type t : thisParameterTypes) {
View Full Code Here


    if(!matcher.matches(methodInvocation, state)) {
      return Description.NO_MATCH;
    }

    // e.g. new Comparator<String>() { ... }
    JCNewClass newComparatorInvocation = (JCNewClass) methodInvocation.getArguments().get(0);

    // e.g. Ordering
    JCIdent orderingIdent = (JCIdent)
        ((JCFieldAccess) ((JCMethodInvocation) methodInvocation).meth).selected;
    // e.g. Ordering<String>
    JCTypeApply newOrderingType = state.getTreeMaker().TypeApply(orderingIdent,
        ((JCTypeApply) newComparatorInvocation.clazz).arguments);

    // Find the class definition and remove the default constructor (it confuses the pretty printer)
    JCClassDecl def = newComparatorInvocation.def;

    // Note that List is not java.util.List, and it's not very nice to deal with.
    ArrayList<JCTree> allDefsExceptConstructor = new ArrayList<>();
    for (JCTree individualDef : def.defs) {
      if (individualDef instanceof JCMethodDecl) {
        JCMethodDecl methodDecl = (JCMethodDecl) individualDef;
        if (!methodDecl.name.toString().equals("<init>")) {
          allDefsExceptConstructor.add(individualDef);
        }
      } else {
        allDefsExceptConstructor.add(individualDef);
      }
    }

    // e.g. new Ordering<String>() { ... }
    JCNewClass newClass = state.getTreeMaker().NewClass(
        newComparatorInvocation.encl, newComparatorInvocation.typeargs, newOrderingType,
        newComparatorInvocation.args,
        state.getTreeMaker().ClassDef(
            def.mods, def.name, def.typarams, def.extending, def.implementing,
            List.from(allDefsExceptConstructor.toArray(
View Full Code Here

  }
 
  @Override
  public boolean matches(ExpressionTree t, VisitorState state) {
    if (t instanceof JCNewClass) {
      JCNewClass invocation = (JCNewClass)t;
      Type type = invocation.getIdentifier().type;
      if (type.tsym.getQualifiedName().toString().equals(superClass)) {
        return true;
      }
    }
    return false;
View Full Code Here

                    p.type = TargetType.INSTANCEOF;
                    p.pos = frame.pos;
                    return;

                case NEW_CLASS:
                    JCNewClass frameNewClass = (JCNewClass) frame;
                    if (frameNewClass.def != null) {
                        // Special handling for anonymous class instantiations
                        JCClassDecl frameClassDecl = frameNewClass.def;
                        if (frameClassDecl.extending == tree) {
                            p.type = TargetType.CLASS_EXTENDS;
View Full Code Here

    if (!(tree instanceof JCTree.JCNewClass)) {
      ErrorReporter.errorAbort("InternalUtils.constructor: not a javac internal tree");
      return null; // dead code
    }

    JCNewClass newClassTree = (JCNewClass) tree;

    if (RETURN_INVOKE_CONSTRUCTOR && tree.getClassBody() != null) {
      // anonymous constructor bodies should contain exactly one statement
      // in the form:
      // super(arg1, ...)
View Full Code Here

            if (aliasArguments) {
                ((InvocationTermTransformer)transformer).callBuilder.argumentHandling(
                        CallBuilder.CB_ALIAS_ARGS, varBaseName);
            }
           
            JCNewClass iterableClass;
            boolean prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(true);
            try {
                JCExpression transformedElement = applyErasureAndBoxing(iteratorResultName.makeIdent(), typeFact().getAnythingDeclaration().getType(), CodegenUtil.hasTypeErased(expr.getPrimary()),
                        true, BoxingStrategy.BOXED,
                        srcElementType, 0);
                transformedElement = transformMemberExpression(expr, transformedElement, transformer);
               
                // This short-circuit is here for spread invocations
                // The code has been called recursively and the part after this if-statement will
                // be handled by the previous recursion
                if (spreadMethodReferenceOuter) {
                    return make().LetExpr(letStmts.toList(), transformedElement);
                }
               
                transformedElement = applyErasureAndBoxing(transformedElement, resultElementType,
                        // don't trust the erased flag of expr, as it reflects the result type of the overall spread expr,
                        // not necessarily of the applied member
                        CodegenUtil.hasTypeErased((TypedDeclaration)expr.getTarget().getDeclaration()),
                        !CodegenUtil.isUnBoxed(expr), BoxingStrategy.BOXED, resultElementType, 0);
               
                MethodDefinitionBuilder nextMdb = MethodDefinitionBuilder.systemMethod(this, "next");
                nextMdb.isOverride(true);
                nextMdb.annotationFlags(Annotations.IGNORE);
                nextMdb.modifiers(Flags.PUBLIC | Flags.FINAL);
                nextMdb.resultType(null, make().Type(syms().objectType));
                nextMdb.body(List.of(
                        makeVar(iteratorResultName,
                            make().Type(syms().objectType), null),
                        make().If(
                                make().Unary(JCTree.NOT,
                                make().TypeTest(make().Assign(
                                        iteratorResultName.makeIdent(),
                                        make().Apply(null,
                                                naming.makeQualIdent(srcIteratorName.makeIdent(), "next"),
                                                List.<JCExpression>nil())),
                                        make().Type(syms().ceylonFinishedType))),
                                make().Block(0, List.<JCStatement>of(make().Exec(make().Assign(iteratorResultName.makeIdent(),
                                        transformedElement)))),
                                null),
                        make().Return(iteratorResultName.makeIdent())));
                JCMethodDecl nextMethod = nextMdb.build();
               
                // new AbstractIterator()
                JCNewClass iteratorClass = make().NewClass(null,
                        null,
                        make().TypeApply(make().QualIdent(syms().ceylonAbstractIteratorType.tsym),
                                List.of(makeJavaType(resultElementType, JT_TYPE_ARGUMENT))),
                        List.of(makeReifiedTypeArgument(resultElementType)),
                        make().AnonymousClassDef(make().Modifiers(0), List.of(srcIterator, nextMethod)));
View Full Code Here

            .indirect(this, attrClassName, attrName, declarationModel, declarationModel.isToplevel())
            .getterBlock(getterBlock)
            .immutable();
       
        List<JCTree> attr =  builder.build();
        JCNewClass newExpr = makeNewClass(attrClassName, false, null);
        JCExpression result = makeLetExpr(naming.temp(), List.<JCStatement>of((JCStatement)attr.get(0)), newExpr);
        return result;
    }
View Full Code Here

            // the original source text
            if ((tree.mods.flags & Flags.ENUM) != 0) {
                scan(tree.mods);
                if (tree.init != null) {
                    if (tree.init.getTag() == JCTree.NEWCLASS) {
                        JCNewClass init = (JCNewClass) tree.init;
                        if (init.args != null && init.args.nonEmpty()) {
                            scan(init.args);
                        }
                        if (init.def != null && init.def.defs != null) {
                            scan(init.def.defs);
View Full Code Here

        transformation.appendMethods(classBody);
       
        JCClassDecl classDef = gen.make().AnonymousClassDef(gen.make().Modifiers(0), classBody.toList());
       
        int variadicIndex = isVariadic ? numParams - 1 : -1;
        JCNewClass instance = gen.make().NewClass(null,
                null,
                gen.makeJavaType(typeModel, JT_EXTENDS | JT_CLASS_NEW),
                List.<JCExpression>of(gen.makeReifiedTypeArgument(typeModel.getTypeArgumentList().get(0)),
                                      gen.makeReifiedTypeArgument(typeModel.getTypeArgumentList().get(1)),
                                      gen.make().Literal(typeModel.getProducedTypeName(true)),
View Full Code Here

        ProducedType callableType = model.getProducedReference(null, Collections.<ProducedType>emptyList()).getFullType();
        CallableBuilder callableBuilder = CallableBuilder.methodArgument(gen.gen(),
                callableType,
                Collections.singletonList(methodArg.getParameterLists().get(0)),
                gen.classGen().transformMplBody(methodArg.getParameterLists(), model, body));
        JCNewClass callable = callableBuilder.build();
        JCExpression typeExpr = gen.makeJavaType(callableType, JT_RAW);
        JCVariableDecl varDecl = gen.makeVar(argName, typeExpr, callable);
       
        statements = ListBuffer.<JCStatement>of(varDecl);
        bind(declaredParam, argName, gen.makeJavaType(callableType), statements.toList());
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.tree.JCTree.JCNewClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.