Search in sources :

Example 6 with List

use of com.sun.tools.javac.util.List in project lombok by rzwitserloot.

the class JavacJavaUtilSingularizer method createJavaUtilSetMapInitialCapacitySwitchStatements.

protected List<JCStatement> createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source) {
    List<JCExpression> jceBlank = List.nil();
    ListBuffer<JCCase> cases = new ListBuffer<JCCase>();
    if (emptyCollectionMethod != null) {
        // case 0: (empty); break;
        JCStatement assignStat;
        {
            // pluralName = java.util.Collections.emptyCollectionMethod();
            JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", emptyCollectionMethod), jceBlank);
            assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
        }
        JCStatement breakStat = maker.Break(null);
        JCCase emptyCase = maker.Case(maker.Literal(CTC_INT, 0), List.of(assignStat, breakStat));
        cases.append(emptyCase);
    }
    if (singletonCollectionMethod != null) {
        // case 1: (singleton); break;
        JCStatement assignStat;
        {
            // !mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName.get(0));
            //  mapMode: pluralName = java.util.Collections.singletonCollectionMethod(this.pluralName$key.get(0), this.pluralName$value.get(0));
            JCExpression zeroLiteral = maker.Literal(CTC_INT, 0);
            JCExpression arg = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$key" : ""), "get"), List.of(zeroLiteral));
            List<JCExpression> args;
            if (mapMode) {
                JCExpression zeroLiteralClone = maker.Literal(CTC_INT, 0);
                JCExpression arg2 = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName() + (mapMode ? "$value" : ""), "get"), List.of(zeroLiteralClone));
                args = List.of(arg, arg2);
            } else {
                args = List.of(arg);
            }
            JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", singletonCollectionMethod), args);
            assignStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
        }
        JCStatement breakStat = maker.Break(null);
        JCCase singletonCase = maker.Case(maker.Literal(CTC_INT, 1), List.of(assignStat, breakStat));
        cases.append(singletonCase);
    }
    {
        // default:
        List<JCStatement> statements = createJavaUtilSimpleCreationAndFillStatements(maker, data, builderType, mapMode, false, true, emptyCollectionMethod == null, targetType, source);
        JCCase defaultCase = maker.Case(null, statements);
        cases.append(defaultCase);
    }
    JCStatement switchStat = maker.Switch(getSize(maker, builderType, mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(), true, false), cases.toList());
    JCExpression localShadowerType = chainDotsString(builderType, data.getTargetFqn());
    localShadowerType = addTypeArgs(mapMode ? 2 : 1, false, builderType, localShadowerType, data.getTypeArgs(), source);
    JCStatement varDefStat = maker.VarDef(maker.Modifiers(0), data.getPluralName(), localShadowerType, null);
    return List.of(varDefStat, switchStat);
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer) List(com.sun.tools.javac.util.List) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) JCCase(com.sun.tools.javac.tree.JCTree.JCCase)

Example 7 with List

use of com.sun.tools.javac.util.List in project error-prone by google.

the class Template method expectedTypes.

/**
   * Returns a list of the expected types to be matched.  This consists of the argument types from
   * the @BeforeTemplate method, concatenated with the return types of expression placeholders, 
   * sorted by the name of the placeholder method.
   *
   * @throws CouldNotResolveImportException if a referenced type could not be resolved
   */
protected List<Type> expectedTypes(Inliner inliner) throws CouldNotResolveImportException {
    ArrayList<Type> result = new ArrayList<>();
    ImmutableList<UType> types = expressionArgumentTypes().values().asList();
    ImmutableList<String> argNames = expressionArgumentTypes().keySet().asList();
    for (int i = 0; i < argNames.size(); i++) {
        String argName = argNames.get(i);
        Optional<JCExpression> singleBinding = inliner.getOptionalBinding(new UFreeIdent.Key(argName));
        if (!singleBinding.isPresent()) {
            Optional<java.util.List<JCExpression>> exprs = inliner.getOptionalBinding(new URepeated.Key(argName));
            if (!exprs.isPresent() || exprs.get().isEmpty()) {
                // It is a repeated template variable and matches no expressions.
                continue;
            }
        }
        result.add(types.get(i).inline(inliner));
    }
    for (PlaceholderExpressionKey key : Ordering.natural().immutableSortedCopy(Iterables.filter(inliner.bindings.keySet(), PlaceholderExpressionKey.class))) {
        result.add(key.method.returnType().inline(inliner));
    }
    return List.from(result);
}
Also used : ArrayList(java.util.ArrayList) MethodType(com.sun.tools.javac.code.Type.MethodType) Type(com.sun.tools.javac.code.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) List(com.sun.tools.javac.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PlaceholderExpressionKey(com.google.errorprone.refaster.PlaceholderMethod.PlaceholderExpressionKey)

Example 8 with List

use of com.sun.tools.javac.util.List in project error-prone by google.

the class Template method actualTypes.

/**
   * Returns a list of the actual types to be matched.  This consists of the types of the 
   * expressions bound to the @BeforeTemplate method parameters, concatenated with the types
   * of the expressions bound to expression placeholders, sorted by the name of the placeholder 
   * method.
   */
protected List<Type> actualTypes(Inliner inliner) {
    ArrayList<Type> result = new ArrayList<>();
    ImmutableList<String> argNames = expressionArgumentTypes().keySet().asList();
    for (int i = 0; i < expressionArgumentTypes().size(); i++) {
        String argName = argNames.get(i);
        Optional<JCExpression> singleBinding = inliner.getOptionalBinding(new UFreeIdent.Key(argName));
        if (singleBinding.isPresent()) {
            result.add(singleBinding.get().type);
        } else {
            Optional<java.util.List<JCExpression>> exprs = inliner.getOptionalBinding(new URepeated.Key(argName));
            if (exprs.isPresent() && !exprs.get().isEmpty()) {
                Type[] exprTys = new Type[exprs.get().size()];
                for (int j = 0; j < exprs.get().size(); j++) {
                    exprTys[j] = exprs.get().get(j).type;
                }
                // Get the least upper bound of the types of all expressions that the argument matches.
                // In the special case where exprs is empty, returns the "bottom" type, which is a
                // subtype of everything.
                result.add(inliner.types().lub(List.from(exprTys)));
            }
        }
    }
    for (PlaceholderExpressionKey key : Ordering.natural().immutableSortedCopy(Iterables.filter(inliner.bindings.keySet(), PlaceholderExpressionKey.class))) {
        result.add(inliner.getBinding(key).type);
    }
    return List.from(result);
}
Also used : ArrayList(java.util.ArrayList) MethodType(com.sun.tools.javac.code.Type.MethodType) Type(com.sun.tools.javac.code.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) List(com.sun.tools.javac.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PlaceholderExpressionKey(com.google.errorprone.refaster.PlaceholderMethod.PlaceholderExpressionKey)

Example 9 with List

use of com.sun.tools.javac.util.List in project jangaroo-tools by CoreMedia.

the class Start method setOption.

private void setOption(String s, List list) {
    String[] as = new String[list.length() + 1];
    int i = 0;
    as[i++] = s;
    for (List list1 = list; list1.nonEmpty(); list1 = list1.tail) as[i++] = (String) list1.head;
    options = options.append(as);
}
Also used : List(com.sun.tools.javac.util.List)

Example 10 with List

use of com.sun.tools.javac.util.List in project lombok by rzwitserloot.

the class JavacTransformer method transform.

public void transform(long priority, Context context, java.util.List<JCCompilationUnit> compilationUnitsRaw) {
    List<JCCompilationUnit> compilationUnits;
    if (compilationUnitsRaw instanceof List<?>) {
        compilationUnits = (List<JCCompilationUnit>) compilationUnitsRaw;
    } else {
        compilationUnits = List.nil();
        for (int i = compilationUnitsRaw.size() - 1; i >= 0; i--) {
            compilationUnits = compilationUnits.prepend(compilationUnitsRaw.get(i));
        }
    }
    java.util.List<JavacAST> asts = new ArrayList<JavacAST>();
    for (JCCompilationUnit unit : compilationUnits) asts.add(new JavacAST(messager, context, unit));
    for (JavacAST ast : asts) {
        ast.traverse(new AnnotationVisitor(priority));
        handlers.callASTVisitors(ast, priority);
    }
    for (JavacAST ast : asts) if (ast.isChanged())
        LombokOptions.markChanged(context, (JCCompilationUnit) ast.top().get());
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) ArrayList(java.util.ArrayList) List(com.sun.tools.javac.util.List) ArrayList(java.util.ArrayList)

Aggregations

List (com.sun.tools.javac.util.List)25 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)16 ArrayList (java.util.ArrayList)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)9 ListBuffer (com.sun.tools.javac.util.ListBuffer)7 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)5 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)5 JCTree (com.sun.tools.javac.tree.JCTree)5 ImmutableList (com.google.common.collect.ImmutableList)4 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)4 Class (com.redhat.ceylon.model.typechecker.model.Class)4 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)4 Value (com.redhat.ceylon.model.typechecker.model.Value)4 LombokImmutableList (lombok.core.LombokImmutableList)4 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)3 Function (com.redhat.ceylon.model.typechecker.model.Function)3 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)3 Interface (com.redhat.ceylon.model.typechecker.model.Interface)3 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)3