mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
removed classes relevant to old parsing (we still need to fix old xml one)
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.psi.impl.source;
|
||||
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.lexer.LexerUtil;
|
||||
import com.intellij.util.CharTable;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class ParsingContext {
|
||||
private final CharTable myTable;
|
||||
|
||||
public ParsingContext(final CharTable table) {
|
||||
myTable = table;
|
||||
}
|
||||
|
||||
public CharTable getCharTable() {
|
||||
return myTable;
|
||||
}
|
||||
|
||||
public CharSequence tokenText(Lexer lexer) {
|
||||
return LexerUtil.internToken(lexer, myTable);
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.psi.impl.source.parsing;
|
||||
|
||||
import com.intellij.lang.ASTFactory;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.impl.source.ParsingContext;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
public abstract class DefaultWhiteSpaceTokenProcessorImpl implements TokenProcessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.parsing.DefaultWhiteSpaceTokenProcessorImpl");
|
||||
|
||||
@Override
|
||||
public boolean isTokenValid(IElementType tokenType) {
|
||||
return tokenType != null && isInSet(tokenType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeElement process(Lexer lexer, ParsingContext context) {
|
||||
TreeElement first = null;
|
||||
TreeElement last = null;
|
||||
while (isTokenValid(lexer.getTokenType())) {
|
||||
TreeElement tokenElement = ASTFactory.leaf(lexer.getTokenType(), context.tokenText(lexer));
|
||||
IElementType type = lexer.getTokenType();
|
||||
|
||||
if (!isInSet(type)) {
|
||||
LOG.error("Missed token should be white space or comment:" + tokenElement + "; type:" + type);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (last != null) {
|
||||
last.rawInsertAfterMe(tokenElement);
|
||||
last = tokenElement;
|
||||
}
|
||||
else {
|
||||
first = last = tokenElement;
|
||||
}
|
||||
lexer.advance();
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
protected abstract boolean isInSet(final IElementType type);
|
||||
}
|
||||
-173
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.psi.impl.source.parsing;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.psi.impl.source.ParsingContext;
|
||||
import com.intellij.psi.impl.source.tree.CompositeElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafElement;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.impl.source.tree.TreeUtil;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.ILazyParseableElementType;
|
||||
|
||||
public class MissingTokenInserter {
|
||||
protected final CompositeElement myRoot;
|
||||
protected final Lexer myLexer;
|
||||
private final int myStartOffset;
|
||||
private final int myEndOffset;
|
||||
private final int myState;
|
||||
private final TokenProcessor myProcessor;
|
||||
private final ParsingContext myContext;
|
||||
|
||||
public MissingTokenInserter(final CompositeElement root,
|
||||
final Lexer lexer,
|
||||
final int startOffset,
|
||||
final int endOffset,
|
||||
final int state,
|
||||
final TokenProcessor processor,
|
||||
final ParsingContext context) {
|
||||
myRoot = root;
|
||||
myLexer = lexer;
|
||||
myStartOffset = startOffset;
|
||||
myEndOffset = endOffset;
|
||||
myState = state;
|
||||
myProcessor = processor;
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public void invoke() {
|
||||
if (myState < 0) {
|
||||
myLexer.start(myLexer.getBufferSequence(), myStartOffset, myEndOffset);
|
||||
}
|
||||
else {
|
||||
myLexer.start(myLexer.getBufferSequence(), myStartOffset, myEndOffset, myState);
|
||||
}
|
||||
|
||||
TreeElement leaf = TreeUtil.findFirstLeafOrChameleon(myRoot);
|
||||
if (leaf == null) {
|
||||
final TreeElement firstMissing = myProcessor.process(myLexer, myContext);
|
||||
if (firstMissing != null) {
|
||||
myRoot.rawAddChildren(firstMissing);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Missing in the beginning
|
||||
final IElementType tokenType = getNextTokenType();
|
||||
if (tokenType != leaf.getElementType() && myProcessor.isTokenValid(tokenType)) {
|
||||
final TreeElement firstMissing = myProcessor.process(myLexer, myContext);
|
||||
if (firstMissing != null) {
|
||||
myRoot.getFirstChildNode().rawInsertBeforeMe(firstMissing);
|
||||
}
|
||||
}
|
||||
passTokenOrChameleon(leaf);
|
||||
}
|
||||
// Missing in tree body
|
||||
insertMissingTokensInTreeBody(leaf);
|
||||
if (myLexer.getTokenType() != null) {
|
||||
// whitespaces at the end of the file
|
||||
final TreeElement firstMissing = myProcessor.process(myLexer, myContext);
|
||||
if (firstMissing != null) {
|
||||
ASTNode current = myRoot;
|
||||
while (current instanceof CompositeElement) {
|
||||
if (current.getUserData(TreeUtil.UNCLOSED_ELEMENT_PROPERTY) != null) break;
|
||||
current = current.getLastChildNode();
|
||||
}
|
||||
if (current instanceof CompositeElement) {
|
||||
((CompositeElement)current).rawAddChildren(firstMissing);
|
||||
}
|
||||
else {
|
||||
myRoot.getLastChildNode().rawInsertAfterMe(firstMissing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected IElementType getNextTokenType() {
|
||||
return myLexer.getTokenType();
|
||||
}
|
||||
|
||||
private void insertMissingTokensInTreeBody(TreeElement leaf) {
|
||||
final TreeUtil.CommonParentState commonParents = new TreeUtil.CommonParentState();
|
||||
while (leaf != null) {
|
||||
commonParents.strongWhiteSpaceHolder = null;
|
||||
final IElementType tokenType = getNextTokenType();
|
||||
final TreeElement next = TreeUtil.nextLeaf(leaf, commonParents, tokenType instanceof ILazyParseableElementType ? tokenType : null, false);
|
||||
|
||||
if (next == null || tokenType == null) break;
|
||||
if (tokenType != next.getElementType() && myProcessor.isTokenValid(tokenType)) {
|
||||
final TreeElement firstMissing = myProcessor.process(myLexer, myContext);
|
||||
final CompositeElement unclosedElement = commonParents.strongWhiteSpaceHolder;
|
||||
if (unclosedElement != null) {
|
||||
if (commonParents.isStrongElementOnRisingSlope || unclosedElement.getFirstChildNode() == null) {
|
||||
unclosedElement.rawAddChildren(firstMissing);
|
||||
}
|
||||
else {
|
||||
unclosedElement.getFirstChildNode().rawInsertBeforeMe(firstMissing);
|
||||
}
|
||||
}
|
||||
else {
|
||||
final ASTNode insertBefore = commonParents.nextLeafBranchStart;
|
||||
TreeElement insertAfter = commonParents.startLeafBranchStart;
|
||||
TreeElement current = commonParents.startLeafBranchStart;
|
||||
while (current != insertBefore) {
|
||||
final TreeElement treeNext = current.getTreeNext();
|
||||
if (treeNext == insertBefore) {
|
||||
insertAfter = current;
|
||||
break;
|
||||
}
|
||||
if (isInsertAfterElement(treeNext)) {
|
||||
insertAfter = current;
|
||||
break;
|
||||
}
|
||||
if (treeNext.getUserData(TreeUtil.UNCLOSED_ELEMENT_PROPERTY) != null) {
|
||||
insertAfter = null;
|
||||
((CompositeElement)treeNext).rawAddChildren(firstMissing);
|
||||
break;
|
||||
}
|
||||
current = treeNext;
|
||||
}
|
||||
if (insertAfter != null) insertAfter.rawInsertAfterMe(firstMissing);
|
||||
}
|
||||
}
|
||||
passTokenOrChameleon(next);
|
||||
leaf = next;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isInsertAfterElement(TreeElement treeNext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void passTokenOrChameleon(final ASTNode node) {
|
||||
if (node instanceof LeafElement && node instanceof OuterLanguageElement
|
||||
|| TreeUtil.isCollapsedChameleon(node)) {
|
||||
final int endOfChameleon = node.getTextLength() + myLexer.getTokenStart();
|
||||
while (myLexer.getTokenType() != null && myLexer.getTokenEnd() < endOfChameleon) {
|
||||
myLexer.advance();
|
||||
}
|
||||
}
|
||||
advanceLexer(node);
|
||||
}
|
||||
|
||||
protected void advanceLexer(final ASTNode next) {
|
||||
myLexer.advance();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.psi.impl.source.parsing;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.intellij.psi.impl.source.tree.TreeElement;
|
||||
import com.intellij.psi.impl.source.ParsingContext;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.lexer.Lexer;
|
||||
|
||||
public interface TokenProcessor {
|
||||
@Nullable
|
||||
TreeElement process(Lexer lexer, ParsingContext context);
|
||||
|
||||
boolean isTokenValid(IElementType tokenType);
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import com.intellij.lexer.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.impl.source.DummyHolderFactory;
|
||||
import com.intellij.psi.impl.source.ParsingContext;
|
||||
import com.intellij.psi.impl.source.parsing.TokenProcessor;
|
||||
import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.templateLanguages.OuterLanguageElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -49,10 +47,10 @@ public class OldXmlParsing implements XmlElementType {
|
||||
public static final TokenSet XML_COMMENT_BIT_SET =
|
||||
TokenSet.create(new IElementType[]{XML_COMMENT_START, XML_COMMENT_CHARACTERS, XML_COMMENT_END});
|
||||
|
||||
private final ParsingContext myContext;
|
||||
private final XmlParsingContext myContext;
|
||||
private int myLastTokenEnd = -1;
|
||||
|
||||
public OldXmlParsing(ParsingContext context) {
|
||||
public OldXmlParsing(XmlParsingContext context) {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
@@ -931,13 +929,13 @@ public class OldXmlParsing implements XmlElementType {
|
||||
}
|
||||
}
|
||||
|
||||
public static class WhiteSpaceAndCommentsProcessor implements TokenProcessor {
|
||||
public static final TokenProcessor INSTANCE = new WhiteSpaceAndCommentsProcessor();
|
||||
public static class WhiteSpaceAndCommentsProcessor {
|
||||
public static final WhiteSpaceAndCommentsProcessor INSTANCE = new WhiteSpaceAndCommentsProcessor();
|
||||
|
||||
private WhiteSpaceAndCommentsProcessor() {
|
||||
}
|
||||
|
||||
public TreeElement process(Lexer lexer, ParsingContext context) {
|
||||
public TreeElement process(Lexer lexer, XmlParsingContext context) {
|
||||
TreeElement first = null;
|
||||
TreeElement last = null;
|
||||
while (isTokenValid(lexer.getTokenType())) {
|
||||
@@ -972,7 +970,7 @@ public class OldXmlParsing implements XmlElementType {
|
||||
return tokenType != null && XML_WHITE_SPACE_OR_COMMENT_BIT_SET.contains(tokenType);
|
||||
}
|
||||
|
||||
private TreeElement parseComment(Lexer lexer, ParsingContext context) {
|
||||
private TreeElement parseComment(Lexer lexer, XmlParsingContext context) {
|
||||
final CompositeElement comment = ASTFactory.composite(XML_COMMENT);
|
||||
|
||||
while (lexer.getTokenType() != null && XML_COMMENT_BIT_SET.contains(lexer.getTokenType())) {
|
||||
@@ -990,8 +988,8 @@ public class OldXmlParsing implements XmlElementType {
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
int state,
|
||||
TokenProcessor processor,
|
||||
ParsingContext context) {
|
||||
WhiteSpaceAndCommentsProcessor processor,
|
||||
XmlParsingContext context) {
|
||||
if (state < 0) {
|
||||
lexer.start(lexer.getBufferSequence(), startOffset, endOffset);
|
||||
}
|
||||
@@ -1039,9 +1037,9 @@ public class OldXmlParsing implements XmlElementType {
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertMissingTokensInTreeBody(TreeElement leaf, Lexer lexer,
|
||||
TokenProcessor processor,
|
||||
ParsingContext context,
|
||||
private static void insertMissingTokensInTreeBody(TreeElement leaf, Lexer lexer,
|
||||
WhiteSpaceAndCommentsProcessor processor,
|
||||
XmlParsingContext context,
|
||||
ASTNode endToken) {
|
||||
final TreeUtil.CommonParentState commonParents = new TreeUtil.CommonParentState();
|
||||
while (leaf != null) {
|
||||
|
||||
@@ -15,21 +15,31 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.parsing.xml;
|
||||
|
||||
import com.intellij.psi.impl.source.ParsingContext;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.lexer.LexerUtil;
|
||||
import com.intellij.util.CharTable;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class XmlParsingContext extends ParsingContext {
|
||||
protected final OldXmlParsing myXmlParsing;
|
||||
public class XmlParsingContext {
|
||||
private final OldXmlParsing myXmlParsing;
|
||||
private final CharTable myTable;
|
||||
|
||||
public XmlParsingContext(final CharTable table) {
|
||||
myTable = table;
|
||||
myXmlParsing = new OldXmlParsing(this);
|
||||
}
|
||||
|
||||
public CharTable getCharTable() {
|
||||
return myTable;
|
||||
}
|
||||
|
||||
public CharSequence tokenText(Lexer lexer) {
|
||||
return LexerUtil.internToken(lexer, myTable);
|
||||
}
|
||||
|
||||
public OldXmlParsing getXmlParsing() {
|
||||
return myXmlParsing;
|
||||
}
|
||||
|
||||
public XmlParsingContext(final CharTable table) {
|
||||
super(table);
|
||||
myXmlParsing = new OldXmlParsing(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user