Skip to content

Commit

Permalink
Adding AST Negation expression
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeygorbaty committed Apr 26, 2017
1 parent 9fae304 commit 0386d71
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
19 changes: 10 additions & 9 deletions pmd-visualforce/etc/grammar/VfParser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ PARSER_END(VfParser)
| <GE: ">=" >
| <LT: "<" >
| <GT: ">" >
| <EXCL: ("!"|"~") >
| <EXCL: ("!"|"~"|"NOT") >
| <PIPE_PIPE: "||" >
| <STRING_LITERAL: <QUOTED_STRING> >
| <DIGITS: (<NUM_CHAR>)+ (<DOT> (<NUM_CHAR>)+)? >
Expand Down Expand Up @@ -496,14 +496,7 @@ void UnaryExpression() #void :
{}
{
( <PLUS> | <MINUS> ) UnaryExpression()
| NegationExpression()
}

void NegationExpression() #void :
{}
{
( <EXCL> ) UnaryExpression()
| PrimaryExpression()
| PrimaryExpression()
}

void PrimaryExpression() #void :
Expand Down Expand Up @@ -537,6 +530,7 @@ void PrimaryPrefix() #void :
| Identifier()
| <LPAREN> Expression() <RPAREN>
| <LSQUARE> Expression() (<COMMA> Expression())* <RSQUARE>
| NegationExpression()
}

void PrimarySuffix() #void :
Expand All @@ -547,6 +541,13 @@ void PrimarySuffix() #void :
| Arguments()
}

void NegationExpression() :
{}
{
( <EXCL> ) Expression()
}


void DotExpression() :
{}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.vf.ast;

public class ASTNegationExpression extends AbstractVFNode {
public ASTNegationExpression(int id) {
super(id);
}

public ASTNegationExpression(VfParser p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(VfParserVisitor visitor, Object data) {

return visitor.visit(this, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public Object visit(ASTContent node, Object data) {
return visit((VfNode) node, data);
}

@Override
public Object visit(ASTNegationExpression node, Object data) {
return visit((VfNode) node, data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
import net.sourceforge.pmd.lang.vf.ast.ASTNegationExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
Expand Down Expand Up @@ -127,4 +128,8 @@ public Object visit(ASTContent node, Object data) {
return visit((VfNode) node, data);
}

public Object visit(ASTNegationExpression node, Object data) {
return visit((VfNode) node, data);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
import net.sourceforge.pmd.lang.vf.ast.ASTNegationExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.AbstractVFNode;
import net.sourceforge.pmd.lang.vf.rule.AbstractVfRule;
Expand Down Expand Up @@ -245,6 +246,11 @@ private void checkAllOnEventTags(ASTElement node, Object data) {
private boolean startsWithSafeResource(final ASTElExpression el) {
final ASTExpression expression = el.getFirstChildOfType(ASTExpression.class);
if (expression != null) {
final ASTNegationExpression negation = expression.getFirstChildOfType(ASTNegationExpression.class);
if (negation != null) {
return true;
}

final ASTIdentifier id = expression.getFirstChildOfType(ASTIdentifier.class);
if (id != null) {
List<ASTArguments> args = expression.findChildrenOfType(ASTArguments.class);
Expand All @@ -254,8 +260,7 @@ private boolean startsWithSafeResource(final ASTElExpression el) {
case "casesafeid":
case "begins":
case "contains":
case "len":
case "not":
case "len":
case "getrecordids":
case "linkto":
case "sqrt":
Expand Down

0 comments on commit 0386d71

Please sign in to comment.