本文整理汇总了Java中com.intellij.psi.search.PsiElementProcessor.FindElement方法的典型用法代码示例。如果您正苦于以下问题:Java PsiElementProcessor.FindElement方法的具体用法?Java PsiElementProcessor.FindElement怎么用?Java PsiElementProcessor.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.search.PsiElementProcessor
的用法示例。
在下文中一共展示了PsiElementProcessor.FindElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findChildOfType
import com.intellij.psi.search.PsiElementProcessor; //导入方法依赖的package包/类
@Nullable
private static <T extends PsiElement> T findChildOfType(@Nullable final PsiElement element,
@NotNull final Class<T> aClass,
@Nullable final Class<? extends PsiElement> stopAt) {
final PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
@Override
public boolean execute(@NotNull PsiElement each) {
if (each == element) return true; // strict
if (aClass.isInstance(each)) {
return setFound(each);
}
return stopAt == null || !stopAt.isInstance(each);
}
};
PsiTreeUtil.processElements(element, processor);
//noinspection unchecked
return (T)processor.getFoundElement();
}
示例2: findChildOfAnyType
import com.intellij.psi.search.PsiElementProcessor; //导入方法依赖的package包/类
/**
* Recursive (depth first) search for first element of any of given {@code classes}.
*
* @param element a PSI element to start search from.
* @param strict if false the {@code element} is also included in the search.
* @param classes element types to search for.
* @param <T> type to cast found element to.
* @return first found element, or null if nothing found.
*/
@Nullable
@Contract("null, _, _ -> null")
public static <T extends PsiElement> T findChildOfAnyType(@Nullable final PsiElement element,
final boolean strict,
@NotNull final Class<? extends T>... classes) {
PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
@Override
public boolean execute(@NotNull PsiElement each) {
if (strict && each == element) return true;
if (instanceOf(each, classes)) {
return setFound(each);
}
return true;
}
};
processElements(element, processor);
//noinspection unchecked
return (T)processor.getFoundElement();
}
示例3: findFirstDocString
import com.intellij.psi.search.PsiElementProcessor; //导入方法依赖的package包/类
@Nullable
private String findFirstDocString() {
final PsiElementProcessor.FindElement<PsiElement> processor = new PsiElementProcessor.FindElement<PsiElement>() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof PyStringLiteralExpression && element.getFirstChild().getNode().getElementType() == PyTokenTypes.DOCSTRING) {
return setFound(element);
}
return true;
}
};
PsiTreeUtil.processElements(myFixture.getFile(), processor);
if (!processor.isFound()) {
return null;
}
final PsiElement foundElement = processor.getFoundElement();
assertNotNull(foundElement);
return ((PyStringLiteralExpression)foundElement).getStringValue();
}
示例4: createAnnotation
import com.intellij.psi.search.PsiElementProcessor; //导入方法依赖的package包/类
@Override
protected void createAnnotation(ASTNode node, String message) {
if (MISSING_START_ELEMENT.equals(message)) {
final PsiFile psiFile = node.getPsi().getContainingFile();
if (psiFile instanceof XmlFile) {
final PsiElementProcessor.FindElement<XmlFile> processor = new PsiElementProcessor.FindElement<XmlFile>();
RelaxIncludeIndex.processBackwardDependencies((XmlFile)psiFile, processor);
if (processor.isFound()) {
// files that are included from other files do not need a <start> element.
myHolder.createWeakWarningAnnotation(node, message);
return;
}
}
} else if (message != null && message.startsWith(UNDEFINED_PATTERN)) {
// we've got our own validation for that
return;
}
myHolder.createErrorAnnotation(node, message);
}
示例5: visitDefine
import com.intellij.psi.search.PsiElementProcessor; //导入方法依赖的package包/类
@Override
public void visitDefine(final Define define) {
final PsiElement element = define.getPsiElement();
if (element != null) {
final XmlFile xmlFile = (XmlFile)element.getContainingFile();
final List<Define> result = new SmartList<Define>();
final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(define, xmlFile, result);
final PsiElementProcessor.FindElement<XmlFile> processor = new PsiElementProcessor.FindElement<XmlFile>() {
@Override
public boolean execute(@NotNull XmlFile file) {
final Grammar grammar = GrammarFactory.getGrammar(file);
if (grammar == null) return true;
grammar.acceptChildren(searcher);
return result.size() == 0 || super.execute(file);
}
};
RelaxIncludeIndex.processBackwardDependencies(xmlFile, processor);
if (processor.isFound()) {
createGutterAnnotation(define, new OverriddenDefineRenderer(define));
}
}
}