本文整理匯總了Java中com.intellij.psi.PsiElement.getFirstChild方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiElement.getFirstChild方法的具體用法?Java PsiElement.getFirstChild怎麽用?Java PsiElement.getFirstChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.PsiElement
的用法示例。
在下文中一共展示了PsiElement.getFirstChild方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findQuotePositionsUntilSeparator
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static PsiElement findQuotePositionsUntilSeparator(PsiElement element, List<Integer> quotePositions) {
PsiElement separatorElement = null;
while (separatorElement == null && element != null) {
if (getElementType(element) == CsvTypes.COMMA || getElementType(element) == CsvTypes.CRLF) {
separatorElement = element;
continue;
}
if (element.getFirstChild() != null) {
separatorElement = findQuotePositionsUntilSeparator(element.getFirstChild(), quotePositions);
} else if (element.getText().equals("\"")) {
quotePositions.add(element.getTextOffset());
}
element = element.getNextSibling();
}
return separatorElement;
}
示例2: annotate
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
PsiElement classElement = null;
if (element instanceof TSDatablockDecl) {
TSDatablockDecl db = (TSDatablockDecl) element;
//Find the first id node, this is kinda wonky since we have to account for whitespace nodes
//datablock ClassName(...)
ASTNode node = db.getNode();
if (node == null) {
return;
}
node = node.findChildByType(TSTypes.ID);
if (node == null) {
return;
}
classElement = node.getPsi();
} else if (element instanceof TSObjectExpr) {
TSObjectExpr obj = (TSObjectExpr) element;
//Class name should be the second thing in the element:
// new ClassName(...)
classElement = PsiTreeUtil.getChildOfType(obj, TSClassNameExpr.class);
if (classElement == null) {
return;
}
classElement = classElement.getFirstChild();
}
if (classElement == null) {
return;
}
//Only annotate if it's an id, can't really tell if it's an expr
if (classElement.getNode().getElementType().equals(TSTypes.ID)) {
createSuccessAnnotation(classElement, holder, TSSyntaxHighlighter.CLASSNAME);
}
}
示例3: getReference
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public PsiReference getReference() {
PsiElement nameIdentifier = this.getNameIdentifier();
if (nameIdentifier != null) {
PsiElement firstChild = nameIdentifier.getFirstChild(); // only first module name, not path yet
if (firstChild instanceof PsiModuleName) {
return new PsiModuleReference((PsiModuleName) firstChild);
}
}
return null;
}
示例4: getFirstMeaningChild
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Nullable
public static PsiElement getFirstMeaningChild(PsiElement element) {
PsiElement first = element.getFirstChild();
return first instanceof PsiWhiteSpace || first instanceof PsiComment
? getNextMeaningSibling(first)
: first;
}
示例5: getStringLiteral
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Nullable
private RStringLiteral getStringLiteral(@NotNull PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if(!(parent instanceof RStringLiteral)) {
return null;
}
if(parent.getParent() == null) {
return null;
}
PsiElement array = parent.getParent().getParent();
if(!(array instanceof RArrayIndexing)) {
return null;
}
PsiElement receiver = ((RArrayIndexing) array).getReceiver();
if(!(receiver instanceof RConstant)) {
return null;
}
if(receiver.getFirstChild() == null) {
return null;
}
if(!Objects.equals(receiver.getFirstChild().getText(), "ENV")) {
return null;
}
return (RStringLiteral) parent;
}
示例6: collectNavigationMarkers
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) {
if (element instanceof EmojiResourceProperty) {
PsiElement firstChild = element.getFirstChild();
String emoji = firstChild.getText().trim().replace(":", "");
Icon icon = EmojiUtil.getIcon(emoji);
if (icon != null) {
NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(icon)
.setTarget(element);
result.add(builder.createLineMarkerInfo(element));
}
}
}
示例7: buildVisitor
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (element == null || !holder.getFile().getLanguage().isKindOf(CsvLanguage.INSTANCE)) {
return;
}
IElementType elementType = CsvIntentionHelper.getElementType(element);
PsiElement firstChild = element.getFirstChild();
PsiElement nextSibling = element.getNextSibling();
if (elementType == TokenType.ERROR_ELEMENT && CsvIntentionHelper.getElementType(firstChild) == TokenType.BAD_CHARACTER) {
if (firstChild.getText().equals("\"")) {
holder.registerProblem(element, UNESCAPED_SEQUENCE, fixUnescapedSequence);
} else {
holder.registerProblem(element, SEPARATOR_MISSING, fixSeparatorMissing);
holder.registerProblem(element, UNESCAPED_SEQUENCE, fixUnescapedSequence);
}
} else if ((elementType == CsvTypes.TEXT || elementType == CsvTypes.ESCAPED_TEXT)
&& CsvIntentionHelper.getElementType(nextSibling) == TokenType.ERROR_ELEMENT
&& nextSibling.getFirstChild() == null) {
holder.registerProblem(element, CLOSING_QUOTE_MISSING, fixClosingQuoteMissing);
}
}
};
}
示例8: getChildren
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static List<PsiElement> getChildren(PsiElement element) {
List<PsiElement> children = new ArrayList<>();
if (element != null) {
element = element.getFirstChild();
while(element != null) {
children.add(element);
element = element.getNextSibling();
}
}
return children;
}
示例9: quoteAll
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
public static void quoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
try {
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
List<Integer> quotePositions = new ArrayList<>();
Collection<PsiElement> fields = getAllFields(psiFile);
PsiElement separator;
for (PsiElement field : fields) {
if (field.getFirstChild() == null || getElementType(field.getFirstChild()) != CsvTypes.QUOTE) {
separator = getPreviousSeparator(field);
if (separator == null) {
quotePositions.add(field.getParent().getTextOffset());
} else {
quotePositions.add(separator.getTextOffset() + separator.getTextLength());
}
}
if (field.getLastChild() == null || getElementType(field.getLastChild()) != CsvTypes.QUOTE) {
separator = getNextSeparator(field);
if (separator == null) {
quotePositions.add(field.getParent().getTextOffset() + field.getParent().getTextLength());
} else {
quotePositions.add(separator.getTextOffset());
}
}
}
String text = addQuotes(document.getText(), quotePositions);
document.setText(text);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例10: isAvailable
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
if (!super.isAvailable(project, editor, element)) {
return false;
}
element = CsvIntentionHelper.getParentFieldElement(element);
return element instanceof CsvField &&
element.getFirstChild() != null &&
(CsvIntentionHelper.getElementType(element.getFirstChild()) == CsvTypes.QUOTE ||
CsvIntentionHelper.getElementType(element.getLastChild()) == CsvTypes.QUOTE) &&
CsvIntentionHelper.getChildren(element).stream().allMatch(psiElement -> CsvIntentionHelper.getElementType(psiElement) != CsvTypes.ESCAPED_TEXT);
}
示例11: isAvailable
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @Nullable PsiElement element) {
if (!super.isAvailable(project, editor, element)) {
return false;
}
element = CsvIntentionHelper.getParentFieldElement(element);
return element instanceof CsvField &&
element.getFirstChild() != null &&
(CsvIntentionHelper.getElementType(element.getFirstChild()) != CsvTypes.QUOTE ||
CsvIntentionHelper.getElementType(element.getLastChild()) != CsvTypes.QUOTE);
}
示例12: visitFunction
import com.intellij.psi.PsiElement; //導入方法依賴的package包/類
private void visitFunction(RArrayIndexing expression) {
PsiElement receiver = expression.getReceiver();
if(!(receiver instanceof RConstant)) {
return;
}
if(receiver.getFirstChild() == null) {
return;
}
if(!Objects.equals(receiver.getFirstChild().getText(), "ENV")) {
return;
}
PsiElement stringLiteral = expression.getIndexes().get(0);
if(stringLiteral == null) return;
if(!(stringLiteral instanceof RStringLiteral)) return;
String key = ((RStringLiteral)stringLiteral).getContent();
collectedItems.add(new KeyUsagePsiElement(key, stringLiteral));
}