com.sun.tools.javac.util.Pair Java Examples
The following examples show how to use
com.sun.tools.javac.util.Pair.
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: PostFlowAnalysis.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void visitClassDef(JCClassDecl tree) { TypeSymbol currentClassPrev = currentClass; currentClass = tree.sym; List<Pair<TypeSymbol, Symbol>> prevOuterThisStack = outerThisStack; try { if (currentClass != null) { if (currentClass.hasOuterInstance()) outerThisDef(currentClass); super.visitClassDef(tree); } } finally { outerThisStack = prevOuterThisStack; currentClass = currentClassPrev; } }
Example #2
Source File: Infer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private List<Pair<Type, Type>> getParameterizedSupers(Type t, Type s) { Type lubResult = types.lub(t, s); if (lubResult == syms.errType || lubResult == syms.botType) { return List.nil(); } List<Type> supertypesToCheck = lubResult.isIntersection() ? ((IntersectionClassType)lubResult).getComponents() : List.of(lubResult); ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>(); for (Type sup : supertypesToCheck) { if (sup.isParameterized()) { Type asSuperOfT = asSuper(t, sup); Type asSuperOfS = asSuper(s, sup); commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS)); } } return commonSupertypes.toList(); }
Example #3
Source File: TestQuickSort.java From new-bull with MIT License | 6 votes |
private Pair<SortTask, SortTask> divide() { int p = array[startInclusive]; int i = startInclusive + 1; int j = endInclusive; while (i < j) { while (i < j && array[i] <= p) { i++; } while (i < j && array[j] > p) { j--; } if (i < j) { swap(i, j); i++; j--; } } swap(i, startInclusive); SortTask left = new SortTask(array, startInclusive, i - 1); SortTask right = new SortTask(array, i + 1, endInclusive); return new Pair<>(left, right); }
Example #4
Source File: SrcClassUtil.java From manifold with Apache License 2.0 | 6 votes |
private Symbol.MethodSymbol findConstructor( IModule module, String fqn, BasicJavacTask javacTask ) { manifold.rt.api.util.Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( module ).getClassSymbol( javacTask, fqn ); Symbol.ClassSymbol cs = classSymbol.getFirst(); Symbol.MethodSymbol ctor = null; for( Symbol sym: cs.getEnclosedElements() ) { if( sym instanceof Symbol.MethodSymbol && sym.flatName().toString().equals( "<init>" ) ) { if( ctor == null ) { ctor = (Symbol.MethodSymbol)sym; } else { ctor = mostAccessible( ctor, (Symbol.MethodSymbol)sym ); } if( Modifier.isPublic( (int)ctor.flags() ) ) { return ctor; } } } return ctor; }
Example #5
Source File: Attribute.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns a string representation of this annotation. * String is of one of the forms: * @com.example.foo(name1=val1, name2=val2) * @com.example.foo(val) * @com.example.foo * Omit parens for marker annotations, and omit "value=" when allowed. */ public String toString() { StringBuilder buf = new StringBuilder(); buf.append("@"); buf.append(type); int len = values.length(); if (len > 0) { buf.append('('); boolean first = true; for (Pair<MethodSymbol, Attribute> value : values) { if (!first) buf.append(", "); first = false; Name name = value.fst.name; if (len > 1 || name != name.table.names.value) { buf.append(name); buf.append('='); } buf.append(value.snd); } buf.append(')'); } return buf.toString(); }
Example #6
Source File: SceneOps.java From annotation-tools with MIT License | 6 votes |
/** * Calculates difference between {@code minuend} and first component * of {@code eltPair}, adding results to second component of {@code eltPair}. */ @Override public Void visitExpression(AExpression minuend, Pair<AElement, AElement> eltPair) { AExpression subtrahend = (AExpression) eltPair.fst; AExpression difference = (AExpression) eltPair.snd; visitElements(minuend.typecasts, subtrahend.typecasts, difference.typecasts); visitElements(minuend.instanceofs, subtrahend.instanceofs, difference.instanceofs); visitElements(minuend.news, subtrahend.news, difference.news); visitElements(minuend.calls, subtrahend.calls, difference.calls); visitElements(minuend.refs, subtrahend.refs, difference.refs); visitElements(minuend.funs, subtrahend.funs, difference.funs); return visitElement(minuend, eltPair); }
Example #7
Source File: Attribute.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns a string representation of this annotation. * String is of one of the forms: * @com.example.foo(name1=val1, name2=val2) * @com.example.foo(val) * @com.example.foo * Omit parens for marker annotations, and omit "value=" when allowed. */ public String toString() { StringBuilder buf = new StringBuilder(); buf.append("@"); buf.append(type); int len = values.length(); if (len > 0) { buf.append('('); boolean first = true; for (Pair<MethodSymbol, Attribute> value : values) { if (!first) buf.append(", "); first = false; Name name = value.fst.name; if (len > 1 || name != name.table.names.value) { buf.append(name); buf.append('='); } buf.append(value.snd); } buf.append(')'); } return buf.toString(); }
Example #8
Source File: JavadocHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private Pair<JavacTask, CompilationUnitTree> findSource(String moduleName, String binaryName) throws IOException { JavaFileObject jfo = fm.getJavaFileForInput(StandardLocation.SOURCE_PATH, binaryName, JavaFileObject.Kind.SOURCE); if (jfo == null) return null; List<JavaFileObject> jfos = Arrays.asList(jfo); JavaFileManager patchFM = moduleName != null ? new PatchModuleFileManager(baseFileManager, jfo, moduleName) : baseFileManager; JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, patchFM, d -> {}, null, null, jfos); Iterable<? extends CompilationUnitTree> cuts = task.parse(); task.enter(); return Pair.of(task, cuts.iterator().next()); }
Example #9
Source File: AnnotationProxyMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns a map from element symbols to their values. * Includes all elements, whether explicit or defaulted. */ private Map<MethodSymbol, Attribute> getAllValues() { Map<MethodSymbol, Attribute> res = new LinkedHashMap<>(); // First find the default values. ClassSymbol sym = (ClassSymbol) anno.type.tsym; for (Symbol s : sym.members().getSymbols(NON_RECURSIVE)) { if (s.kind == MTH) { MethodSymbol m = (MethodSymbol) s; Attribute def = m.getDefaultValue(); if (def != null) res.put(m, def); } } // Next find the explicit values, possibly overriding defaults. for (Pair<MethodSymbol, Attribute> p : anno.values) res.put(p.fst, p.snd); return res; }
Example #10
Source File: Infer.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Computes a path that goes from a given node to the leafs in the graph. * Typically this will start from a node containing a variable in * {@code varsToSolve}. For any given path, the cost is computed as the total * number of type-variables that should be eagerly instantiated across that path. */ Pair<List<Node>, Integer> computeTreeToLeafs(Node n) { Pair<List<Node>, Integer> cachedPath = treeCache.get(n); if (cachedPath == null) { //cache miss if (n.isLeaf()) { //if leaf, stop cachedPath = new Pair<>(List.of(n), n.data.length()); } else { //if non-leaf, proceed recursively Pair<List<Node>, Integer> path = new Pair<>(List.of(n), n.data.length()); for (Node n2 : n.getAllDependencies()) { if (n2 == n) continue; Pair<List<Node>, Integer> subpath = computeTreeToLeafs(n2); path = new Pair<>(path.fst.prependList(subpath.fst), path.snd + subpath.snd); } cachedPath = path; } //save results in cache treeCache.put(n, cachedPath); } return cachedPath; }
Example #11
Source File: CreateSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private element_value createAttributeValue(List<CPInfo> constantPool, Object value) { Pair<Integer, Character> constantPoolEntry = addConstant(constantPool, value, true); if (constantPoolEntry != null) { return new Primitive_element_value(constantPoolEntry.fst, constantPoolEntry.snd); } else if (value instanceof EnumConstant) { EnumConstant ec = (EnumConstant) value; return new Enum_element_value(addString(constantPool, ec.type), addString(constantPool, ec.constant), 'e'); } else if (value instanceof ClassConstant) { ClassConstant cc = (ClassConstant) value; return new Class_element_value(addString(constantPool, cc.type), 'c'); } else if (value instanceof AnnotationDescription) { Annotation annotation = createAnnotation(constantPool, ((AnnotationDescription) value)); return new Annotation_element_value(annotation, '@'); } else if (value instanceof Collection) { @SuppressWarnings("unchecked") Collection<Object> array = (Collection<Object>) value; element_value[] values = new element_value[array.size()]; int i = 0; for (Object elem : array) { values[i++] = createAttributeValue(constantPool, elem); } return new Array_element_value(values, '['); } throw new IllegalStateException(value.getClass().getName()); }
Example #12
Source File: FDTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "fdCases") public Object[][] caseGenerator() { List<Pair<TestKind, Hierarchy>> cases = generateCases(); Object[][] fdCases = new Object[cases.size()][]; for (int i = 0; i < cases.size(); ++i) { fdCases[i] = new Object[2]; fdCases[i][0] = cases.get(i).fst; fdCases[i][1] = cases.get(i).snd; } return fdCases; }
Example #13
Source File: DocTreeMaker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) { ListBuffer<DCTree> lb = new ListBuffer<>(); lb.addAll(cast(fullBody)); List<DCTree> fBody = lb.toList(); // A dummy comment to keep the diagnostics logic happy. Comment c = new Comment() { @Override public String getText() { return null; } @Override public int getSourcePos(int index) { return Position.NOPOS; } @Override public CommentStyle getStyle() { return CommentStyle.JAVADOC; } @Override public boolean isDeprecated() { return false; } }; Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody); DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags)); return tree; }
Example #14
Source File: FDTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "fdCases") public Object[][] caseGenerator() { List<Pair<TestKind, Hierarchy>> cases = generateCases(); Object[][] fdCases = new Object[cases.size()][]; for (int i = 0; i < cases.size(); ++i) { fdCases[i] = new Object[2]; fdCases[i][0] = cases.get(i).fst; fdCases[i][1] = cases.get(i).snd; } return fdCases; }
Example #15
Source File: DocTreeMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) { ListBuffer<DCTree> lb = new ListBuffer<>(); lb.addAll(cast(fullBody)); List<DCTree> fBody = lb.toList(); // A dummy comment to keep the diagnostics logic happy. Comment c = new Comment() { @Override public String getText() { return null; } @Override public int getSourcePos(int index) { return Position.NOPOS; } @Override public CommentStyle getStyle() { return CommentStyle.JAVADOC; } @Override public boolean isDeprecated() { return false; } }; Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody); DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags)); return tree; }
Example #16
Source File: SceneOps.java From annotation-tools with MIT License | 5 votes |
/** * Calculates difference between {@code minuend} and first component * of {@code eltPair}, adding results to second component of {@code eltPair}. */ @Override public Void visitBlock(ABlock minuend, Pair<AElement, AElement> eltPair) { ABlock subtrahend = (ABlock) eltPair.fst; ABlock difference = (ABlock) eltPair.snd; visitElements(minuend.locals, subtrahend.locals, difference.locals); return visitExpression(minuend, eltPair); }
Example #17
Source File: JavadocHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public String getResolvedDocComment(Element forElement) throws IOException { Pair<JavacTask, TreePath> sourceElement = getSourceElement(mainTask, forElement); if (sourceElement == null) return null; return getResolvedDocComment(sourceElement.fst, sourceElement.snd); }
Example #18
Source File: CreateSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void addAttributes(FieldDescription desc, List<CPInfo> constantPool, Map<String, Attribute> attributes) { addGenericAttributes(desc, constantPool, attributes); if (desc.constantValue != null) { Pair<Integer, Character> constantPoolEntry = addConstant(constantPool, desc.constantValue, false); Assert.checkNonNull(constantPoolEntry); int constantValueString = addString(constantPool, Attribute.ConstantValue); attributes.put(Attribute.ConstantValue, new ConstantValue_attribute(constantValueString, constantPoolEntry.fst)); } }
Example #19
Source File: FDTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { init(); for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { runTest(fdtest.fst, fdtest.snd, comp, fm); } }
Example #20
Source File: FDTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { init(); for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { runTest(fdtest.fst, fdtest.snd, comp, fm); } }
Example #21
Source File: Lint.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void visitCompound(Attribute.Compound compound) { if (compound.type.tsym == syms.suppressWarningsType.tsym) { for (List<Pair<MethodSymbol,Attribute>> v = compound.values; v.nonEmpty(); v = v.tail) { Pair<MethodSymbol,Attribute> value = v.head; if (value.fst.name.toString().equals("value")) value.snd.accept(this); } } }
Example #22
Source File: FDTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static List<Pair<TestKind, Hierarchy>> generateCases() { ArrayList<Pair<TestKind,Hierarchy>> list = new ArrayList<>(); HierarchyGenerator hg = new HierarchyGenerator(); for (TestKind tk : TestKind.values()) { for (Hierarchy hs : tk.getHierarchy(hg)) { list.add(new Pair<>(tk, hs)); } } return list; }
Example #23
Source File: AnnotationDescImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Returns this annotation's elements and their values. * Only those explicitly present in the annotation are * included, not those assuming their default values. * Returns an empty array if there are none. */ public ElementValuePair[] elementValues() { List<Pair<MethodSymbol,Attribute>> vals = annotation.values; ElementValuePair res[] = new ElementValuePair[vals.length()]; int i = 0; for (Pair<MethodSymbol,Attribute> val : vals) { res[i++] = new ElementValuePairImpl(env, val.fst, val.snd); } return res; }
Example #24
Source File: CheckAttributedTree.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void test(List<Pair<JCCompilationUnit, JCTree>> trees) { for (Pair<JCCompilationUnit, JCTree> p : trees) { sourcefile = p.fst.sourcefile; endPosTable = p.fst.endPositions; encl = new Info(p.snd, endPosTable); p.snd.accept(this); } }
Example #25
Source File: FDTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { init(); for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { runTest(fdtest.fst, fdtest.snd, comp, fm); } }
Example #26
Source File: Lint.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public void visitCompound(Attribute.Compound compound) { if (compound.type.tsym == syms.suppressWarningsType.tsym) { for (List<Pair<MethodSymbol,Attribute>> v = compound.values; v.nonEmpty(); v = v.tail) { Pair<MethodSymbol,Attribute> value = v.head; if (value.fst.name.toString().equals("value")) value.snd.accept(this); } } }
Example #27
Source File: Attribute.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public Map<MethodSymbol, Attribute> getElementValues() { Map<MethodSymbol, Attribute> valmap = new LinkedHashMap<MethodSymbol, Attribute>(); for (Pair<MethodSymbol, Attribute> value : values) valmap.put(value.fst, value.snd); return valmap; }
Example #28
Source File: FDTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { init(); for (Pair<TestKind,Hierarchy> fdtest : generateCases()) { runTest(fdtest.fst, fdtest.snd, comp, fm); } }
Example #29
Source File: FDTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "fdCases") public Object[][] caseGenerator() { List<Pair<TestKind, Hierarchy>> cases = generateCases(); Object[][] fdCases = new Object[cases.size()][]; for (int i = 0; i < cases.size(); ++i) { fdCases[i] = new Object[2]; fdCases[i][0] = cases.get(i).fst; fdCases[i][1] = cases.get(i).snd; } return fdCases; }
Example #30
Source File: FDTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@DataProvider(name = "fdCases") public Object[][] caseGenerator() { List<Pair<TestKind, Hierarchy>> cases = generateCases(); Object[][] fdCases = new Object[cases.size()][]; for (int i = 0; i < cases.size(); ++i) { fdCases[i] = new Object[2]; fdCases[i][0] = cases.get(i).fst; fdCases[i][1] = cases.get(i).snd; } return fdCases; }