Java Code Examples for com.sun.tools.javac.util.Pair#of()

The following examples show how to use com.sun.tools.javac.util.Pair#of() . 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: FindMaximumSellProfit.java    From Android-Cheat-sheet with Apache License 2.0 6 votes vote down vote up
public static Pair<Integer, Integer> findMaximumSellProfit(int length, int[] arr) {
    int currentBuy = arr[0];
    int globalSell = arr[1];
    int globalProfit = globalSell - currentBuy;

    int currentProfit;

    for(int i=1; i< length; i++) {
        int currentSell = arr[i];
        currentProfit = currentSell - currentBuy;

        if(currentProfit > globalProfit) {
            globalProfit = currentProfit;
            globalSell = arr[i];
        }

        if(currentBuy > arr[i]) {
            currentBuy = arr[i];
        }
    }

    int optimalBuyPrice = globalSell-globalProfit;
    int optimalSellPrice = globalSell;
    return Pair.of(optimalBuyPrice, optimalSellPrice) ;
}
 
Example 2
Source File: JavadocHelper.java    From openjdk-jdk9 with 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 3
Source File: CreateSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Pair<Integer, Character> addConstant(List<CPInfo> constantPool, Object value, boolean annotation) {
    if (value instanceof Boolean) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info(((Boolean) value) ? 1 : 0)), 'Z');
    } else if (value instanceof Byte) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((byte) value)), 'B');
    } else if (value instanceof Character) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((char) value)), 'C');
    } else if (value instanceof Short) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((short) value)), 'S');
    } else if (value instanceof Integer) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((int) value)), 'I');
    } else if (value instanceof Long) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Long_info((long) value)), 'J');
    } else if (value instanceof Float) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Float_info((float) value)), 'F');
    } else if (value instanceof Double) {
        return Pair.of(addToCP(constantPool, new CONSTANT_Double_info((double) value)), 'D');
    } else if (value instanceof String) {
        int stringIndex = addString(constantPool, (String) value);
        if (annotation) {
            return Pair.of(stringIndex, 's');
        } else {
            return Pair.of(addToCP(constantPool, new CONSTANT_String_info(null, stringIndex)), 's');
        }
    }

    return null;
}
 
Example 4
Source File: PipeInputStreamTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Pair<InputStream, OutputStream> createPipeStream() throws Exception {
    Class<?> pipeStreamClass = Class.forName("jdk.jshell.execution.PipeInputStream");
    Constructor<?> c = pipeStreamClass.getDeclaredConstructor();
    c.setAccessible(true);
    Object pipeStream = c.newInstance();
    Method createOutputStream = pipeStreamClass.getDeclaredMethod("createOutput");
    createOutputStream.setAccessible(true);
    return Pair.of((InputStream) pipeStream, (OutputStream) createOutputStream.invoke(pipeStream));
}
 
Example 5
Source File: PostFlowAnalysis.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void outerThisDef(Symbol owner) {
    Type target = types.erasure(owner.enclClass().type.getEnclosingType());
    Pair<TypeSymbol, Symbol> outerThis = Pair.of(target.tsym, owner);
    outerThisStack = outerThisStack.prepend(outerThis);
}
 
Example 6
Source File: LocalVariableCriterion.java    From annotation-tools with MIT License 4 votes vote down vote up
@Override
public boolean isSatisfiedBy(TreePath path) {
  if (path == null) {
    return false;
  }

  TreePath parentPath = path.getParentPath();
  if (parentPath == null) {
    return false;
  }

  Tree parent = parentPath.getLeaf();
  Tree leaf = path.getLeaf();
  if (parent instanceof VariableTree) {
    // parent is a variable declaration

    if (parentPath.getParentPath().getLeaf() instanceof MethodTree) {
      // formal parameter, not local variable
      return false;
    }

    VariableTree vtt = (VariableTree) parent;
    if (leaf.equals(vtt.getInitializer())) {
      // don't match in initializer
      return false;
    }

    String varName = vtt.getName().toString();

    if (Objects.equals(loc.varName, varName)) {
      int varIndex = LocalVariableScanner.indexOfVarTree(path, vtt, varName);
      return (loc.varIndex == varIndex);
    }

    Pair<String, Pair<Integer, Integer>> key =
            Pair.of(fullMethodName, Pair.of(loc.index, loc.scopeStart));
    String potentialVarName =
            LocalVariableScanner.getFromMethodNameIndexMap(key);
    if (potentialVarName != null) {
      if (varName.equals(potentialVarName)) {
        // now use methodNameCounter to ensure that if this is the
        // i'th variable of this name, its offset is the i'th offset
        // of all variables with this name
        List<Integer> allOffsetsWithThisName =
                LocalVariableScanner.getFromMethodNameCounter(fullMethodName, potentialVarName);
        //      methodNameCounter.get(fullMethodName).get(potentialVarName);
        Integer thisVariablesOffset =
                allOffsetsWithThisName.indexOf(loc.scopeStart);

        // now you need to make sure that this is the
        // thisVariablesOffset'th variable tree in the entire source
        int i = LocalVariableScanner.indexOfVarTree(path, parent, potentialVarName);

        if (i == thisVariablesOffset) {
          return true;
        }
      }
    }
    return false;
  }
  // isSatisfiedBy should return true not just for the local variable itself, but for its type.
  // So, if this is part of a type, try its parent.
  // For example, return true for the tree for "Integer"
  // within the local variable "List<Integer> foo;"
  //
  // But, stop the search once it gets to certain types, such as MethodTree.
  // Is it OK to stop at ExpressionTree too?
  else if (parent instanceof MethodTree) {
    return false;
  } else {
    return this.isSatisfiedBy(parentPath);
  }
}
 
Example 7
Source File: SceneOps.java    From annotation-tools with MIT License 4 votes vote down vote up
/**
 * Convenience method for ensuring returned {@link Pair} is of the
 * most general type.
 */
private Pair<AElement, AElement> elemPair(AElement stype,
    AElement dtype) {
  return Pair.of(stype, dtype);
}