use of org.intellij.lang.regexp.psi.RegExpGroup in project intellij-community by JetBrains.
the class RegExpBackrefImpl method resolve.
public RegExpGroup resolve() {
final int index = getIndex();
final PsiElementProcessor.FindFilteredElement<RegExpElement> processor = new PsiElementProcessor.FindFilteredElement<>(new PsiElementFilter() {
int groupCount;
public boolean isAccepted(PsiElement element) {
if (element instanceof RegExpGroup) {
if (((RegExpGroup) element).isCapturing() && ++groupCount == index) {
return true;
}
}
return element == RegExpBackrefImpl.this;
}
});
PsiTreeUtil.processElements(getContainingFile(), processor);
if (processor.getFoundElement() instanceof RegExpGroup) {
return (RegExpGroup) processor.getFoundElement();
}
return null;
}
use of org.intellij.lang.regexp.psi.RegExpGroup in project intellij-community by JetBrains.
the class RegExpNamedGroupRefImpl method resolve.
@Nullable
public RegExpGroup resolve() {
final PsiElementProcessor.FindFilteredElement<RegExpGroup> processor = new PsiElementProcessor.FindFilteredElement<>(new PsiElementFilter() {
public boolean isAccepted(PsiElement element) {
if (!(element instanceof RegExpGroup)) {
return false;
}
final RegExpGroup group = (RegExpGroup) element;
return group.isAnyNamedGroup() && Comparing.equal(getGroupName(), group.getGroupName());
}
});
PsiTreeUtil.processElements(getContainingFile(), processor);
return processor.getFoundElement();
}
use of org.intellij.lang.regexp.psi.RegExpGroup in project intellij-community by JetBrains.
the class RegExpNamedGroupRefImpl method getReference.
@Override
public PsiReference getReference() {
return new PsiReference() {
public PsiElement getElement() {
return RegExpNamedGroupRefImpl.this;
}
@Override
public TextRange getRangeInElement() {
final ASTNode groupNode = getNode().findChildByType(GROUP_REF_TOKENS);
assert groupNode != null;
return new TextRange(groupNode.getTextLength(), getTextLength() - 1);
}
public PsiElement resolve() {
return RegExpNamedGroupRefImpl.this.resolve();
}
@NotNull
public String getCanonicalText() {
return getRangeInElement().substring(getText());
}
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
throw new UnsupportedOperationException();
}
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
throw new UnsupportedOperationException();
}
public boolean isReferenceTo(PsiElement element) {
return resolve() == element;
}
@Override
@NotNull
public Object[] getVariants() {
final PsiElementProcessor.CollectFilteredElements<RegExpGroup> processor = new PsiElementProcessor.CollectFilteredElements<>(new PsiElementFilter() {
@Override
public boolean isAccepted(PsiElement element) {
if (!(element instanceof RegExpGroup)) {
return false;
}
final RegExpGroup regExpGroup = (RegExpGroup) element;
return regExpGroup.isAnyNamedGroup();
}
});
PsiTreeUtil.processElements(getContainingFile(), processor);
return processor.toArray();
}
public boolean isSoft() {
return false;
}
};
}
use of org.intellij.lang.regexp.psi.RegExpGroup in project intellij-community by JetBrains.
the class ValueRegExpAnnotator method annotate.
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
if (psiElement instanceof RegExpFile && psiElement.getCopyableUserData(KEY) == Boolean.TRUE) {
final PsiElement pattern = psiElement.getFirstChild();
if (!(pattern instanceof RegExpPattern)) {
return;
}
final RegExpBranch[] branches = ((RegExpPattern) pattern).getBranches();
if (branches.length == 1 && branches[0].getAtoms().length == 0) {
return;
}
for (RegExpBranch branch : branches) {
final int[] count = new int[1];
branch.accept(new RegExpRecursiveElementVisitor() {
@Override
public void visitRegExpGroup(RegExpGroup group) {
if (group.isCapturing()) {
count[0]++;
}
super.visitRegExpGroup(group);
}
});
if (count[0] != 1) {
holder.createWarningAnnotation(branch, "The pattern should contain exactly one capturing group");
}
}
}
}
Aggregations