use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class RestParser method parseMarkup.
private static void parseMarkup(PsiBuilder builder) {
PsiBuilder.Marker marker = builder.mark();
IElementType type = builder.getTokenType();
if (type == RestTokenTypes.SUBSTITUTION) {
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
builder.advanceLexer();
marker = builder.mark();
type = builder.getTokenType();
}
if (type == RestTokenTypes.DIRECTIVE) {
gotoNextWhiteSpaces(builder);
if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
builder.advanceLexer();
marker.done(RestElementTypes.DIRECTIVE_BLOCK);
return;
}
skipBlankLines(builder);
if (builder.getTokenType() != RestTokenTypes.WHITESPACE || "\n".equals(builder.getTokenText())) {
marker.done(RestElementTypes.DIRECTIVE_BLOCK);
return;
}
String white = builder.getTokenText();
parseDirective(builder, white, marker);
} else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION || type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
} else {
builder.advanceLexer();
marker.drop();
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class RestParser method parse.
@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
final PsiBuilder.Marker rootMarker = builder.mark();
while (!builder.eof()) {
IElementType type = builder.getTokenType();
if (type == RestTokenTypes.EXPLISIT_MARKUP_START) {
builder.advanceLexer();
parseMarkup(builder);
} else if (type == RestTokenTypes.REFERENCE_NAME || type == RestTokenTypes.SUBSTITUTION) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestTokenTypes.REFERENCE_NAME);
} else if (type == RestTokenTypes.TITLE) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestTokenTypes.TITLE);
} else if (type == RestTokenTypes.FIELD) {
parseFieldList(builder);
} else if (type == RestTokenTypes.INLINE_LINE) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestElementTypes.INLINE_BLOCK);
} else if (type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
} else if (type == RestTokenTypes.LINE) {
parseLineText(builder, type);
} else
builder.advanceLexer();
}
rootMarker.done(root);
return builder.getTreeBuilt();
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class XmlAttributeImpl method getDisplayValue.
@Override
public String getDisplayValue() {
String displayText = myDisplayText;
if (displayText != null)
return displayText;
XmlAttributeValue value = getValueElement();
if (value == null)
return null;
PsiElement firstChild = value.getFirstChild();
if (firstChild == null)
return null;
ASTNode child = firstChild.getNode();
TextRange valueTextRange = new TextRange(0, value.getTextLength());
if (child != null && child.getElementType() == XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER) {
valueTextRange = new TextRange(child.getTextLength(), valueTextRange.getEndOffset());
child = child.getTreeNext();
}
final TIntArrayList gapsStarts = new TIntArrayList();
final TIntArrayList gapsShifts = new TIntArrayList();
StringBuilder buffer = new StringBuilder(getTextLength());
while (child != null) {
final int start = buffer.length();
IElementType elementType = child.getElementType();
if (elementType == XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER) {
valueTextRange = new TextRange(valueTextRange.getStartOffset(), child.getTextRange().getStartOffset() - value.getTextRange().getStartOffset());
break;
}
if (elementType == XmlTokenType.XML_CHAR_ENTITY_REF) {
buffer.append(XmlUtil.getCharFromEntityRef(child.getText()));
} else if (elementType == XmlElementType.XML_ENTITY_REF) {
buffer.append(XmlUtil.getEntityValue((XmlEntityRef) child));
} else {
appendChildToDisplayValue(buffer, child);
}
int end = buffer.length();
int originalLength = child.getTextLength();
if (end - start != originalLength) {
gapsStarts.add(start);
gapsShifts.add(originalLength - (end - start));
}
child = child.getTreeNext();
}
int[] gapDisplayStarts = ArrayUtil.newIntArray(gapsShifts.size());
int[] gapPhysicalStarts = ArrayUtil.newIntArray(gapsShifts.size());
int currentGapsSum = 0;
for (int i = 0; i < gapDisplayStarts.length; i++) {
currentGapsSum += gapsShifts.get(i);
gapDisplayStarts[i] = gapsStarts.get(i);
gapPhysicalStarts[i] = gapDisplayStarts[i] + currentGapsSum;
}
myGapDisplayStarts = gapDisplayStarts;
myGapPhysicalStarts = gapPhysicalStarts;
myValueTextRange = valueTextRange;
return myDisplayText = buffer.toString();
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class XmlTextImpl method insertText.
@Override
public void insertText(String text, int displayOffset) throws IncorrectOperationException {
if (text == null || text.isEmpty())
return;
final int physicalOffset = displayToPhysical(displayOffset);
final PsiElement psiElement = findElementAt(physicalOffset);
//if (!(psiElement instanceof XmlTokenImpl)) throw new IncorrectOperationException("Can't insert at offset: " + displayOffset);
final IElementType elementType = psiElement != null ? psiElement.getNode().getElementType() : null;
if (elementType == XmlTokenType.XML_DATA_CHARACTERS) {
int insertOffset = physicalOffset - psiElement.getStartOffsetInParent();
final String oldElementText = psiElement.getText();
final String newElementText = oldElementText.substring(0, insertOffset) + text + oldElementText.substring(insertOffset);
final PomModel model = PomManager.getModel(getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(this, aspect) {
@Override
public PomModelEvent runInner() {
final String oldText = getText();
final ASTNode e = getPolicy().encodeXmlTextContents(newElementText, XmlTextImpl.this);
final ASTNode node = psiElement.getNode();
final ASTNode treeNext = node.getTreeNext();
addChildren(e, null, treeNext);
deleteChildInternal(node);
clearCaches();
return XmlTextChangedImpl.createXmlTextChanged(model, XmlTextImpl.this, oldText);
}
});
} else {
setValue(new StringBuffer(getValue()).insert(displayOffset, text).toString());
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class XmlTextImpl method removeText.
@Override
public void removeText(int displayStart, int displayEnd) throws IncorrectOperationException {
final String value = getValue();
final int physicalStart = displayToPhysical(displayStart);
final PsiElement psiElement = findElementAt(physicalStart);
if (psiElement != null) {
final IElementType elementType = psiElement.getNode().getElementType();
final int elementDisplayEnd = physicalToDisplay(psiElement.getStartOffsetInParent() + psiElement.getTextLength());
final int elementDisplayStart = physicalToDisplay(psiElement.getStartOffsetInParent());
if (elementType == XmlTokenType.XML_DATA_CHARACTERS || elementType == TokenType.WHITE_SPACE) {
if (elementDisplayEnd >= displayEnd && elementDisplayStart <= displayStart) {
int physicalEnd = physicalStart;
while (physicalEnd < getTextRange().getLength()) {
if (physicalToDisplay(physicalEnd) == displayEnd)
break;
physicalEnd++;
}
int removeStart = physicalStart - psiElement.getStartOffsetInParent();
int removeEnd = physicalEnd - psiElement.getStartOffsetInParent();
final String oldElementText = psiElement.getText();
final String newElementText = oldElementText.substring(0, removeStart) + oldElementText.substring(removeEnd);
final PomModel model = PomManager.getModel(getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(this, aspect) {
@Override
public PomModelEvent runInner() throws IncorrectOperationException {
final String oldText = getText();
if (!newElementText.isEmpty()) {
final ASTNode e = getPolicy().encodeXmlTextContents(newElementText, XmlTextImpl.this);
replaceChild(psiElement.getNode(), e);
} else {
psiElement.delete();
}
clearCaches();
return XmlTextChangedImpl.createXmlTextChanged(model, XmlTextImpl.this, oldText);
}
});
return;
}
}
}
if (displayStart == 0 && displayEnd == value.length()) {
delete();
} else {
setValue(new StringBuffer(getValue()).replace(displayStart, displayEnd, "").toString());
}
}
Aggregations