本文整理汇总了Java中com.intellij.patterns.ElementPattern.accepts方法的典型用法代码示例。如果您正苦于以下问题:Java ElementPattern.accepts方法的具体用法?Java ElementPattern.accepts怎么用?Java ElementPattern.accepts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.patterns.ElementPattern
的用法示例。
在下文中一共展示了ElementPattern.accepts方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertNavigationMatch
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
private void assertNavigationMatch(ElementPattern<?> pattern) {
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Set<String> targetStrings = new HashSet<String>();
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
continue;
}
for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
targetStrings.add(gotoDeclarationTarget.toString());
if(pattern.accepts(gotoDeclarationTarget)) {
return;
}
}
}
fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
}
示例2: findIdentifierPrefix
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public static String findIdentifierPrefix(PsiElement insertedElement, int offset, ElementPattern<Character> idPart,
ElementPattern<Character> idStart) {
if(insertedElement == null) return "";
final String text = insertedElement.getText();
final int offsetInElement = offset - insertedElement.getTextRange().getStartOffset();
int start = offsetInElement - 1;
while (start >=0 ) {
if (!idPart.accepts(text.charAt(start))) break;
--start;
}
while (start + 1 < offsetInElement && !idStart.accepts(text.charAt(start + 1))) {
start++;
}
return text.substring(start + 1, offsetInElement).trim();
}
示例3: accepts
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public boolean accepts(PrattBuilder builder) {
ListIterator<IElementType> iterator = null;
for (final ElementPattern pattern : myPath) {
if (builder == null) return false;
if (iterator == null) {
iterator = builder.getBackResultIterator();
}
if (pattern == null) {
if (iterator.hasPrevious()) return false;
builder = builder.getParent();
iterator = null;
} else {
if (!iterator.hasPrevious()) return false;
if (!pattern.accepts(iterator.previous())) return false;
}
}
return true;
}
示例4: isInContext
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
if (!super.isInContext(file, offset)) {
return false;
}
final ElementPattern<PsiElement> illegalPattern = or(psiElement().inside(JsonStringLiteral.class),
psiElement().inside(psiElement(JsonValue.class)
.with(new PatternCondition<PsiElement>("insidePropertyKey") {
@Override
public boolean accepts(@NotNull PsiElement element,
ProcessingContext context) {
return JsonPsiUtil.isPropertyKey(element);
}
})));
return !illegalPattern.accepts(file.findElementAt(offset));
}
示例5: assertNavigationMatch
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
myFixture.configureByText(languageFileType, configureByText);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
Set<String> targetStrings = new HashSet<>();
for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor());
if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
continue;
}
for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) {
targetStrings.add(gotoDeclarationTarget.toString());
if(pattern.accepts(gotoDeclarationTarget)) {
return;
}
}
}
fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString()));
}
示例6: assertPhpReferenceResolveTo
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) {
myFixture.configureByText(languageFileType, configureByText);
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
if (psiElement == null) {
fail("Element is not PhpReference.");
}
PsiElement resolve = ((PhpReference) psiElement).resolve();
if(!pattern.accepts(resolve)) {
fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString()));
}
assertTrue(pattern.accepts(resolve));
}
示例7: findPrefixDefault
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public static String findPrefixDefault(final PsiElement insertedElement, final int offset, @NotNull final ElementPattern trimStart) {
String substr = insertedElement.getText().substring(0, offset - insertedElement.getTextRange().getStartOffset());
if (substr.length() == 0 || Character.isWhitespace(substr.charAt(substr.length() - 1))) return "";
substr = substr.trim();
int i = 0;
while (substr.length() > i && trimStart.accepts(substr.charAt(i))) i++;
return substr.substring(i).trim();
}
示例8: fromClassPattern
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
public static ClassContextFilter fromClassPattern(final ElementPattern pattern) {
return new ClassContextFilter(new Condition<Pair<PsiType, PsiFile>>() {
@Override
public boolean value(Pair<PsiType, PsiFile> pair) {
final PsiType type = pair.first;
return type instanceof PsiClassType ? pattern.accepts(((PsiClassType)type).resolve()) : false;
}
});
}
示例9: doTest
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
private boolean doTest(final String text, final ElementPattern<PsiElement> ref) {
myFixture.configureByText(PythonFileType.INSTANCE, text);
PsiElement element = myFixture.getFile().findElementAt(text.length() - 1);
return ref.accepts(element);
}
示例10: isAfterForParameter
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
private static boolean isAfterForParameter(PsiElement position) {
ElementPattern<PsiElement> forParameter =
PsiJavaPatterns.psiElement().withParents(GrParameter.class, GrTraditionalForClause.class, GrForStatement.class);
return PsiJavaPatterns.psiElement().withParent(GrReferenceExpression.class).afterLeaf(forParameter).accepts(position) ||
forParameter.accepts(position) && PsiJavaPatterns.psiElement().afterLeaf(PsiJavaPatterns.psiElement(GroovyTokenTypes.mIDENT)).accepts(position);
}
示例11: isAfterForParameter
import com.intellij.patterns.ElementPattern; //导入方法依赖的package包/类
private static boolean isAfterForParameter(PsiElement position) {
ElementPattern<PsiElement> forParameter =
psiElement().withParents(GrParameter.class, GrTraditionalForClause.class, GrForStatement.class);
return psiElement().withParent(GrReferenceExpression.class).afterLeaf(forParameter).accepts(position) ||
forParameter.accepts(position) && psiElement().afterLeaf(psiElement(GroovyTokenTypes.mIDENT)).accepts(position);
}