diff --git a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java index 3338241e705a..c68f20e07082 100644 --- a/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java +++ b/platform/core-impl/src/com/intellij/lang/impl/PsiBuilderImpl.java @@ -1152,8 +1152,8 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { } private void balanceWhiteSpaces() { - RelativeTokenTypesView wsTokens = null; - RelativeTokenTextView tokenTextGetter = null; + RelativeTokenTypesView wsTokens = new RelativeTokenTypesView(); + RelativeTokenTextView tokenTextGetter = new RelativeTokenTextView(); for (int i = 1, size = myProduction.size() - 1; i < size; i++) { final ProductionMarker item = myProduction.get(i); @@ -1162,54 +1162,50 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder { LOG.error(UNBALANCED_MESSAGE); } - final int prevProductionLexIndex = myProduction.get(i - 1).myLexemeIndex; - int idx = item.myLexemeIndex; - while (idx > prevProductionLexIndex && whitespaceOrComment(myLexTypes[idx - 1])) idx--; - final int wsStartIndex = idx; - + int prevProductionLexIndex = myProduction.get(i - 1).myLexemeIndex; + int wsStartIndex = item.myLexemeIndex; + while (wsStartIndex > prevProductionLexIndex && whitespaceOrComment(myLexTypes[wsStartIndex - 1])) wsStartIndex--; int wsEndIndex = item.myLexemeIndex; while (wsEndIndex < myLexemeCount && whitespaceOrComment(myLexTypes[wsEndIndex])) wsEndIndex++; - if (wsTokens == null) wsTokens = new RelativeTokenTypesView(); wsTokens.configure(wsStartIndex, wsEndIndex); - final boolean atEnd = wsStartIndex == 0 || wsEndIndex == myLexemeCount; - if (tokenTextGetter == null) tokenTextGetter = new RelativeTokenTextView(); tokenTextGetter.configure(wsStartIndex); + boolean atEnd = wsStartIndex == 0 || wsEndIndex == myLexemeCount; item.myLexemeIndex = wsStartIndex + item.myEdgeTokenBinder.getEdgePosition(wsTokens, atEnd, tokenTextGetter); } } private final class RelativeTokenTypesView extends AbstractList { - private int start; - private int size; + private int myStart; + private int mySize; - private void configure(int _start, int _end) { - size = _end - _start; - start = _start; + private void configure(int start, int end) { + myStart = start; + mySize = end - start; } @Override - public IElementType get(final int index) { - return myLexTypes[start + index]; + public IElementType get(int index) { + return myLexTypes[myStart + index]; } @Override public int size() { - return size; + return mySize; } } private final class RelativeTokenTextView implements WhitespacesAndCommentsBinder.TokenTextGetter { - private int start; + private int myStart; - private void configure(int _start) { - start = _start; + private void configure(int start) { + myStart = start; } @Override - public CharSequence get(final int i) { - return myText.subSequence(myLexStarts[start + i], myLexStarts[start + i + 1]); + public CharSequence get(int i) { + return myText.subSequence(myLexStarts[myStart + i], myLexStarts[myStart + i + 1]); } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/text/DiffLog.java b/platform/core-impl/src/com/intellij/psi/impl/source/text/DiffLog.java index d41138043e95..386fb2dea0e9 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/text/DiffLog.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/text/DiffLog.java @@ -39,8 +39,7 @@ import java.util.List; * User: cdr */ public class DiffLog implements DiffTreeChangeBuilder { - public DiffLog() { - } + public DiffLog() { } private abstract static class LogEntry { protected LogEntry() { @@ -58,7 +57,6 @@ public class DiffLog implements DiffTreeChangeBuilder { entry.doActualPsiChange(file, astDiffBuilder); } file.subtreeChanged(); - return astDiffBuilder.getEvent(); } @@ -83,7 +81,6 @@ public class DiffLog implements DiffTreeChangeBuilder { @Override public void nodeDeleted(@NotNull ASTNode oldParent, @NotNull ASTNode oldNode) { myEntries.add(new DeleteEntry(oldParent, oldNode)); - } @Override @@ -126,14 +123,12 @@ public class DiffLog implements DiffTreeChangeBuilder { astDiffBuilder.nodeReplaced(oldNode, newNode); - ///////////////// ((TreeElement)newNode).clearCaches(); if (!(newNode instanceof FileElement)) { ((CompositeElement)newNode.getTreeParent()).subtreeChanged(); } DebugUtil.checkTreeStructure(parent); - } } @@ -168,7 +163,6 @@ public class DiffLog implements DiffTreeChangeBuilder { ((CompositeElement)parent).subtreeChanged(); DebugUtil.checkTreeStructure(parent); - } } @@ -222,7 +216,6 @@ public class DiffLog implements DiffTreeChangeBuilder { DebugUtil.checkTreeStructure(myOldParent); } - } private static PsiElement getPsi(ASTNode node, PsiFile file) { diff --git a/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java b/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java index 5a47fdf4c5f3..cb83db5711f9 100644 --- a/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java +++ b/platform/platform-tests/testSrc/com/intellij/lang/PsiBuilderQuickTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +18,14 @@ package com.intellij.lang; import com.intellij.lang.impl.PsiBuilderImpl; import com.intellij.lexer.Lexer; import com.intellij.lexer.LexerBase; +import com.intellij.openapi.fileTypes.PlainTextParserDefinition; import com.intellij.openapi.project.Project; -import com.intellij.psi.FileViewProvider; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.impl.DebugUtil; import com.intellij.psi.impl.source.tree.ASTStructure; import com.intellij.psi.tree.*; -import com.intellij.testFramework.LightPlatformTestCase; -import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.LightPlatformLangTestCase; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.ThreeState; import com.intellij.util.diff.DiffTree; import com.intellij.util.diff.DiffTreeChangeBuilder; @@ -36,12 +34,9 @@ import com.intellij.util.diff.ShallowNodeComparator; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; import java.util.List; -public class PsiBuilderQuickTest extends LightPlatformTestCase { +public class PsiBuilderQuickTest extends LightPlatformLangTestCase { private static final IFileElementType ROOT = new IFileElementType("ROOT", Language.ANY); private static final IElementType LETTER = new IElementType("LETTER", Language.ANY); @@ -57,11 +52,6 @@ public class PsiBuilderQuickTest extends LightPlatformTestCase { private static final TokenSet WHITESPACE_SET = TokenSet.create(TokenType.WHITE_SPACE); private static final TokenSet COMMENT_SET = TokenSet.create(COMMENT); - @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") - public PsiBuilderQuickTest() { - PlatformTestCase.initPlatformLangPrefix(); - } - public void testPlain() { doTest("a< { final FlyweightCapableTreeStructure newTree, final ShallowNodeComparator comparator, final DiffTreeChangeBuilder consumer) { - myOldTree = oldTree; myNewTree = newTree; myComparator = comparator; @@ -53,7 +51,7 @@ public class DiffTree { new DiffTree(oldTree, newTree, comparator, consumer).build(oldTree.getRoot(), newTree.getRoot(), 0); } - private static enum CompareResult { + private enum CompareResult { EQUAL, // 100% equal DRILL_DOWN_NEEDED, // element types are equal, but elements are composite TYPE_ONLY, // only element types are equal @@ -146,6 +144,7 @@ public class DiffTree { newIndex++; continue; } + CompareResult c12 = looksEqual(comparator, oldChild1, newChild2); if (c12 == CompareResult.EQUAL || c12 == CompareResult.DRILL_DOWN_NEEDED || c12 == CompareResult.TYPE_ONLY) { myConsumer.nodeInserted(oldNode, newChild1, newIndex); @@ -170,6 +169,7 @@ public class DiffTree { oldIndex++; continue; } + myConsumer.nodeReplaced(oldChild1, newChild1); oldIndex++; newIndex++;