Java Code Examples for com.sun.tools.javac.util.Pair

The following examples show how to use com.sun.tools.javac.util.Pair. These examples are extracted from open source projects. 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 Project: annotation-tools   Source File: SceneOps.java    License: MIT License 6 votes vote down vote up
/**
 * 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 2
Source Project: netbeans   Source File: PostFlowAnalysis.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: javaide   Source File: Attribute.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 4
Source Project: java-n-IDE-for-Android   Source File: Attribute.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source Project: new-bull   Source File: TestQuickSort.java    License: MIT License 6 votes vote down vote up
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 6
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 7
Source Project: manifold   Source File: SrcClassUtil.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: openjdk-jdk9   Source File: JavadocHelper.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
/**
 * 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
/**
 * 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 Project: openjdk-8   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    init();

    for (Pair<TestKind,Hierarchy> fdtest : generateCases()) {
        runTest(fdtest.fst, fdtest.snd, comp, fm);
    }
}
 
Example 12
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 13
Source Project: dragonwell8_jdk   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 14
Source Project: openjdk-jdk9   Source File: Lint.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 15
Source Project: hottub   Source File: JavacTemplateTestBase.java    License: GNU General Public License v2.0 5 votes vote down vote up
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 16
Source Project: openjdk-8-source   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 17
Source Project: openjdk-jdk8u-backup   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 18
Source Project: hottub   Source File: Lint.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 19
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}
 
Example 20
Source Project: hottub   Source File: AnnotationDescImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 21
Source Project: jdk8u-dev-jdk   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    init();

    for (Pair<TestKind,Hierarchy> fdtest : generateCases()) {
        runTest(fdtest.fst, fdtest.snd, comp, fm);
    }
}
 
Example 22
/**
 * Returns the best approximation for the tree node and compilation unit
 * corresponding to the given element, annotation and value.
 * If the element is null, null is returned.
 * If the annotation is null or cannot be found, the tree node and
 * compilation unit for the element is returned.
 * If the annotation value is null or cannot be found, the tree node and
 * compilation unit for the annotation is returned.
 */
public Pair<JCTree, JCCompilationUnit> getTreeAndTopLevel(
                  Element e, AnnotationMirror a, AnnotationValue v) {
    if (e == null)
        return null;

    Pair<JCTree, JCCompilationUnit> elemTreeTop = getTreeAndTopLevel(e);
    if (elemTreeTop == null)
        return null;

    if (a == null)
        return elemTreeTop;

    JCTree annoTree = matchAnnoToTree(a, e, elemTreeTop.fst);
    if (annoTree == null)
        return elemTreeTop;

    if (v == null)
        return new Pair<>(annoTree, elemTreeTop.snd);

    JCTree valueTree = matchAttributeToTree(
            cast(Attribute.class, v), cast(Attribute.class, a), annoTree);
    if (valueTree == null)
        return new Pair<>(annoTree, elemTreeTop.snd);

    return new Pair<>(valueTree, elemTreeTop.snd);
}
 
Example 23
Source Project: annotation-tools   Source File: MethodOffsetClassVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public void visitLocalVariable(String name, String descriptor,
      String signature, Label start, Label end, int index)  {
  super.visitLocalVariable(name, descriptor, signature, start, end, index);
  LocalVariableScanner.addToMethodNameIndexMap(
      Pair.of(methodName, Pair.of(index, start.getOffset())),
      name);
  LocalVariableScanner.addToMethodNameCounter(
      methodName, name, start.getOffset());
  methodCodeOffsetAdapter.visitLocalVariable(name, descriptor, signature, start, end, index);
}
 
Example 24
Source Project: TencentKona-8   Source File: FDTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 25
public void testReadArrayNotBlocking() throws Exception {
    Pair<InputStream, OutputStream> streams = createPipeStream();
    InputStream in = streams.fst;
    OutputStream out = streams.snd;
    out.write('a');
    byte[] data = new byte[12];
    assertEquals(in.read(data), 1);
    assertEquals(data[0], 'a');
    out.write('a'); out.write('b'); out.write('c');
    assertEquals(in.read(data), 3);
    assertEquals(data[0], 'a');
    assertEquals(data[1], 'b');
    assertEquals(data[2], 'c');
}
 
Example 26
Source Project: openjdk-8-source   Source File: Lint.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 Project: annotation-tools   Source File: SceneOps.java    License: MIT License 5 votes vote down vote up
/**
 * Calculates difference between {@code minuend} and first component
 * of {@code eltPair}, adding results to second component of {@code eltPair}.
 */
@Override
public Void visitDeclaration(ADeclaration minuend,
    Pair<AElement, AElement> eltPair) {
  ADeclaration subtrahend = (ADeclaration) eltPair.fst;
  ADeclaration difference = (ADeclaration) eltPair.snd;
  visitElements(minuend.insertAnnotations,
      subtrahend.insertAnnotations, difference.insertAnnotations);
  visitElements(minuend.insertTypecasts, subtrahend.insertTypecasts,
      difference.insertTypecasts);
  return visitElement(minuend, eltPair);
}
 
Example 28
Source Project: jdk8u60   Source File: Lint.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 29
Source Project: jdk8u60   Source File: SymbolMetadata.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Placeholder(Annotate.AnnotateRepeatedContext<T> ctx, List<T> placeholderFor, Symbol on) {
    super(on.type, List.<Pair<Symbol.MethodSymbol, Attribute>>nil(),
            ctx.isTypeCompound ?
                    ((Attribute.TypeCompound)placeholderFor.head).position :
                        new TypeAnnotationPosition());
    this.ctx = ctx;
    this.placeholderFor = placeholderFor;
    this.on = on;
}
 
Example 30
@AfterMethod
public void copyErrors(ITestResult result) {
    if (!result.isSuccess()) {
        suiteErrors.addAll(diags.errorKeys());

        List<Object> list = new ArrayList<>();
        Collections.addAll(list, result.getParameters());
        list.add("Test case: " + getTestCaseDescription());
        for (Pair<String, Template> e : sourceFiles)
            list.add("Source file " + e.fst + ": " + e.snd);
        if (diags.errorsFound())
            list.add("Compile diagnostics: " + diags.toString());
        result.setParameters(list.toArray(new Object[list.size()]));
    }
}