use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class CodeStyleManagerImpl method doFindWhiteSpaceNode.
@NotNull
private static Pair<PsiElement, CharTable> doFindWhiteSpaceNode(@NotNull PsiFile file, int offset) {
ASTNode astNode = SourceTreeToPsiMap.psiElementToTree(file);
if (!(astNode instanceof FileElement)) {
return new Pair<>(null, null);
}
PsiElement elementAt = InjectedLanguageUtil.findInjectedElementNoCommit(file, offset);
final CharTable charTable = ((FileElement) astNode).getCharTable();
if (elementAt == null) {
elementAt = findElementInTreeWithFormatterEnabled(file, offset);
}
if (elementAt == null) {
return new Pair<>(null, charTable);
}
ASTNode node = elementAt.getNode();
if (node == null || node.getElementType() != TokenType.WHITE_SPACE) {
return new Pair<>(null, charTable);
}
return Pair.create(elementAt, charTable);
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class JavaResolveUtil method resolveImaginarySuperCallInThisPlace.
/**
* @return the constructor (or a class if there are none)
* which the "{@code super();}" no-args call resolves to if inserted in the {@code place} (typically it would be inserted in the sub class constructor)
* No code modifications happen in this method; it's used for resolving multiple overloaded constructors.
*/
public static PsiElement resolveImaginarySuperCallInThisPlace(@NotNull PsiMember place, @NotNull Project project, @NotNull PsiClass superClassWhichTheSuperCallMustResolveTo) {
PsiExpressionListImpl expressionList = new PsiExpressionListImpl();
final DummyHolder result = DummyHolderFactory.createHolder(PsiManager.getInstance(project), place);
final FileElement holder = result.getTreeElement();
holder.rawAddChildren((TreeElement) expressionList.getNode());
return PsiResolveHelper.SERVICE.getInstance(project).resolveConstructor(PsiTypesUtil.getClassType(superClassWhichTheSuperCallMustResolveTo), expressionList, place).getElement();
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class SmartPsiElementPointersTest method assertTreeLoaded.
private static void assertTreeLoaded(PsiFileImpl file, boolean loaded) {
FileElement treeElement = file.getTreeElement();
assertEquals(loaded, treeElement != null);
StubTree stubTree = file.getStubTree();
assertEquals(loaded, stubTree == null);
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class PomModelImpl method getContainingFileByTree.
@Nullable
private static PsiFile getContainingFileByTree(@NotNull final PsiElement changeScope) {
// there could be pseudo physical trees (JSPX/JSP/etc.) which must not translate
// any changes to document and not to fire any PSI events
final PsiFile psiFile;
final ASTNode node = changeScope.getNode();
if (node == null) {
psiFile = changeScope.getContainingFile();
} else {
final FileElement fileElement = TreeUtil.getFileElement((TreeElement) node);
// Hack. the containing tree can be invalidated if updating supplementary trees like HTML in JSP.
if (fileElement == null)
return null;
psiFile = (PsiFile) fileElement.getPsi();
}
return psiFile.getNode() != null ? psiFile : null;
}
use of com.intellij.psi.impl.source.tree.FileElement in project intellij-community by JetBrains.
the class XmlTextImpl method _splitText.
@Nullable
private XmlText _splitText(final int displayOffset) throws IncorrectOperationException {
final XmlTag xmlTag = (XmlTag) getParent();
if (displayOffset == 0)
return this;
final int length = getValue().length();
if (displayOffset >= length) {
return null;
}
final PomModel model = PomManager.getModel(xmlTag.getProject());
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
class MyTransaction extends PomTransactionBase {
private XmlTextImpl myRight;
MyTransaction() {
super(xmlTag, aspect);
}
@Override
@Nullable
public PomModelEvent runInner() throws IncorrectOperationException {
final String oldText = getValue();
final int physicalOffset = displayToPhysical(displayOffset);
PsiElement childElement = findElementAt(physicalOffset);
if (childElement != null && childElement.getNode().getElementType() == XmlTokenType.XML_DATA_CHARACTERS) {
FileElement holder = DummyHolderFactory.createHolder(getManager(), null).getTreeElement();
int splitOffset = physicalOffset - childElement.getStartOffsetInParent();
myRight = (XmlTextImpl) ASTFactory.composite(XmlElementType.XML_TEXT);
CodeEditUtil.setNodeGenerated(myRight, true);
holder.rawAddChildren(myRight);
PsiElement e = childElement;
while (e != null) {
CodeEditUtil.setNodeGenerated(e.getNode(), true);
e = e.getNextSibling();
}
String leftText = childElement.getText().substring(0, splitOffset);
String rightText = childElement.getText().substring(splitOffset);
LeafElement rightElement = ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, holder.getCharTable().intern(rightText));
CodeEditUtil.setNodeGenerated(rightElement, true);
LeafElement leftElement = ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, holder.getCharTable().intern(leftText));
CodeEditUtil.setNodeGenerated(leftElement, true);
rawInsertAfterMe(myRight);
myRight.rawAddChildren(rightElement);
if (childElement.getNextSibling() != null) {
myRight.rawAddChildren((TreeElement) childElement.getNextSibling());
}
((TreeElement) childElement).rawRemove();
XmlTextImpl.this.rawAddChildren(leftElement);
} else {
final PsiFile containingFile = xmlTag.getContainingFile();
final FileElement holder = DummyHolderFactory.createHolder(containingFile.getManager(), null, ((PsiFileImpl) containingFile).getTreeElement().getCharTable()).getTreeElement();
final XmlTextImpl rightText = (XmlTextImpl) ASTFactory.composite(XmlElementType.XML_TEXT);
CodeEditUtil.setNodeGenerated(rightText, true);
holder.rawAddChildren(rightText);
((ASTNode) xmlTag).addChild(rightText, getTreeNext());
final String value = getValue();
setValue(value.substring(0, displayOffset));
rightText.setValue(value.substring(displayOffset));
CodeEditUtil.setNodeGenerated(rightText, true);
myRight = rightText;
}
clearCaches();
myRight.clearCaches();
return createEvent(new XmlTextChangedImpl(XmlTextImpl.this, oldText), new XmlTagChildAddImpl(xmlTag, myRight));
}
public XmlText getResult() {
return myRight;
}
}
final MyTransaction transaction = new MyTransaction();
model.runTransaction(transaction);
return transaction.getResult();
}
Aggregations