本文整理汇总了Java中com.intellij.psi.util.PsiTreeUtil类的典型用法代码示例。如果您正苦于以下问题:Java PsiTreeUtil类的具体用法?Java PsiTreeUtil怎么用?Java PsiTreeUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiTreeUtil类属于com.intellij.psi.util包,在下文中一共展示了PsiTreeUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPropsNameListWithIdentityReference
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@NotNull
private List<PropTypeBean> findPropsNameListWithIdentityReference(String identity, PsiElement psiElement){
return PsiTreeUtil.findChildrenOfType(psiElement, LeafPsiElement.class)
.stream()
.filter(o -> o.getText().equals(identity))
.filter(o -> o.getElementType().toString().equals("JS:IDENTIFIER"))
.filter(o -> {
if(o.getParent() instanceof JSReferenceExpressionImpl){
JSReferenceExpressionImpl parent = (JSReferenceExpressionImpl) o.getParent();
if(parent.getTreeNext()!=null && parent.getTreeNext().getElementType().toString().equals("JS:DOT")
&&parent.getTreeNext().getTreeNext()!=null){
return true;
}
}
return false;
})
.map(o -> ((JSReferenceExpressionImpl)o.getParent()).getTreeNext().getTreeNext().getText())
.distinct()
.map(o -> new PropTypeBean(o,"any", false))
.collect(Collectors.toList());
}
示例2: createColumnInfoMap
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
private Map<Integer, CsvColumnInfo<PsiElement>> createColumnInfoMap(CsvFile csvFile) {
Map<Integer, CsvColumnInfo<PsiElement>> columnInfoMap = new HashMap<>();
CsvRecord[] records = PsiTreeUtil.getChildrenOfType(csvFile, CsvRecord.class);
int row = 0;
for (CsvRecord record : records) {
int column = 0;
for (CsvField field : record.getFieldList()) {
Integer length = field.getTextLength();
if (!columnInfoMap.containsKey(column)) {
columnInfoMap.put(column, new CsvColumnInfo(column, length));
} else if (columnInfoMap.get(column).getMaxLength() < length) {
columnInfoMap.get(column).setMaxLength(length);
}
columnInfoMap.get(column).addElement(field, row);
++column;
}
++row;
}
return columnInfoMap;
}
示例3: invokeAutoPopup
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
MethodReference reference = PsiTreeUtil.getParentOfType(position, MethodReference.class);
if (reference != null && reference.getName() != null && reference.getName().equals("t") && reference.getClassReference() instanceof ClassReference) {
ClassReference classReference = (ClassReference) reference.getClassReference();
if (classReference == null || classReference.getName() == null || !classReference.getName().equals("Yii")) {
return false;
}
if (typeChar == '\'' || typeChar == '"') {
if (position instanceof LeafPsiElement && (position.getText().equals("$category") || position.getText().equals("$message"))) {
return true;
}
if (position.getNextSibling() instanceof ParameterList) {
return true;
}
}
}
return false;
}
示例4: getNamedSubComponentsFor
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@NotNull
public static List<AppleScriptComponent> getNamedSubComponentsFor(@NotNull AppleScriptScriptObject script) {
List<AppleScriptComponent> result = new ArrayList<>();
AppleScriptScriptBody scriptBody = script.getScriptBody();
AppleScriptComponent[] namedComponents = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptComponent.class);
AppleScriptAssignmentStatement[] varsCreations = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptAssignmentStatement.class);
AppleScriptVarDeclarationList[] varsDeclarations = PsiTreeUtil.getChildrenOfType(scriptBody, AppleScriptVarDeclarationList.class);
if (namedComponents != null) {
result.addAll(Arrays.asList(namedComponents));
}
if (varsCreations != null) {
for (AppleScriptAssignmentStatement variable : varsCreations) {
result.addAll(variable.getTargets());
}
}
if (varsDeclarations != null) {
for (AppleScriptVarDeclarationList declarationList : varsDeclarations) {
AppleScriptComponent[] vars = PsiTreeUtil.getChildrenOfType(declarationList, AppleScriptComponent.class);
if (vars != null) {
result.addAll(Arrays.asList(vars));
}
}
}
return result;
}
示例5: expectDomAttributeValue
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
public static <T extends DomElement, V> GenericAttributeValue<V> expectDomAttributeValue(
@NotNull final PsiElement element,
@NotNull final Class<? extends T> domTagClass,
@NotNull final Function<T, GenericAttributeValue<V>> domGetter
) {
final DomManager domManager = DomManager.getDomManager(element.getProject());
if (!(element instanceof XmlElement)) {
return null;
}
final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
if (xmlAttribute == null) {
return null;
}
final XmlTag xmlParentTag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
DomElement domParentTag = domManager.getDomElement(xmlParentTag);
return Optional.ofNullable(domParentTag)
.map(o -> ObjectUtils.tryCast(o, domTagClass))
.map(domGetter)
.filter(val -> val == domManager.getDomElement(xmlAttribute))
.orElse(null);
}
示例6: getContainingClass
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
public static PsiClass getContainingClass( PsiElement element )
{
final PsiClass psiClass = PsiTreeUtil.getParentOfType( element, PsiClass.class, false );
if( psiClass == null )
{
final PsiFile containingFile = element.getContainingFile();
if( containingFile instanceof PsiClassOwner )
{
final PsiClass[] classes = ((PsiClassOwner)containingFile).getClasses();
if( classes.length == 1 )
{
return classes[0];
}
}
}
return psiClass;
}
示例7: 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);
}
示例8: getHeaderTypeNamePsiElementOfAttribute
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Nullable
@Contract("null -> null")
protected ImpexHeaderTypeName getHeaderTypeNamePsiElementOfAttribute(@Nullable final PsiElement headerAttributePsiElement) {
if (null == headerAttributePsiElement || null == headerAttributePsiElement.getNode()) {
return null;
}
final ImpexHeaderLine impexHeaderLine = PsiTreeUtil.getParentOfType(
headerAttributePsiElement,
ImpexHeaderLine.class
);
if (null == impexHeaderLine) {
return null;
}
final ImpexFullHeaderType impexFullHeaderType = impexHeaderLine.getFullHeaderType();
return null == impexFullHeaderType ? null : impexFullHeaderType.getHeaderTypeName();
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImpexHeaderItemTypeAttributeNameCompletionProvider.java
示例9: generateDoc
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
if (element instanceof PsiModuleName) {
element = element.getParent();
PsiElement previousElement = element == null ? null : PsiTreeUtil.prevVisibleLeaf(element);
if (previousElement instanceof PsiComment) {
StringBuilder sb = new StringBuilder();
sb.append(previousElement.getText());
return sb.toString();
}
}
return super.generateDoc(element, originalElement);
}
示例10: isCallResultUsed
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
private boolean isCallResultUsed(PsiMethodCallExpression call) {
if (hasChainedMethodCall(call)) {
return true;
} else if (getBoundVariable(call, true) != null) {
// TODO: Check that variable is actually used
return true;
} else if (PsiTreeUtil.getParentOfType(call, PsiReturnStatement.class) != null) {
return true;
} else if (PsiTreeUtil.getParentOfType(call, PsiMethodCallExpression.class) != null) {
return true;
}
return false;
}
示例11: getReactImportDeclaration
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Nullable
ES6ImportDeclaration getReactImportDeclaration(PsiFile file){
return PsiTreeUtil.findChildrenOfType(file, ES6FromClause.class)
.stream()
.filter(o -> o.getText().contains("\'react\'"))
.filter(o -> o.getParent() instanceof ES6ImportDeclaration)
.map(o -> (ES6ImportDeclaration) o.getParent())
.findFirst()
.orElse(null);
}
示例12: setProcessParameters
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Override
protected void setProcessParameters(Project project, ApplicationConfiguration configuration, Module module, @NotNull VirtualFile testsFile) {
configuration.setMainClassName(EduIntelliJNames.TEST_RUNNER_CLASS);
configuration.setModule(module);
PsiFile psiFile = PsiManager.getInstance(project).findFile(testsFile);
Collection<KtClass> ktClasses = PsiTreeUtil.findChildrenOfType(psiFile, KtClass.class);
for (KtClass ktClass : ktClasses) {
String name = ktClass.getName();
configuration.setProgramParameters(name);
}
}
示例13: resolveInner
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode, @NotNull PsiFile containingFile) {
final AppleScriptResolveProcessor resolveProcessor = new AppleScriptResolveProcessor(getHandlerSelector());
PsiTreeUtil.treeWalkUp(resolveProcessor, AbstractAppleScriptHandlerCall.this, null, ResolveState.initial());
final List<PsiElement> results = new ArrayList<>();
results.add(resolveProcessor.getResult());
return AppleScriptResolveUtil.toCandidateInfoArray(results);
}
示例14: handleElementRename
import com.intellij.psi.util.PsiTreeUtil; //导入依赖的package包/类
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
PsiElement element = this;
final AppleScriptIdentifier identifier = PsiTreeUtil.getChildOfType(element, AppleScriptIdentifier.class);
final AppleScriptIdentifier identifierNew = AppleScriptPsiElementFactory.createIdentifierFromText(getProject(), newElementName);
if (identifierNew != null && identifier != null) {
element.getNode().replaceChild(identifier.getNode(), identifierNew.getNode());
}
return this;
}
示例15: 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;
};
}