本文整理汇总了Java中com.intellij.psi.util.PsiTreeUtil.findChildOfType方法的典型用法代码示例。如果您正苦于以下问题:Java PsiTreeUtil.findChildOfType方法的具体用法?Java PsiTreeUtil.findChildOfType怎么用?Java PsiTreeUtil.findChildOfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiTreeUtil
的用法示例。
在下文中一共展示了PsiTreeUtil.findChildOfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassName
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static String getClassName(@NotNull PsiElement element) {
ParameterList parameterList = PsiTreeUtil.getParentOfType(element, ParameterList.class);
if (parameterList == null) {
return null;
}
MethodReference methodReference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
if (methodReference == null) {
return null;
}
Variable variableBeingCalledOn = PsiTreeUtil.findChildOfType(methodReference, Variable.class);
if (variableBeingCalledOn != null && variableBeingCalledOn.getInferredType() != null) {
PhpType inferredType = variableBeingCalledOn.getInferredType();
return inferredType.toString();
}
ClassReference classReference = PsiTreeUtil.getChildOfType(methodReference, ClassReference.class);
return extractFqnFromClassReference(methodReference, classReference);
}
示例2: testVariableReferences
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public void testVariableReferences() throws Throwable {
myFixture.configureByFiles("CompletionSource.soy");
PsiElement container = PsiTreeUtil.findChildOfType(myFixture.getFile(), SoyMsgStatement.class);
Collection<SoyVariableReferenceIdentifier> vars =
PsiTreeUtil.findChildrenOfType(container, SoyVariableReferenceIdentifier.class);
assertSize(3, vars);
for (SoyVariableReferenceIdentifier var : vars) {
Class expectedClass;
if (var.getText().equals("$planet")) {
// @param
expectedClass = SoyParamDefinitionIdentifier.class;
} else if (var.getText().equals("$probe")) {
// @inject
expectedClass = SoyParamDefinitionIdentifier.class;
} else {
// {let}
expectedClass = SoyVariableDefinitionIdentifier.class;
}
PsiElement id = var.getReference().resolve();
assertInstanceOf(id, expectedClass);
}
}
示例3: firstStageMainSketchIdentification
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static Collection<PsiFile> firstStageMainSketchIdentification(@NotNull Collection<PsiFile> parsedPdeFiles) {
Set<PsiFile> shortlist = new HashSet<>();
for (PsiFile parsedPdeFile : parsedPdeFiles) {
PsiErrorElement firstErrorInFile = PsiTreeUtil.findChildOfType(parsedPdeFile, PsiErrorElement.class);
if (firstErrorInFile == null) {
continue;
}
PsiClass errorContainingClass = PsiTreeUtil.getParentOfType(firstErrorInFile, PsiClass.class);
if (errorContainingClass == null) {
shortlist.add(parsedPdeFile);
}
}
return shortlist;
}
示例4: isAvailable
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
if (!element.isWritable()) return false;
boolean isTwigFile = GravFileTemplateUtil.isTwigTemplateFile(element.getContainingFile()) || element.getContainingFile() instanceof HtmlFileImpl;
boolean isXmlAttribute = false;
if (!isTwigFile) return false;
if (element.getParent() instanceof XmlAttributeValueImpl) {
XmlAttributeValueImpl parent0 = ((XmlAttributeValueImpl) element.getParent());
boolean hasTwigElement = PsiTreeUtil.findChildOfType(parent0, OuterLanguageElement.class) != null;
if (!hasTwigElement && parent0.getParent() instanceof XmlAttributeImpl) {
XmlAttributeImpl parent1 = (XmlAttributeImpl) parent0.getParent();
if (parent1.getName().equalsIgnoreCase("href") || parent1.getName().equalsIgnoreCase("src"))
isXmlAttribute = true;
}
}
return isXmlAttribute;
}
示例5: getApplicationName
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Nullable
public static String getApplicationName(AppleScriptUseStatement useStatement) {
if (useStatement.getText().contains("application")) {
AppleScriptApplicationReference appRef = PsiTreeUtil.findChildOfType(useStatement,
AppleScriptApplicationReference.class);
if (appRef == null) return null;
ASTNode appNameNode = appRef.getNode().findChildByType(AppleScriptTypes.STRING_LITERAL);
return appNameNode != null ? appNameNode.getText().replace("\"", "") : null;
} else if (useStatement.getNode().findChildByType(AppleScriptTypes.SCRIPTING_ADDITIONS) != null) {
return ApplicationDictionary.SCRIPTING_ADDITIONS_LIBRARY;
}
return null;
}
示例6: getIndexer
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@NotNull
@Override
public DataIndexer<String, Void, FileContent> getIndexer() {
return fileContent -> {
final Map<String, Void> map = new THashMap<>();
/* ignore file if its' structure is not as expected */
final PhpReturn returnExpression = PsiTreeUtil.findChildOfType(fileContent.getPsiFile(), PhpReturn.class);
final PsiElement argument = null == returnExpression ? null : returnExpression.getArgument();
if (!(argument instanceof ArrayCreationExpression)) {
return map;
}
/* extract translations from the file */
for (ArrayHashElement item : ((ArrayCreationExpression) argument).getHashElements()) {
final PhpPsiElement key = item.getKey();
if (key instanceof StringLiteralExpression) {
final StringLiteralExpression literal = (StringLiteralExpression) key;
final String message = literal.getContents();
if (message.length() > 0) {
map.putIfAbsent(PhpStringUtil.unescapeText(message, literal.isSingleQuote()), null);
}
}
}
return map;
};
}
示例7: annotate
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
if (psiElement instanceof CallStatementElement) {
CallStatementElement statement = (CallStatementElement) psiElement;
Collection<String> givenParameters = ParamUtils.getGivenParameters(statement);
// TODO(thso): Detect data="" in more robust way.
if (statement.getText().contains("data=")) return;
PsiElement identifier =
PsiTreeUtil.findChildOfType(statement, SoyTemplateReferenceIdentifier.class);
if (identifier == null) return;
List<String> requiredParameters =
ParamUtils.getParametersForInvocation(statement, identifier.getText())
.stream()
.filter((var) -> !var.isOptional)
.map((var) -> var.name)
.collect(Collectors.toList());
if (!givenParameters.containsAll(requiredParameters)) {
requiredParameters.removeAll(givenParameters);
annotationHolder.createErrorAnnotation(
identifier, "Missing required parameters: " + String.join(",", requiredParameters));
}
}
}
示例8: getNamespace
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public String getNamespace() {
if (getStub() != null) {
return getStub().getNamespace();
}
SoyNamespaceDeclarationIdentifier namespaceDeclaration =
PsiTreeUtil.findChildOfType(this, SoyNamespaceDeclarationIdentifier.class);
return namespaceDeclaration == null ? "" : namespaceDeclaration.getName();
}
示例9: testTemplateReference
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public void testTemplateReference() throws Throwable {
myFixture.configureByFiles("ReferenceSource.soy", "CompletionSource.soy");
CallStatementElement element =
PsiTreeUtil.findChildOfType(myFixture.getFile(), CallStatementElement.class);
PsiElement id =
element.getBeginCall().getTemplateReferenceIdentifier().getReference().resolve();
assertInstanceOf(id, SoyTemplateDefinitionIdentifier.class);
assertEquals(".moon", ((SoyTemplateDefinitionIdentifier) id).getName());
}
示例10: testParamReference
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public void testParamReference() throws Throwable {
myFixture.configureByFiles("ReferenceSource.soy", "CompletionSource.soy");
SoyParamListElement element =
PsiTreeUtil.findChildOfType(myFixture.getFile(), SoyParamListElement.class);
PsiElement id =
element.getBeginParamTag().getParamSpecificationIdentifier().getReference().resolve();
assertInstanceOf(id, SoyParamDefinitionIdentifier.class);
assertEquals("planet", ((SoyParamDefinitionIdentifier) id).getName());
}
示例11: isWritable
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
private static boolean isWritable(SwiftPatternInitializer pattern) {
boolean isComputed = pattern.isComputed();
if (isComputed) {
return PsiTreeUtil.findChildOfType(pattern, SwiftSetterClause.class) != null;
} else {
return true;
}
}
示例12: isStartOfValueLine
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Contract(pure = true)
private boolean isStartOfValueLine(@Nullable final ASTNode currentNode) {
return null != currentNode
&& PsiTreeUtil.findChildOfType(
currentNode.getTreeParent().getPsi(),
ImpexValueGroup.class
) == currentNode.getPsi();
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:9,代码来源:ColumnsAlignmentStrategy.java
示例13: getSelectorIdentifier
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static AppleScriptIdentifier getSelectorIdentifier(AppleScriptArgumentSelector argumentSelector) {
return PsiTreeUtil.findChildOfType(argumentSelector, AppleScriptIdentifier.class);
}
示例14: findApplicationNameFromTellStatement
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
public static String findApplicationNameFromTellStatement(PsiElement tellStatement) {
//todo: could be not only application but any class of the application (process "Mail", etc)
AppleScriptApplicationReference appRef = PsiTreeUtil.findChildOfType(tellStatement, AppleScriptApplicationReference.class);
return getNameFromApplicationReference(appRef);
}
示例15: visitElement
import com.intellij.psi.util.PsiTreeUtil; //导入方法依赖的package包/类
@Override
public void visitElement(PsiElement element) {
Variable iconFolder = PsiTreeUtil.findChildOfType(element, Variable.class);
if (iconFolder == null || !iconFolder.getName().equals("iconFolder")) {
// Something changed - dynamic parsing failed.
return;
}
StringLiteralExpression iconFolderValueString = PsiTreeUtil.getNextSiblingOfType(iconFolder, StringLiteralExpression.class);
if (iconFolderValueString == null) {
return;
}
String iconFolderValue = iconFolderValueString.getContents();
Statement parentStatement = PsiTreeUtil.getParentOfType(iconFolder, Statement.class);
Statement iconArrayAssignment = PsiTreeUtil.getNextSiblingOfType(
parentStatement,
Statement.class
);
if (iconArrayAssignment == null) {
return;
}
Variable iconArray = PsiTreeUtil.findChildOfType(iconArrayAssignment, Variable.class);
if (iconArray == null) {
// something changed, meh. dynamic parsing failed.
return;
}
ClassConstantReference iconProvider = PsiTreeUtil.findChildOfType(element, ClassConstantReference.class);
if (iconProvider == null) {
// something changed. - ...
return;
}
ArrayCreationExpression flagsArray = PsiTreeUtil.getNextSiblingOfType(iconArray, ArrayCreationExpression.class);
if (flagsArray == null) {
return;
}
Collection<StringLiteralExpression> flagNames = PsiTreeUtil.findChildrenOfType(flagsArray, StringLiteralExpression.class);
for (StringLiteralExpression flagNameExpression : flagNames) {
String countryAbbreviation = flagNameExpression.getContents();
this.createFlagIcon(iconProvider, iconFolderValue, countryAbbreviation, flagNameExpression);
}
}