Java Code Examples for com.sun.tools.javac.util.List#size()

The following examples show how to use com.sun.tools.javac.util.List#size() . 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: TList.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void test_addAll_int_Collection() {
    System.err.println("test addAll(int,Collection)");
    for (List<String> l: examples.values()) {
        int l_size = l.size();
        for (java.util.List<String> arg: examples.keySet()) {
            try {
                boolean modified = l.addAll(0, arg);
                if (modified)
                    throw new AssertionError();
            } catch (UnsupportedOperationException e) {
            }
            if (l.size() != l_size)
                throw new AssertionError();
        }
    }
}
 
Example 2
Source File: T6238612.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void test(List<String> list, String[] array) {
    String[] result = list.toArray(array);

    if (result.length < list.size()) {
        error("returned array is too small; expected: " + list.size() + ", found: " + result.length);
        return;
    }

    if (list.size() <= array.length && result != array)
        error("new array wrongly created");

    int i = 0;
    for (String s: list)
        check(result, i++, s);

    if (i < result.length)
        check(result, i, null);
}
 
Example 3
Source File: TList.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void test_addAll_int_Collection() {
    System.err.println("test addAll(int,Collection)");
    for (List<String> l: examples.values()) {
        int l_size = l.size();
        for (java.util.List<String> arg: examples.keySet()) {
            try {
                boolean modified = l.addAll(0, arg);
                if (modified)
                    throw new AssertionError();
            } catch (UnsupportedOperationException e) {
            }
            if (l.size() != l_size)
                throw new AssertionError();
        }
    }
}
 
Example 4
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static void sanityCheckForMethodGeneratingAnnotationsOnBuilderClass(JavacNode typeNode, JavacNode errorNode) {
	List<String> disallowed = List.nil();
	for (JavacNode child : typeNode.down()) {
		for (Class<? extends java.lang.annotation.Annotation> annType : INVALID_ON_BUILDERS) {
			if (annotationTypeMatches(annType, child)) {
				disallowed = disallowed.append(annType.getSimpleName());
			}
		}
	}
	
	int size = disallowed.size();
	if (size == 0) return;
	if (size == 1) {
		errorNode.addError("@" + disallowed.head + " is not allowed on builder classes.");
		return;
	}
	StringBuilder out = new StringBuilder();
	for (String a : disallowed) out.append("@").append(a).append(", ");
	out.setLength(out.length() - 2);
	errorNode.addError(out.append(" are not allowed on builder classes.").toString());
}
 
Example 5
Source File: T6238612.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
void test(List<String> list, String[] array) {
    String[] result = list.toArray(array);

    if (result.length < list.size()) {
        error("returned array is too small; expected: " + list.size() + ", found: " + result.length);
        return;
    }

    if (list.size() <= array.length && result != array)
        error("new array wrongly created");

    int i = 0;
    for (String s: list)
        check(result, i++, s);

    if (i < result.length)
        check(result, i, null);
}
 
Example 6
Source File: TList.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void test_retainAll_Collection() {
    System.err.println("test retainAll(Collection)");
    for (List<String> l: examples.values()) {
        int l_size = l.size();
        for (java.util.List<String> arg: examples.keySet()) {
            try {
                boolean modified = l.retainAll(arg);
                if (modified)
                    throw new AssertionError();
            } catch (UnsupportedOperationException e) {
            }
            if (l.size() != l_size)
                throw new AssertionError();
        }
    }
}
 
Example 7
Source File: TList.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
void test_addAll_Collection() {
    System.err.println("test addAll(Collection)");
    for (List<String> l: examples.values()) {
        int l_size = l.size();
        for (java.util.List<String> arg: examples.keySet()) {
            try {
                boolean modified = l.addAll(arg);
                if (modified)
                    throw new AssertionError();
            } catch (UnsupportedOperationException e) {
            }
            if (l.size() != l_size)
                throw new AssertionError();
        }
    }
}
 
Example 8
Source File: T7042566.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
boolean isApplicable(TypeConfiguration that) {
    List<TypeKind> actuals = that.typeKindList;
    List<TypeKind> formals = parameterTypes.typeKindList;
    if ((actuals.size() - formals.size()) < -1)
        return false; //not enough args
    for (TypeKind actual : actuals) {
        if (!actual.isSubtypeOf(formals.head))
            return false; //type mismatch
        formals = formals.tail.isEmpty() ?
            formals :
            formals.tail;
    }
    return true;
}
 
Example 9
Source File: JavacParser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** CatchClause     = CATCH "(" FormalParameter ")" Block
 * TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below.
 */
protected JCCatch catchClause() {
    int pos = token.pos;
    accept(CATCH);
    accept(LPAREN);
    JCModifiers mods = optFinal(Flags.PARAMETER);
    List<JCExpression> catchTypes = catchTypes();
    JCExpression paramType = catchTypes.size() > 1 ?
            toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) :
            catchTypes.head;
    JCVariableDecl formal = variableDeclaratorId(mods, paramType);
    accept(RPAREN);
    JCBlock body = block();
    return F.at(pos).Catch(formal, body);
}
 
Example 10
Source File: TList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test_size() {
    System.err.println("test size()");
    for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
        java.util.List<String> ref = e.getKey();
        List<String> l = e.getValue();
        int  expect = ref.size();
        int found = l.size();
        if (expect != found)
            throw new AssertionError();
    }
}
 
Example 11
Source File: TList.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void test_reverse() {
    System.err.println("test reverse()");
    for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
        java.util.List<String> ref = e.getKey();
        List<String> l = e.getValue();
        java.util.List<String> expect = reverse(ref);
        List<String> found = l.reverse();
        if (l.size() < 2 && found != l)  // reverse of empty or singleton list is itself
            throw new AssertionError();
        if (!equal(l, ref)) // orginal should be unchanged
            throw new AssertionError();
        if (!equal(expect, found))
            throw new AssertionError();
    }
}
 
Example 12
Source File: T6238612.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void test(List<String> list) {
    int n = list.size();
    if (n > 0)
        test(list, new String[0]);

    if (n > 1)
        test(list, new String[n - 1]);

    test(list, new String[n]);
    test(list, new String[n + 1]);
    test(list, new String[n + 5]);
}
 
Example 13
Source File: JavacParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** CatchClause     = CATCH "(" FormalParameter ")" Block
 * TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below.
 */
protected JCCatch catchClause() {
    int pos = token.pos;
    accept(CATCH);
    accept(LPAREN);
    JCModifiers mods = optFinal(Flags.PARAMETER);
    List<JCExpression> catchTypes = catchTypes();
    JCExpression paramType = catchTypes.size() > 1 ?
            toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) :
            catchTypes.head;
    JCVariableDecl formal = variableDeclaratorId(mods, paramType);
    accept(RPAREN);
    JCBlock body = block();
    return F.at(pos).Catch(formal, body);
}
 
Example 14
Source File: T6238612.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test(List<String> list) {
    int n = list.size();
    if (n > 0)
        test(list, new String[0]);

    if (n > 1)
        test(list, new String[n - 1]);

    test(list, new String[n]);
    test(list, new String[n + 1]);
    test(list, new String[n + 5]);
}
 
Example 15
Source File: TList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test_reverse() {
    System.err.println("test reverse()");
    for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
        java.util.List<String> ref = e.getKey();
        List<String> l = e.getValue();
        java.util.List<String> expect = reverse(ref);
        List<String> found = l.reverse();
        if (l.size() < 2 && found != l)  // reverse of empty or singleton list is itself
            throw new AssertionError();
        if (!equal(l, ref)) // orginal should be unchanged
            throw new AssertionError();
        if (!equal(expect, found))
            throw new AssertionError();
    }
}
 
Example 16
Source File: TList.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void test_clear() {
    System.err.println("test clear()");
    for (List<String> l: examples.values()) {
        int l_size = l.size();
        try {
            l.clear();
            if (l_size > 0)
                throw new AssertionError();
        } catch (UnsupportedOperationException e) {
        }
        if (l.size() != l_size)
            throw new AssertionError();
    }
}
 
Example 17
Source File: Pretty.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void visitNewArray(JCNewArray tree) {
    try {
        if (tree.elemtype != null) {
            print("new ");
            JCTree elem = tree.elemtype;
            printBaseElementType(elem);

            if (!tree.annotations.isEmpty()) {
                print(' ');
                printTypeAnnotations(tree.annotations);
            }
            if (tree.elems != null) {
                print("[]");
            }

            int i = 0;
            List<List<JCAnnotation>> da = tree.dimAnnotations;
            for (List<JCExpression> l = tree.dims; l.nonEmpty(); l = l.tail) {
                if (da.size() > i && !da.get(i).isEmpty()) {
                    print(' ');
                    printTypeAnnotations(da.get(i));
                }
                print("[");
                i++;
                printExpr(l.head);
                print("]");
            }
            printBrackets(elem);
        }
        if (tree.elems != null) {
            print("{");
            printExprs(tree.elems);
            print("}");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 18
Source File: JavacParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/** CatchClause     = CATCH "(" FormalParameter ")" Block
 * TODO: the "FormalParameter" is not correct, it uses the special "catchTypes" rule below.
 */
protected JCCatch catchClause() {
    int pos = token.pos;
    accept(CATCH);
    accept(LPAREN);
    JCModifiers mods = optFinal(Flags.PARAMETER);
    List<JCExpression> catchTypes = catchTypes();
    JCExpression paramType = catchTypes.size() > 1 ?
            toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) :
            catchTypes.head;
    JCVariableDecl formal = variableDeclaratorId(mods, paramType);
    accept(RPAREN);
    JCBlock body = block();
    return F.at(pos).Catch(formal, body);
}
 
Example 19
Source File: DynamicProxyFactory.java    From manifold with Apache License 2.0 4 votes vote down vote up
private static boolean hasCallMethod( BasicJavacTask javacTask, Symbol.ClassSymbol classSymbol )
{
  Name call = Names.instance( javacTask.getContext() ).fromString( "call" );
  Iterable<Symbol> elems = IDynamicJdk.instance().getMembersByName( classSymbol, call );
  for( Symbol s : elems )
  {
    if( s instanceof Symbol.MethodSymbol )
    {
      List<Symbol.VarSymbol> parameters = ((Symbol.MethodSymbol)s).getParameters();
      if( parameters.size() != 6 )
      {
        return false;
      }

      Symtab symbols = Symtab.instance( javacTask.getContext() );
      Types types = Types.instance( javacTask.getContext() );
      return types.erasure( parameters.get( 0 ).asType() ).equals( types.erasure( symbols.classType ) ) &&
             parameters.get( 1 ).asType().equals( symbols.stringType ) &&
             parameters.get( 2 ).asType().equals( symbols.stringType ) &&
             types.erasure( parameters.get( 3 ).asType() ).equals( types.erasure( symbols.classType ) ) &&
             parameters.get( 4 ).asType() instanceof Type.ArrayType && types.erasure( ((Type.ArrayType)parameters.get( 4 ).asType()).getComponentType() ).equals( types.erasure( symbols.classType ) ) &&
             parameters.get( 5 ).asType() instanceof Type.ArrayType && ((Type.ArrayType)parameters.get( 5 ).asType()).getComponentType().equals( symbols.objectType );
    }
  }
  Type superclass = classSymbol.getSuperclass();
  if( !(superclass instanceof NoType) )
  {
    if( hasCallMethod( javacTask, (Symbol.ClassSymbol)superclass.tsym ) )
    {
      return true;
    }
  }
  for( Type iface : classSymbol.getInterfaces() )
  {
    if( hasCallMethod( javacTask, (Symbol.ClassSymbol)iface.tsym ) )
    {
      return true;
    }
  }
  return false;
}
 
Example 20
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
  * This method is used to infer a suitable target SAM in case the original
  * SAM type contains one or more wildcards. An inference process is applied
  * so that wildcard bounds, as well as explicit lambda/method ref parameters
  * (where applicable) are used to constraint the solution.
  */
public Type instantiateFunctionalInterface(DiagnosticPosition pos, Type funcInterface,
        List<Type> paramTypes, Check.CheckContext checkContext) {
    if (types.capture(funcInterface) == funcInterface) {
        //if capture doesn't change the type then return the target unchanged
        //(this means the target contains no wildcards!)
        return funcInterface;
    } else {
        Type formalInterface = funcInterface.tsym.type;
        InferenceContext funcInterfaceContext =
                new InferenceContext(funcInterface.tsym.type.getTypeArguments());

        Assert.check(paramTypes != null);
        //get constraints from explicit params (this is done by
        //checking that explicit param types are equal to the ones
        //in the functional interface descriptors)
        List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes();
        if (descParameterTypes.size() != paramTypes.size()) {
            checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda"));
            return types.createErrorType(funcInterface);
        }
        for (Type p : descParameterTypes) {
            if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) {
                checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
                return types.createErrorType(funcInterface);
            }
            paramTypes = paramTypes.tail;
        }

        try {
            funcInterfaceContext.solve(funcInterfaceContext.boundedVars(), types.noWarnings);
        } catch (InferenceException ex) {
            checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
        }

        List<Type> actualTypeargs = funcInterface.getTypeArguments();
        for (Type t : funcInterfaceContext.undetvars) {
            UndetVar uv = (UndetVar)t;
            if (uv.inst == null) {
                uv.inst = actualTypeargs.head;
            }
            actualTypeargs = actualTypeargs.tail;
        }

        Type owntype = funcInterfaceContext.asInstType(formalInterface);
        if (!chk.checkValidGenericType(owntype)) {
            //if the inferred functional interface type is not well-formed,
            //or if it's not a subtype of the original target, issue an error
            checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
        }
        return owntype;
    }
}