Java Code Examples for com.sun.tools.javac.util.List#get()
The following examples show how to use
com.sun.tools.javac.util.List#get() .
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 TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 2
Source File: TList.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 3
Source File: TList.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 4
Source File: DeferredAttr.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Pick the deferred node to be unstuck. The chosen node is the first strongly connected * component containing exactly one node found in the dependency graph induced by deferred nodes. * If no such component is found, the first deferred node is returned. */ DeferredAttrNode pickDeferredNode() { List<StuckNode> nodes = StreamSupport.stream(deferredAttrNodes) .map(StuckNode::new) .collect(List.collector()); //init stuck expression graph; a deferred node A depends on a deferred node B iff //the intersection between A's input variable and B's output variable is non-empty. for (StuckNode sn1 : nodes) { for (Type t : sn1.data.deferredStuckPolicy.stuckVars()) { for (StuckNode sn2 : nodes) { if (sn1 != sn2 && sn2.data.deferredStuckPolicy.depVars().contains(t)) { sn1.deps.add(sn2); } } } } //compute tarjan on the stuck graph List<? extends StuckNode> csn = GraphUtils.tarjan(nodes).get(0); return csn.length() == 1 ? csn.get(0).data : deferredAttrNodes.get(0); }
Example 5
Source File: TList.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 6
Source File: TList.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 7
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 6 votes |
private String genSuperCtorCall( Symbol.MethodSymbol superCtor ) { String bodyStmt; StringBuilder sb = new StringBuilder( "super(" ); List<Symbol.VarSymbol> parameters = superCtor.getParameters(); for( int i = 0; i < parameters.size(); i++ ) { Symbol.VarSymbol param = parameters.get( i ); if( i > 0 ) { sb.append( ", " ); } sb.append( getValueForType( param.type ) ); } sb.append( ");" ); bodyStmt = sb.toString(); return bodyStmt; }
Example 8
Source File: TList.java From hottub with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 9
Source File: TList.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 10
Source File: TList.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
void test_get_int() { System.err.println("test get(int)"); for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) { java.util.List<String> ref = e.getKey(); List<String> l = e.getValue(); for (int i = -1; i <= ref.size(); i++) { boolean expectException = i < 0 || i >= ref.size(); String expectValue = (expectException ? null : ref.get(i)); try { String foundValue = l.get(i); if (expectException || !equal(expectValue, foundValue)) throw new AssertionError(); } catch (IndexOutOfBoundsException ex) { if (!expectException) throw new AssertionError(); } } } }
Example 11
Source File: JavacSingularsRecipes.java From EasyMPermission with MIT License | 6 votes |
protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) { if (typeArgs == null || typeArgs.size() <= index) { return genJavaLangTypeRef(builderType, "Object"); } else { JCExpression originalType = typeArgs.get(index); if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) { return genJavaLangTypeRef(builderType, "Object"); } else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) { try { return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext()); } catch (Exception e) { return genJavaLangTypeRef(builderType, "Object"); } } else { return cloneType(maker, originalType, source, builderType.getContext()); } } }
Example 12
Source File: TreePruner.java From bazel with Apache License 2.0 | 6 votes |
private static boolean delegatingConstructor(List<JCStatement> stats) { if (stats.isEmpty()) { return false; } JCStatement stat = stats.get(0); if (stat.getKind() != Kind.EXPRESSION_STATEMENT) { return false; } JCExpression expr = ((JCExpressionStatement) stat).getExpression(); if (expr.getKind() != Kind.METHOD_INVOCATION) { return false; } JCExpression method = ((JCMethodInvocation) expr).getMethodSelect(); Name name; switch (method.getKind()) { case IDENTIFIER: name = ((JCIdent) method).getName(); break; case MEMBER_SELECT: name = ((JCFieldAccess) method).getIdentifier(); break; default: return false; } return name.contentEquals("this") || name.contentEquals("super"); }
Example 13
Source File: HandleNonNull.java From EasyMPermission with MIT License | 5 votes |
/** * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;}, * where the block braces are optional. If it is of this form, returns "x". * If it is not of this form, returns null. */ public String returnVarNameIfNullCheck(JCStatement stat) { if (!(stat instanceof JCIf)) return null; /* Check that the if's statement is a throw statement, possibly in a block. */ { JCStatement then = ((JCIf) stat).thenpart; if (then instanceof JCBlock) { List<JCStatement> stats = ((JCBlock) then).stats; if (stats.length() == 0) return null; then = stats.get(0); } if (!(then instanceof JCThrow)) return null; } /* Check that the if's conditional is like 'x == null'. Return from this method (don't generate a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ { JCExpression cond = ((JCIf) stat).cond; while (cond instanceof JCParens) cond = ((JCParens) cond).expr; if (!(cond instanceof JCBinary)) return null; JCBinary bin = (JCBinary) cond; if (!CTC_EQUAL.equals(treeTag(bin))) return null; if (!(bin.lhs instanceof JCIdent)) return null; if (!(bin.rhs instanceof JCLiteral)) return null; if (!CTC_BOT.equals(typeTag(bin.rhs))) return null; return ((JCIdent) bin.lhs).name.toString(); } }
Example 14
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 4 votes |
private Symbol.MethodSymbol findExtMethod( JCTree.JCMethodInvocation tree ) { Symbol sym = null; if( tree.meth instanceof JCTree.JCFieldAccess ) { sym = ((JCTree.JCFieldAccess)tree.meth).sym; } else if( tree.meth instanceof JCTree.JCIdent ) { sym = ((JCTree.JCIdent)tree.meth).sym; } if( sym == null || !sym.hasAnnotations() ) { return null; } for( Attribute.Compound annotation: sym.getAnnotationMirrors() ) { if( annotation.type.toString().equals( ExtensionMethod.class.getName() ) ) { String extensionClass = (String)annotation.values.get( 0 ).snd.getValue(); boolean isStatic = (boolean)annotation.values.get( 1 ).snd.getValue(); BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); //JavacHook.instance() != null ? (JavacTaskImpl)JavacHook.instance().getJavacTask_PlainFileMgr() : ClassSymbols.instance( _sp.getModule() ).getJavacTask_PlainFileMgr(); Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( _sp.getModule() ).getClassSymbol( javacTask, _tp, extensionClass ); if( classSymbol == null ) { // In module mode if a package in another module is not exported, classes in the package // will not be accessible to other modules, hence the null classSymbol continue; } Symbol.ClassSymbol extClassSym = classSymbol.getFirst(); if( extClassSym == null ) { // This can happen during bootstrapping with Dark Java classes from Manifold itself // So we short-circuit that here (ManClassFinder_9 or any other darkj class used during bootstrapping doesn't really need to use extensions) return null; } Types types = Types.instance( javacTask.getContext() ); outer: for( Symbol elem: IDynamicJdk.instance().getMembers( extClassSym ) ) { if( elem instanceof Symbol.MethodSymbol && elem.flatName().toString().equals( sym.name.toString() ) ) { Symbol.MethodSymbol extMethodSym = (Symbol.MethodSymbol)elem; List<Symbol.VarSymbol> extParams = extMethodSym.getParameters(); List<Symbol.VarSymbol> calledParams = ((Symbol.MethodSymbol)sym).getParameters(); int thisOffset = isStatic ? 0 : 1; if( extParams.size() - thisOffset != calledParams.size() ) { continue; } for( int i = thisOffset; i < extParams.size(); i++ ) { Symbol.VarSymbol extParam = extParams.get( i ); Symbol.VarSymbol calledParam = calledParams.get( i - thisOffset ); if( !types.isSameType( types.erasure( extParam.type ), types.erasure( calledParam.type ) ) ) { continue outer; } } return extMethodSym; } } } } return null; }
Example 15
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 4 votes |
private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol method, BasicJavacTask javacTask ) { String name = method.flatName().toString(); SrcMethod srcMethod = new SrcMethod( srcClass, name.equals( "<init>" ) ); addAnnotations( srcMethod, method ); srcMethod.modifiers( method.getModifiers() ); if( (method.flags() & Flags.VARARGS) != 0 ) { srcMethod.modifiers( srcMethod.getModifiers() | 0x00000080 ); // Modifier.VARARGS } if( name.equals( "<clinit>" ) ) { return; } if( !srcMethod.isConstructor() ) { srcMethod.name( name ); srcMethod.returns( makeSrcType( method.getReturnType(), method, TargetType.METHOD_RETURN, -1 ) ); } for( Symbol.TypeVariableSymbol typeVar: method.getTypeParameters() ) { srcMethod.addTypeVar( makeTypeVarType( typeVar ) ); } List<Symbol.VarSymbol> parameters = method.getParameters(); for( int i = 0; i < parameters.size(); i++ ) { Symbol.VarSymbol param = parameters.get( i ); SrcParameter srcParam = new SrcParameter( param.flatName().toString(), makeSrcType( param.type, method, TargetType.METHOD_FORMAL_PARAMETER, i ) ); srcMethod.addParam( srcParam ); addAnnotations( srcParam, param ); } List<Type> thrownTypes = method.getThrownTypes(); for( int i = 0; i < thrownTypes.size(); i++ ) { Type throwType = thrownTypes.get( i ); srcMethod.addThrowType( makeSrcType( throwType, method, TargetType.THROWS, i ) ); } String bodyStmt; if( srcMethod.isConstructor() && !srcClass.isEnum() ) { // Note we can't just throw an exception for the ctor body, the compiler will // still complain about the missing super() call if the super class does not have // an accessible default ctor. To appease the compiler we generate a super(...) // call to the first accessible constructor we can find in the super class. bodyStmt = genSuperCtorCall( module, srcClass, javacTask ); } else { bodyStmt = "throw new RuntimeException();"; } srcMethod.body( new SrcStatementBlock() .addStatement( new SrcRawStatement() .rawText( bodyStmt ) ) ); srcClass.addMethod( srcMethod ); }
Example 16
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 4 votes |
private String typeNoAnnotations( Type type ) { if( isJava8() ) { return type.toString(); } StringBuilder sb = new StringBuilder(); if( type instanceof Type.ClassType ) { if( type.getEnclosingType().hasTag( CLASS ) && ReflectUtil.field( type.tsym.owner, "kind" ).get() == ReflectUtil.field( "com.sun.tools.javac.code.Kinds$Kind", "TYP" ).getStatic() ) { sb.append( typeNoAnnotations( type.getEnclosingType() ) ); sb.append( "." ); sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, false ) ); } else { sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, true ) ); } List<Type> typeArgs = type.getTypeArguments(); if( typeArgs.nonEmpty() ) { sb.append( '<' ); for( int i = 0; i < typeArgs.size(); i++ ) { if( i > 0 ) { sb.append( ", " ); } Type typeArg = typeArgs.get( i ); sb.append( typeNoAnnotations( typeArg ) ); } sb.append( ">" ); } } else if( type instanceof Type.ArrayType ) { sb.append( typeNoAnnotations( ((Type.ArrayType)type).getComponentType() ) ).append( "[]" ); } else if( type instanceof Type.WildcardType ) { Type.WildcardType wildcardType = (Type.WildcardType)type; BoundKind kind = wildcardType.kind; sb.append( kind.toString() ); if( kind != BoundKind.UNBOUND ) { sb.append( typeNoAnnotations( wildcardType.type ) ); } } else { sb.append( type.toString() ); } return sb.toString(); }