コード例 #1
0
 @Override
 public void emptyStack() {
   myCachedHash = null;
   while (!myStack.isEmpty() && !(myStack.peek() instanceof DfaControlTransferValue)) {
     myStack.pop();
   }
 }
コード例 #2
0
  /**
   * Asks current builder to wrap one more remaining {@link Block code block} (if any).
   *
   * @return <code>true</code> if all blocks are wrapped; <code>false</code> otherwise
   */
  public boolean iteration() {
    if (myStates.isEmpty()) {
      return true;
    }

    State state = myStates.peek();
    doIteration(state);
    return myStates.isEmpty();
  }
コード例 #3
0
  final void restoreValue(boolean pushed) {
    if (pushed) {
      --myLevel;
      if (myValueStack != null && !myValueStack.isEmpty()) {
        myValueStack.pop();
      }
    }

    if (myValueStack != null) {
      myValue = myValueStack.isEmpty() ? null : myValueStack.peek();
    }
  }
コード例 #4
0
  private void doIteration(@NotNull State state) {
    List<Block> subBlocks = state.parentBlock.getSubBlocks();
    final int subBlocksCount = subBlocks.size();
    int childBlockIndex = state.getIndexOfChildBlockToProcess();
    final Block block = subBlocks.get(childBlockIndex);
    if (state.previousBlock != null
        || (myCurrentWhiteSpace != null && myCurrentWhiteSpace.isIsFirstWhiteSpace())) {
      myCurrentSpaceProperty =
          (SpacingImpl) state.parentBlock.getSpacing(state.previousBlock, block);
    }

    boolean childBlockIsRightBlock = false;

    if (childBlockIndex == subBlocksCount - 1 && state.parentBlockIsRightBlock) {
      childBlockIsRightBlock = true;
    }

    final AbstractBlockWrapper wrapper =
        buildFrom(
            block,
            childBlockIndex,
            state.wrappedBlock,
            state.parentBlockWrap,
            state.parentBlock,
            childBlockIsRightBlock);
    registerExpandableIndents(block, wrapper);

    if (wrapper.getIndent() == null) {
      wrapper.setIndent((IndentImpl) block.getIndent());
    }
    if (!state.readOnly) {
      try {
        subBlocks.set(childBlockIndex, null); // to prevent extra strong refs during model building
      } catch (Throwable ex) {
        // read-only blocks
      }
    }

    if (state.childBlockProcessed(block, wrapper)) {
      while (!myStates.isEmpty() && myStates.peek().isProcessed()) {
        myStates.pop();
      }
    }
  }
コード例 #5
0
ファイル: GenerationState.java プロジェクト: vonwao/kotlin
 public BindingContext getBindingContext() {
   return bindingContexts.peek();
 }
コード例 #6
0
 @Nullable
 private DefaultArrangementEntry getCurrent() {
   return myStack.isEmpty() ? null : myStack.peek();
 }
コード例 #7
0
ファイル: CheckerTestUtil.java プロジェクト: JetBrains/kotlin
  public static StringBuffer addDiagnosticMarkersToText(
      @NotNull final PsiFile psiFile,
      @NotNull Collection<Diagnostic> diagnostics,
      @NotNull Map<Diagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
      @NotNull Function<PsiFile, String> getFileText) {
    String text = getFileText.fun(psiFile);
    StringBuffer result = new StringBuffer();
    diagnostics =
        Collections2.filter(
            diagnostics,
            new Predicate<Diagnostic>() {
              @Override
              public boolean apply(Diagnostic diagnostic) {
                return psiFile.equals(diagnostic.getPsiFile());
              }
            });
    if (!diagnostics.isEmpty()) {
      List<DiagnosticDescriptor> diagnosticDescriptors =
          getSortedDiagnosticDescriptors(diagnostics);

      Stack<DiagnosticDescriptor> opened = new Stack<DiagnosticDescriptor>();
      ListIterator<DiagnosticDescriptor> iterator = diagnosticDescriptors.listIterator();
      DiagnosticDescriptor currentDescriptor = iterator.next();

      for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        while (!opened.isEmpty() && i == opened.peek().end) {
          closeDiagnosticString(result);
          opened.pop();
        }
        while (currentDescriptor != null && i == currentDescriptor.start) {
          openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic);
          if (currentDescriptor.getEnd() == i) {
            closeDiagnosticString(result);
          } else {
            opened.push(currentDescriptor);
          }
          if (iterator.hasNext()) {
            currentDescriptor = iterator.next();
          } else {
            currentDescriptor = null;
          }
        }
        result.append(c);
      }

      if (currentDescriptor != null) {
        assert currentDescriptor.start == text.length();
        assert currentDescriptor.end == text.length();
        openDiagnosticsString(result, currentDescriptor, diagnosticToExpectedDiagnostic);
        opened.push(currentDescriptor);
      }

      while (!opened.isEmpty() && text.length() == opened.peek().end) {
        closeDiagnosticString(result);
        opened.pop();
      }

      assert opened.isEmpty() : "Stack is not empty: " + opened;
    } else {
      result.append(text);
    }
    return result;
  }
コード例 #8
0
 private SignatureVisitor signatureVisitor() {
   return !visitors.isEmpty() ? visitors.peek() : signatureVisitor;
 }
コード例 #9
0
  @SuppressWarnings("unchecked")
  private static <E extends ArrangementEntry> void doArrange(Context<E> context) {
    // The general idea is to process entries bottom-up where every processed group belongs to the
    // same parent. We may not bother
    // with entries text ranges then. We use a list and a stack for achieving that than.
    //
    // Example:
    //            Entry1              Entry2
    //            /    \              /    \
    //      Entry11   Entry12    Entry21  Entry22
    //
    //    --------------------------
    //    Stage 1:
    //      list: Entry1 Entry2    <-- entries to process
    //      stack: [0, 0, 2]       <-- holds current iteration info at the following format:
    //                                 (start entry index at the auxiliary list (inclusive); current
    // index; end index (exclusive))
    //    --------------------------
    //    Stage 2:
    //      list: Entry1 Entry2 Entry11 Entry12
    //      stack: [0, 1, 2]
    //             [2, 2, 4]
    //    --------------------------
    //    Stage 3:
    //      list: Entry1 Entry2 Entry11 Entry12
    //      stack: [0, 1, 2]
    //             [2, 3, 4]
    //    --------------------------
    //    Stage 4:
    //      list: Entry1 Entry2 Entry11 Entry12
    //      stack: [0, 1, 2]
    //             [2, 4, 4]
    //    --------------------------
    //      arrange 'Entry11 Entry12'
    //    --------------------------
    //    Stage 5:
    //      list: Entry1 Entry2
    //      stack: [0, 1, 2]
    //    --------------------------
    //    Stage 6:
    //      list: Entry1 Entry2 Entry21 Entry22
    //      stack: [0, 2, 2]
    //             [2, 2, 4]
    //    --------------------------
    //    Stage 7:
    //      list: Entry1 Entry2 Entry21 Entry22
    //      stack: [0, 2, 2]
    //             [2, 3, 4]
    //    --------------------------
    //    Stage 8:
    //      list: Entry1 Entry2 Entry21 Entry22
    //      stack: [0, 2, 2]
    //             [2, 4, 4]
    //    --------------------------
    //      arrange 'Entry21 Entry22'
    //    --------------------------
    //    Stage 9:
    //      list: Entry1 Entry2
    //      stack: [0, 2, 2]
    //    --------------------------
    //      arrange 'Entry1 Entry2'

    List<ArrangementEntryWrapper<E>> entries = new ArrayList<ArrangementEntryWrapper<E>>();
    Stack<StackEntry> stack = new Stack<StackEntry>();
    entries.addAll(context.wrappers);
    stack.push(new StackEntry(0, context.wrappers.size()));
    while (!stack.isEmpty()) {
      StackEntry stackEntry = stack.peek();
      if (stackEntry.current >= stackEntry.end) {
        List<ArrangementEntryWrapper<E>> subEntries =
            entries.subList(stackEntry.start, stackEntry.end);
        if (subEntries.size() > 1) {
          doArrange(subEntries, context);
        }
        subEntries.clear();
        stack.pop();
      } else {
        ArrangementEntryWrapper<E> wrapper = entries.get(stackEntry.current++);
        List<ArrangementEntryWrapper<E>> children = wrapper.getChildren();
        if (!children.isEmpty()) {
          entries.addAll(children);
          stack.push(new StackEntry(stackEntry.end, children.size()));
        }
      }
    }
  }
コード例 #10
0
 @Override
 public DfaValue peek() {
   return myStack.peek();
 }