mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
1. Ability to be notified about whitespaces being skipped by default PsiBuilder whitespace skipper.
2. Cheap lookAhead implementation for the PsiBuilder.
This commit is contained in:
@@ -313,6 +313,21 @@ public class JavaParserUtil {
|
||||
myDelegate.setTokenTypeRemapper(remapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitespaceSkippedCallback(WhitespaceSkippedCallback callback) {
|
||||
myDelegate.setWhitespaceSkippedCallback(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remapCurrentToken(IElementType type) {
|
||||
myDelegate.remapCurrentToken(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementType lookAhead(int steps) {
|
||||
return myDelegate.lookAhead(steps);
|
||||
}
|
||||
|
||||
@Nullable @NonNls
|
||||
public String getTokenText() {
|
||||
return myDelegate.getTokenText();
|
||||
@@ -374,4 +389,4 @@ public class JavaParserUtil {
|
||||
myDelegate.putUserDataUnprotected(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,25 @@ public interface PsiBuilder extends UserDataHolder, UserDataHolderUnprotected {
|
||||
*/
|
||||
void setTokenTypeRemapper(ITokenTypeRemapper remapper);
|
||||
|
||||
/**
|
||||
* Slightly easier way to what {@link ITokenTypeRemapper} does. I.e. we just remap current token to given type
|
||||
*/
|
||||
void remapCurrentToken(IElementType type);
|
||||
|
||||
/**
|
||||
* Subscribe for notification on default whitespace and comments skipped events.
|
||||
* @param callback an implementation for the callback
|
||||
*/
|
||||
void setWhitespaceSkippedCallback(WhitespaceSkippedCallback callback);
|
||||
|
||||
/**
|
||||
* See what token type is in <code>steps</code> ahead
|
||||
* @param steps 0 is current token (i.e. the same {@link PsiBuilder#getTokenType()} returns)
|
||||
* @return type element which getTokenType() will return if we call advance <code>steps</code> times in a row
|
||||
*/
|
||||
@Nullable
|
||||
IElementType lookAhead(int steps);
|
||||
|
||||
/**
|
||||
* Returns the text of the current token from the lexer.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package com.intellij.lang;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
|
||||
public interface WhitespaceSkippedCallback {
|
||||
void onSkip(IElementType type, int start, int end);
|
||||
}
|
||||
@@ -93,6 +93,8 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
private int myLexemeCount = 0;
|
||||
private boolean myTokenTypeChecked;
|
||||
private ITokenTypeRemapper myRemapper;
|
||||
private WhitespaceSkippedCallback myWhispaceSkippedCallback;
|
||||
|
||||
|
||||
private ASTNode myOriginalTree = null;
|
||||
private MyTreeStructure myParentLightTree = null;
|
||||
@@ -610,6 +612,23 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
myRemapper = remapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remapCurrentToken(IElementType type) {
|
||||
myLexTypes[myCurrentLexeme] = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IElementType lookAhead(int steps) {
|
||||
if (steps + myCurrentLexeme >= myLexemeCount) return null;
|
||||
return myLexTypes[myCurrentLexeme + steps];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitespaceSkippedCallback(WhitespaceSkippedCallback callback) {
|
||||
myWhispaceSkippedCallback = callback;
|
||||
}
|
||||
|
||||
public void advanceLexer() {
|
||||
if (eof()) return;
|
||||
|
||||
@@ -621,7 +640,16 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
|
||||
private void skipWhitespace() {
|
||||
while (myCurrentLexeme < myLexemeCount && whitespaceOrComment(myLexTypes[myCurrentLexeme])) myCurrentLexeme++;
|
||||
while (myCurrentLexeme < myLexemeCount && whitespaceOrComment(myLexTypes[myCurrentLexeme])) {
|
||||
onSkip(myLexTypes[myCurrentLexeme], myLexStarts[myCurrentLexeme], myCurrentLexeme + 1 < myLexemeCount ? myLexStarts[myCurrentLexeme + 1] : myText.length());
|
||||
myCurrentLexeme++;
|
||||
}
|
||||
}
|
||||
|
||||
private void onSkip(IElementType type, int start, int end) {
|
||||
if (myWhispaceSkippedCallback != null) {
|
||||
myWhispaceSkippedCallback.onSkip(type, start, end);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentOffset() {
|
||||
|
||||
Reference in New Issue
Block a user