use of com.intellij.structuralsearch.MalformedPatternException in project intellij-community by JetBrains.
the class JavaCompilingVisitor method visitDeclarationStatement.
@Override
public void visitDeclarationStatement(PsiDeclarationStatement psiDeclarationStatement) {
super.visitDeclarationStatement(psiDeclarationStatement);
final PsiElement firstChild = psiDeclarationStatement.getFirstChild();
if (firstChild instanceof PsiTypeElement) {
// search for expression or symbol
final PsiJavaCodeReferenceElement reference = ((PsiTypeElement) firstChild).getInnermostComponentReferenceElement();
if (reference != null && reference.getParameterList().getTypeParameterElements().length > 0) {
myCompilingVisitor.setHandler(psiDeclarationStatement, new TypedSymbolHandler());
final MatchingHandler handler = myCompilingVisitor.getContext().getPattern().getHandler(psiDeclarationStatement);
// typed symbol
handler.setFilter(TypedSymbolNodeFilter.getInstance());
final PsiTypeElement[] params = reference.getParameterList().getTypeParameterElements();
for (PsiTypeElement param : params) {
if (param.getInnermostComponentReferenceElement() != null && (myCompilingVisitor.getContext().getPattern().isRealTypedVar(param.getInnermostComponentReferenceElement().getReferenceNameElement()))) {
myCompilingVisitor.getContext().getPattern().getHandler(param).setFilter(TypeParameterFilter.getInstance());
}
}
return;
}
} else if (firstChild instanceof PsiModifierList) {
final PsiModifierList modifierList = (PsiModifierList) firstChild;
final PsiAnnotation[] annotations = modifierList.getAnnotations();
if (annotations.length != 1) {
throw new MalformedPatternException();
}
for (String modifier : PsiModifier.MODIFIERS) {
if (modifierList.hasExplicitModifier(modifier)) {
throw new MalformedPatternException();
}
}
myCompilingVisitor.setHandler(psiDeclarationStatement, new AnnotationHandler());
final MatchingHandler handler = myCompilingVisitor.getContext().getPattern().getHandler(psiDeclarationStatement);
handler.setFilter(AnnotationFilter.getInstance());
return;
}
final MatchingHandler handler = new DeclarationStatementHandler();
myCompilingVisitor.getContext().getPattern().setHandler(psiDeclarationStatement, handler);
final PsiElement previousNonWhiteSpace = PsiTreeUtil.skipSiblingsBackward(psiDeclarationStatement, PsiWhiteSpace.class);
if (previousNonWhiteSpace instanceof PsiComment) {
((DeclarationStatementHandler) handler).setCommentHandler(myCompilingVisitor.getContext().getPattern().getHandler(previousNonWhiteSpace));
myCompilingVisitor.getContext().getPattern().setHandler(previousNonWhiteSpace, handler);
}
// detect typed symbol, it will have no variable
handler.setFilter(DeclarationFilter.getInstance());
}
use of com.intellij.structuralsearch.MalformedPatternException in project intellij-community by JetBrains.
the class JavaCompilingVisitor method visitComment.
@Override
public void visitComment(PsiComment comment) {
super.visitComment(comment);
final String text = comment.getText();
Matcher matcher = ourPattern.matcher(text);
boolean matches = false;
if (!matcher.matches()) {
matcher = ourPattern2.matcher(text);
if (!matcher.matches()) {
matcher = ourPattern3.matcher(text);
} else {
matches = true;
}
} else {
matches = true;
}
if (matches || matcher.matches()) {
String str = matcher.group(1);
comment.putUserData(CompiledPattern.HANDLER_KEY, str);
GlobalCompilingVisitor.setFilter(myCompilingVisitor.getContext().getPattern().getHandler(comment), CommentFilter.getInstance());
SubstitutionHandler handler = (SubstitutionHandler) myCompilingVisitor.getContext().getPattern().getHandler(str);
if (handler == null) {
throw new MalformedPatternException();
}
if (handler.getPredicate() != null) {
((RegExpPredicate) handler.getPredicate()).setMultiline(true);
}
RegExpPredicate predicate = MatchingHandler.getSimpleRegExpPredicate(handler);
if (GlobalCompilingVisitor.isSuitablePredicate(predicate, handler)) {
myCompilingVisitor.processTokenizedName(predicate.getRegExp(), true, GlobalCompilingVisitor.OccurenceKind.COMMENT);
}
matches = true;
}
if (!matches) {
MatchingHandler handler = myCompilingVisitor.processPatternStringWithFragments(text, GlobalCompilingVisitor.OccurenceKind.COMMENT);
if (handler != null)
comment.putUserData(CompiledPattern.HANDLER_KEY, handler);
}
}
use of com.intellij.structuralsearch.MalformedPatternException in project intellij-community by JetBrains.
the class RegExpPredicate method compilePattern.
private void compilePattern() {
try {
@NonNls String realRegexp = regexp;
if (wholeWords) {
realRegexp = ".*?\\b(?:" + realRegexp + ")\\b.*?";
}
pattern = Pattern.compile(realRegexp, (caseSensitive ? 0 : Pattern.CASE_INSENSITIVE) | (multiline ? Pattern.DOTALL : 0));
} catch (PatternSyntaxException ex) {
throw new MalformedPatternException(SSRBundle.message("error.incorrect.regexp.constraint", regexp, baseHandlerName));
}
}
Aggregations