Java源码示例:com.intellij.util.containers.Stack
示例1
@NotNull
public Map<Integer, LogicalPositionSignature> signaturesByLines(@NotNull Language lang) {
Map<Integer, LogicalPositionSignature> result = new THashMap<>();
for (Stack<OpenModule> openStack : m_opens.values()) {
for (OpenModule openModule : openStack) {
String exposing = openModule.getExposing();
if (exposing != null) {
result.put(openModule.getLine(), makeLogicalPositionSignature(0, 0, exposing));
}
}
}
for (Map.Entry<Integer, LogicalORSignature> entry : m_vals.entrySet()) {
result.put(entry.getKey(), makeLogicalPositionSignature(lang, entry.getValue()));
}
return result;
}
示例2
private boolean reevaluate(Project context) {
this.context = context;
boolean ret = false;
if (isComplete()) {
try {
Stack<ASTNode> rpn = infixToRPN();
String rpnString = LOG.isDebugEnabled() ? tokensToString(rpn) : null;
ret = objectIsTrue(calculateRPN(rpn));
if (LOG.isDebugEnabled()) { // Don't create the strings unless we are debugging them...
LOG.debug(toString() + " --> " + rpnString + " ==> " + (ret ? "true" : "false"));
}
if (!rpn.isEmpty()) {
throw new CalculationException("Invalid Expression: Tokens left after calculating: " + rpn.toString());
}
} catch (CalculationException e) {
String msg = "Error calculating conditional compiler expression '" + toString() + "'";
// Add stack info if in debug mode.
LOG.info( msg, LOG.isDebugEnabled() ? e : null );
}
}
return ret;
}
示例3
@SuppressWarnings("unchecked")
private <T> void ensureTheDataIsReadyToUse(@Nonnull Collection<DataNode<T>> nodes) {
Map<Key<?>, List<ProjectDataService<?, ?>>> servicesByKey = myServices.getValue();
Stack<DataNode<T>> toProcess = ContainerUtil.newStack(nodes);
while (!toProcess.isEmpty()) {
DataNode<T> node = toProcess.pop();
List<ProjectDataService<?, ?>> services = servicesByKey.get(node.getKey());
if (services != null) {
for (ProjectDataService<?, ?> service : services) {
node.prepareData(service.getClass().getClassLoader());
}
}
for (DataNode<?> dataNode : node.getChildren()) {
toProcess.push((DataNode<T>)dataNode);
}
}
}
示例4
public static void enterModal(Project project, Dialog dialog) {
LOG.assertTrue(isDispatchThread(), "enterModal() should be invoked in event-dispatch thread");
if (LOG.isDebugEnabled()) {
LOG.debug("enterModal:" + dialog.getName() + " ; for project: " + project.getName());
}
if (project == null) {
enterModal(dialog);
return;
}
ourModalityStateMulticaster.getMulticaster().beforeModalityStateChanged(true);
List<Dialog> modalEntitiesList = projectToModalEntities.getOrDefault(project, ContainerUtil.createLockFreeCopyOnWriteList());
projectToModalEntities.put(project, modalEntitiesList);
modalEntitiesList.add(dialog);
Stack<ModalityState> modalEntitiesStack = projectToModalEntitiesStack.getOrDefault(project, new Stack<>(ModalityState.NON_MODAL));
projectToModalEntitiesStack.put(project, modalEntitiesStack);
modalEntitiesStack.push(new ModalityStateEx(ArrayUtil.toObjectArray(ourModalEntities)));
}
示例5
@Nullable
private Pair<PomModelAspect, PomTransaction> getBlockingTransaction(final PomModelAspect aspect, PomTransaction transaction) {
final List<PomModelAspect> allDependants = getAllDependants(aspect);
for (final PomModelAspect pomModelAspect : allDependants) {
Stack<Pair<PomModelAspect, PomTransaction>> blockedAspects = myBlockedAspects.get();
ListIterator<Pair<PomModelAspect, PomTransaction>> blocksIterator = blockedAspects.listIterator(blockedAspects.size());
while (blocksIterator.hasPrevious()) {
final Pair<PomModelAspect, PomTransaction> pair = blocksIterator.previous();
if (pomModelAspect == pair.getFirst() && // aspect dependence
PsiTreeUtil.isAncestor(getContainingFileByTree(pair.getSecond().getChangeScope()), transaction.getChangeScope(), false) // same file
) {
return pair;
}
}
}
return null;
}
示例6
public void initStateFrom(@Nonnull final ProgressIndicator indicator) {
synchronized (getLock()) {
myRunning = indicator.isRunning();
myCanceled = indicator.isCanceled();
myFraction = indicator.getFraction();
myIndeterminate = indicator.isIndeterminate();
myText = indicator.getText();
myText2 = indicator.getText2();
myFraction = indicator.getFraction();
if (indicator instanceof AbstractProgressIndicatorBase) {
AbstractProgressIndicatorBase stacked = (AbstractProgressIndicatorBase)indicator;
myTextStack = stacked.myTextStack == null ? null : new Stack<>(stacked.getTextStack());
myText2Stack = stacked.myText2Stack == null ? null : new Stack<>(stacked.getText2Stack());
myFractionStack = stacked.myFractionStack == null ? null : new TDoubleArrayList(stacked.getFractionStack().toNativeArray());
}
dontStartActivity();
}
}
示例7
public static void leaveModal(Project project, Dialog dialog) {
LOG.assertTrue(isDispatchThread(), "leaveModal() should be invoked in event-dispatch thread");
if (LOG.isDebugEnabled()) {
LOG.debug("leaveModal:" + dialog.getName() + " ; for project: " + project.getName());
}
ourModalityStateMulticaster.getMulticaster().beforeModalityStateChanged(false);
int index = ourModalEntities.indexOf(dialog);
if (index != -1) {
ourModalEntities.remove(index);
ourModalityStack.remove(index + 1);
for (int i = 1; i < ourModalityStack.size(); i++) {
ourModalityStack.get(i).removeModality(dialog);
}
}
else if (project != null) {
List<Dialog> dialogs = projectToModalEntities.get(project);
int perProjectIndex = dialogs.indexOf(dialog);
LOG.assertTrue(perProjectIndex >= 0);
dialogs.remove(perProjectIndex);
Stack<ModalityState> states = projectToModalEntitiesStack.get(project);
states.remove(perProjectIndex + 1);
for (int i = 1; i < states.size(); i++) {
((ModalityStateEx)states.get(i)).removeModality(dialog);
}
}
reincludeSkippedItems();
requestFlush();
}
示例8
public static int findLeftmostLParen(HighlighterIterator iterator,
IElementType lparenTokenType,
CharSequence fileText,
FileType fileType) {
int lastLbraceOffset = -1;
Stack<IElementType> braceStack = new Stack<IElementType>();
for (; !iterator.atEnd(); iterator.retreat()) {
final IElementType tokenType = iterator.getTokenType();
if (isLBraceToken(iterator, fileText, fileType)) {
if (!braceStack.isEmpty()) {
IElementType topToken = braceStack.pop();
if (!isPairBraces(tokenType, topToken, fileType)) {
break; // unmatched braces
}
}
else {
if (tokenType == lparenTokenType) {
lastLbraceOffset = iterator.getStart();
}
else {
break;
}
}
}
else if (isRBraceToken(iterator, fileText, fileType)) {
braceStack.push(iterator.getTokenType());
}
}
return lastLbraceOffset;
}
示例9
public static int findLeftLParen(HighlighterIterator iterator,
IElementType lparenTokenType,
CharSequence fileText,
FileType fileType) {
int lastLbraceOffset = -1;
Stack<IElementType> braceStack = new Stack<IElementType>();
for (; !iterator.atEnd(); iterator.retreat()) {
final IElementType tokenType = iterator.getTokenType();
if (isLBraceToken(iterator, fileText, fileType)) {
if (!braceStack.isEmpty()) {
IElementType topToken = braceStack.pop();
if (!isPairBraces(tokenType, topToken, fileType)) {
break; // unmatched braces
}
}
else {
if (tokenType == lparenTokenType) {
return iterator.getStart();
}
else {
break;
}
}
}
else if (isRBraceToken(iterator, fileText, fileType)) {
braceStack.push(iterator.getTokenType());
}
}
return lastLbraceOffset;
}
示例10
public static int findRightmostRParen(HighlighterIterator iterator,
IElementType rparenTokenType,
CharSequence fileText,
FileType fileType) {
int lastRbraceOffset = -1;
Stack<IElementType> braceStack = new Stack<IElementType>();
for (; !iterator.atEnd(); iterator.advance()) {
final IElementType tokenType = iterator.getTokenType();
if (isRBraceToken(iterator, fileText, fileType)) {
if (!braceStack.isEmpty()) {
IElementType topToken = braceStack.pop();
if (!isPairBraces(tokenType, topToken, fileType)) {
break; // unmatched braces
}
}
else {
if (tokenType == rparenTokenType) {
lastRbraceOffset = iterator.getStart();
}
else {
break;
}
}
}
else if (isLBraceToken(iterator, fileText, fileType)) {
braceStack.push(iterator.getTokenType());
}
}
return lastRbraceOffset;
}
示例11
AdjustFormatRangesState(Block currentRoot, FormatTextRanges formatRanges, FormattingDocumentModel model) {
myModel = model;
myFormatRanges = formatRanges;
myExtendedRanges = formatRanges.getExtendedRanges();
state = new Stack<>(currentRoot);
setOnDone(() -> totalNewRanges.forEach(range -> myFormatRanges.add(range, false)));
}
示例12
@NotNull
public String convert(@NotNull String text) {
m_lexer.reset(text, 0, text.length() - 1, ODocLexer.YYINITIAL);
m_builder.append("<p>");
Stack<String> scopes = new Stack<>();
boolean inPre = false;
boolean inLink = false;
try {
IElementType previousVisibleTokenType = null;
IElementType tokenType = m_lexer.advance();
while (true) {
if (tokenType == null) {
break;
}
//System.out.println(tokenType.toString() + " : " + m_lexer.yytext());
if (!m_paragraphStarted && tokenType != ODocTypes.NEW_LINE && tokenType != TokenType.WHITE_SPACE) {
m_paragraphStarted = true;
m_builder.append("<p>");
}
//noinspection StatementWithEmptyBody
if (tokenType == ODocTypes.OCL_START || tokenType == ODocTypes.OCL_END || tokenType == ODocTypes.RML_START || tokenType == ODocTypes.RML_END) {
// skip
} else if (tokenType == ODocTypes.CODE) {
m_builder.append(CODE_START).append(extract(m_lexer.yytext(), 1, 1)).append(CODE_END);
} else if (tokenType == ODocTypes.BOLD) {
m_builder.append("<b>").append(extract(m_lexer.yytext(), 2, 1)).append("</b>");
} else if (tokenType == ODocTypes.ITALIC) {
m_builder.append("<i>").append(extract(m_lexer.yytext(), 2, 1)).append("</i>");
} else if (tokenType == ODocTypes.EMPHASIS) {
m_builder.append("<em>").append(extract(m_lexer.yytext(), 2, 1)).append("</em>");
} else if (tokenType == ODocTypes.CROSS_REF) {
String link = extract(m_lexer.yytext(), 2, 1);
m_builder.append("<a href=\")").append(link).append("\">").append(link).append("</a>");
} else if (tokenType == ODocTypes.O_LIST) {
m_builder.append("<ol>");
scopes.add("</ol>");
} else if (tokenType == ODocTypes.U_LIST) {
m_builder.append("<ul>");
scopes.add("</ul>");
} else if (tokenType == ODocTypes.LIST_ITEM) {
m_builder.append("<li>");
scopes.add("</li>");
} else if (tokenType == ODocTypes.PRE_START) {
m_builder.append("<pre>");
inPre = true;
} else if (tokenType == ODocTypes.PRE_END) {
inPre = false;
m_builder.append("</pre>");
} else if (tokenType == ODocTypes.SECTION) {
String section = "h" + extract(m_lexer.yytext(), 1);
m_builder.append("<").append(section).append(">");
scopes.add("</" + section + ">");
} else if (tokenType == ODocTypes.LINK) {
m_builder.append("<a href=\"");
inLink = true;
} else if (tokenType == ODocTypes.RBRACE) {
if (inLink) {
inLink = false;
m_builder.append("\">");
scopes.add("</a>");
} else if (!scopes.empty()) {
m_builder.append(scopes.pop());
}
} else if (tokenType == ODocTypes.NEW_LINE) {
if (inPre) {
m_builder.append("\n");
} else if (previousVisibleTokenType == ODocTypes.NEW_LINE && m_paragraphStarted) {
m_paragraphStarted = false;
m_builder.append("</p>");
}
} else {
m_builder.append(tokenType == TokenType.WHITE_SPACE ? " " : m_lexer.yytext());
}
if (tokenType != TokenType.WHITE_SPACE) {
previousVisibleTokenType = tokenType;
}
tokenType = m_lexer.advance();
}
} catch (IOException e) {
LOG.error("Error during ODoc parsing", e);
}
if (m_paragraphStarted) {
m_builder.append("</p>");
}
return m_builder.toString();
}
示例13
/**
* Converts an infix expression into an RPN expression. (Re-orders and removes parenthesis.)
* For example: !(cpp && js) -> cpp js && !
* and: (( cpp || js ) && (haxe-ver < 3)) -> cpp js || haxe-ver 3 < &&
* See https://en.wikipedia.org/wiki/Reverse_Polish_notation
* @return
* @throws CalculationException
*/
private Stack<ASTNode> infixToRPN() throws CalculationException {
// This is a simplified shunting-yard algorithm: http://https://en.wikipedia.org/wiki/Shunting-yard_algorithm
Stack<ASTNode> rpnOutput = new Stack<ASTNode>();
Stack<ASTNode> operatorStack = new Stack<ASTNode>();
try {
for (ASTNode token : tokens) {
if (isWhitespace(token)) {
continue;
}
if (isLiteral(token) || isStringQuote(token) || isString(token)) {
rpnOutput.push(token);
}
else if (isLeftParen(token)) {
operatorStack.push(token);
}
else if (isRightParen(token)) {
boolean foundLeftParen = false;
while (!operatorStack.isEmpty()) {
ASTNode op = operatorStack.pop();
if (!isLeftParen(op)) {
rpnOutput.push(op);
}
else {
foundLeftParen = true;
break;
}
}
if (operatorStack.isEmpty() && !foundLeftParen) {
// mismatched parens.
// TODO: Report errors back through a reporter class.
throw new CalculationException("Mismatched right parenthesis.");
}
}
else if (isCCOperator(token)) {
while (!operatorStack.isEmpty()
&& !isLeftParen(operatorStack.peek()) // Parens have the highest priority, but should not be considered for comparison.
&& HaxeOperatorPrecedenceTable.shuntingYardCompare(token.getElementType(), operatorStack.peek().getElementType())) {
rpnOutput.push(operatorStack.pop());
}
operatorStack.push(token);
}
else {
throw new CalculationException("Couldn't process token '" + token.toString() + "' when converting to RPN.");
}
}
} catch (HaxeOperatorPrecedenceTable.OperatorNotFoundException e) {
LOG.warn("IntelliJ-Haxe plugin internal error: Unknown operator encountered while calculating compiler conditional exression:"
+ toString(), e);
throw new CalculationException(e.toString());
}
// Anything left in the operator stack means an error.
while(!operatorStack.isEmpty()) {
ASTNode node = operatorStack.pop();
if (isLeftParen(node)) {
// Mismatched parens.
// TODO: Report errors back through a reporter class.
throw new CalculationException("Mismatched left parenthesis.");
} else {
rpnOutput.push(node);
}
}
return rpnOutput;
}
示例14
public PreorderEnumeration(@Nonnull final TreeModel treeModel) {
myTreeModel = treeModel;
myStack = new Stack<Enumeration>();
myStack.push(Collections.enumeration(Collections.singleton(treeModel.getRoot())));
}
示例15
@Nonnull
Stack<String> getTextStack();
示例16
@Nonnull
Stack<String> getText2Stack();
示例17
@Nonnull
private Stack<String> getTextStack() {
Stack<String> stack = myTextStack;
if (stack == null) myTextStack = stack = new Stack<>(2);
return stack;
}
示例18
@Nonnull
private Stack<String> getText2Stack() {
Stack<String> stack = myText2Stack;
if (stack == null) myText2Stack = stack = new Stack<>(2);
return stack;
}
示例19
protected void buildStubTree(@Nonnull LighterAST tree, @Nonnull LighterASTNode root, @Nonnull StubElement rootStub) {
final Stack<LighterASTNode> parents = new Stack<>();
final TIntStack childNumbers = new TIntStack();
final BooleanStack parentsStubbed = new BooleanStack();
final Stack<List<LighterASTNode>> kinderGarden = new Stack<>();
final Stack<StubElement> parentStubs = new Stack<>();
LighterASTNode parent = null;
LighterASTNode element = root;
List<LighterASTNode> children = null;
int childNumber = 0;
StubElement parentStub = rootStub;
boolean immediateParentStubbed = true;
nextElement:
while (element != null) {
ProgressManager.checkCanceled();
final StubElement stub = createStub(tree, element, parentStub);
boolean hasStub = stub != parentStub || parent == null;
if (hasStub && !immediateParentStubbed) {
((ObjectStubBase) stub).markDangling();
}
if (parent == null || !skipNode(tree, parent, element)) {
final List<LighterASTNode> kids = tree.getChildren(element);
if (!kids.isEmpty()) {
if (parent != null) {
parents.push(parent);
childNumbers.push(childNumber);
kinderGarden.push(children);
parentStubs.push(parentStub);
parentsStubbed.push(immediateParentStubbed);
}
parent = element;
immediateParentStubbed = hasStub;
element = (children = kids).get(childNumber = 0);
parentStub = stub;
if (!skipNode(tree, parent, element)) continue nextElement;
}
}
while (children != null && ++childNumber < children.size()) {
element = children.get(childNumber);
if (!skipNode(tree, parent, element)) continue nextElement;
}
element = null;
while (!parents.isEmpty()) {
parent = parents.pop();
childNumber = childNumbers.pop();
children = kinderGarden.pop();
parentStub = parentStubs.pop();
immediateParentStubbed = parentsStubbed.pop();
while (++childNumber < children.size()) {
element = children.get(childNumber);
if (!skipNode(tree, parent, element)) continue nextElement;
}
element = null;
}
}
}
示例20
public static boolean findStructuralLeftBrace(@Nonnull FileType fileType, @Nonnull HighlighterIterator iterator, @Nonnull CharSequence fileText) {
final Stack<IElementType> braceStack = new Stack<IElementType>();
final Stack<String> tagNameStack = new Stack<String>();
BraceMatcher matcher = getBraceMatcher(fileType, iterator);
while (!iterator.atEnd()) {
if (isStructuralBraceToken(fileType, iterator, fileText)) {
if (isRBraceToken(iterator, fileText, fileType)) {
braceStack.push(iterator.getTokenType());
tagNameStack.push(getTagName(matcher, fileText, iterator));
}
if (isLBraceToken(iterator, fileText, fileType)) {
if (braceStack.isEmpty()) return true;
final int group = matcher.getBraceTokenGroupId(iterator.getTokenType());
final IElementType topTokenType = braceStack.pop();
final IElementType tokenType = iterator.getTokenType();
boolean isStrict = isStrictTagMatching(matcher, fileType, group);
boolean isCaseSensitive = areTagsCaseSensitive(matcher, fileType, group);
String topTagName = null;
String tagName = null;
if (isStrict) {
topTagName = tagNameStack.pop();
tagName = getTagName(matcher, fileText, iterator);
}
if (!isPairBraces(topTokenType, tokenType, fileType)
|| isStrict && !Comparing.equal(topTagName, tagName, isCaseSensitive)) {
return false;
}
}
}
iterator.retreat();
}
return false;
}
示例21
@SuppressWarnings("unchecked")
private <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);
// arrange entries even if subEntries.size() == 1, because we don't want to miss new section comments here
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()));
}
}
}
}
示例22
/**
* Stores the {@code value} to this visitor. The stored value can be retrieved later by calling the {@link #getCurrentValue()}.
* The visitor maintains the stack of stored values. I.e:
* This value is held here only during the visiting the current file and all its children. As soon as the visitor finished with
* the current file and all its subtree and returns to the level up, the value is cleared
* and the {@link #getCurrentValue()} returns the previous value, which was stored here before this method call.
*/
public final void setValueForChildren(@Nullable T value) {
myValue = value;
if (myValueStack == null) {
myValueStack = new Stack<>();
}
}