From d7e89d2498ed98e30a0b9d5bddedfff91596cd03 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 14 Feb 2017 15:49:54 -0800 Subject: [PATCH] Fixed script tag and removed unneeded content AST node --- pmd-visualforce/etc/grammar/VfParser.jjt | 163 +++++++++--------- .../pmd/lang/vf/VfTokenManager.java | 2 +- .../pmd/lang/vf/ast/ASTContent.java | 26 --- .../lang/vf/ast/VfParserVisitorAdapter.java | 4 - .../pmd/lang/vf/rule/AbstractVFRule.java | 5 - .../lang/vf/rule/basic/BasicVFTestRule.java | 7 - .../lang/vf/rule/basic/xml/BasicVFTest.xml | 27 ++- 7 files changed, 101 insertions(+), 133 deletions(-) delete mode 100644 pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ASTContent.java diff --git a/pmd-visualforce/etc/grammar/VfParser.jjt b/pmd-visualforce/etc/grammar/VfParser.jjt index c8c5e49e53..b036cad2dc 100644 --- a/pmd-visualforce/etc/grammar/VfParser.jjt +++ b/pmd-visualforce/etc/grammar/VfParser.jjt @@ -1,15 +1,15 @@ -options { +options { USER_CHAR_STREAM = true; NODE_USES_PARSER=true; UNICODE_INPUT=true; - FORCE_LA_CHECK = false; - IGNORE_CASE = true; - STATIC = false; - + FORCE_LA_CHECK = false; + IGNORE_CASE = true; + STATIC = false; + MULTI=true; VISITOR=true; TRACK_TOKENS = true; -} +} PARSER_BEGIN(VfParser) package net.sourceforge.pmd.lang.vf.ast; @@ -24,7 +24,7 @@ public class VfParser { * Counter used to keep track of unclosed tags */ private OpenTagRegister tagRegister = new OpenTagRegister(); - + /** * Return the contents of a quote. * @param quote String - starting and ending with " or ' @@ -34,7 +34,7 @@ public class VfParser { private static String quoteContent(String quote) { return quote.substring(1, quote.length()-1); } - + /** * Return the contents of a EL expression. * @param expression String - starting with ${ or #{ and ending with } @@ -50,7 +50,7 @@ PARSER_END(VfParser) /** ******************************************************************** */ -/** ************************* JSP LEXICON **************************** */ +/** ************************* VF LEXICON **************************** */ /** ******************************************************************** */ @@ -93,7 +93,7 @@ PARSER_END(VfParser) | <#IDENTIFIER_CHAR: ( | [ "_", "-", ".", ":" ] ) > | <#IDENTIFIER: ()* > | <#XMLNAME: ( | "_" | ":") ()* > -| <#QUOTED_STRING_NO_BREAKS: ( "'" ( ~["'", "\r", "\n"] )* "'" ) +| <#QUOTED_STRING_NO_BREAKS: ( "'" ( ~["'", "\r", "\n"] )* "'" ) | ( "\"" ( ~["\"", "\r", "\n"] )* "\"" ) > | <#QUOTED_STRING: ( "'" ( ~["'"] )* "'" ) | ( "\"" ( ~["\""] )* "\"" ) > | <#WHITESPACE: ( " " | "\t" | "\n" | "\r" ) > @@ -118,7 +118,7 @@ PARSER_END(VfParser) < ()+ > } - TOKEN : + TOKEN : { : StartTagState | : StartTagState @@ -130,12 +130,12 @@ PARSER_END(VfParser) } TOKEN : -{ +{ | )* "}" ) > | |)+ > } - TOKEN : + TOKEN : { )+ > } @@ -198,7 +198,7 @@ PARSER_END(VfParser) TOKEN : { : InTagState -| | : InTagState } @@ -206,21 +206,21 @@ PARSER_END(VfParser) TOKEN : { : InTagState -| | : InTagState } - TOKEN : + TOKEN : { - < COMMENT_END: ("--" (" ")* ">" | "->") > : AfterTagState + < COMMENT_END: ("--" (" ")* ">" | "->") > : AfterTagState | < COMMENT_TEXT: (~[]) > } TOKEN : { - | : AfterTagState + | " | "" | ""> : AfterTagState } /** ******************************************************************** */ @@ -234,8 +234,8 @@ ASTCompilationUnit CompilationUnit() : {} { Prolog() - - Content() + + Content() { return jjtThis; } } @@ -250,7 +250,7 @@ void Prolog() #void : ( CommentTag() )* Declaration() )? - + ( LOOKAHEAD( ( CommentTag() )* DoctypeDeclaration() ) ( CommentTag() )* @@ -261,24 +261,24 @@ void Prolog() #void : /** * Everything between a start-tag and the corresponding end-tag of an element (if an end tag exists). */ -void Content() : +void Content() #void : {} -{ +{ ( Text() | ContentElement() )* } /** * A single (non-text) element that can occur between a start-tag and end-tag of an element. - * + * */ void ContentElement() #void : {} { - ( - CommentTag() - | Element() - | CData() - | HtmlScript() + ( + CommentTag() + | Element() + | CData() + | HtmlScript() ) } @@ -293,21 +293,21 @@ void Text() : StringBuffer content = new StringBuffer(); String tmp; } -{ - ( +{ + ( tmp = UnparsedText() { content.append(tmp); } | tmp = ElExpression() { content.append(tmp); } )+ {jjtThis.setImage(content.toString());} - + } String UnparsedText() : { Token t; } -{ - t = +{ + t = { - jjtThis.setImage(t.image); + jjtThis.setImage(t.image); return t.image; } } @@ -319,23 +319,23 @@ String UnparsedTextNoWhitespace() #UnparsedText : t = ) { - jjtThis.setImage(t.image); + jjtThis.setImage(t.image); return t.image; } } - + /** * Text that contains no single quotes, and that does not contain the start * of a EL expression. */ -String UnparsedTextNoSingleQuotes() #UnparsedText : +String UnparsedTextNoSingleQuotes() #UnparsedText : { Token t; } { - t = - { - jjtThis.setImage(t.image); + t = + { + jjtThis.setImage(t.image); return t.image; } } @@ -344,12 +344,12 @@ String UnparsedTextNoSingleQuotes() #UnparsedText : * Text that contains no double quotes, and that does not contain the start * of a EL expression. */ -String UnparsedTextNoDoubleQuotes() #UnparsedText : +String UnparsedTextNoDoubleQuotes() #UnparsedText : { Token t; } { - t = - { - jjtThis.setImage(t.image); + t = + { + jjtThis.setImage(t.image); return t.image; } } @@ -360,9 +360,9 @@ String UnparsedTextNoDoubleQuotes() #UnparsedText : String ElExpression() : { Token t; } { - t = - { - jjtThis.setImage(expressionContent(t.image)); + t = + { + jjtThis.setImage(expressionContent(t.image)); return t.image; } } @@ -370,9 +370,9 @@ String ElExpression() : String ElExpressionInAttribute() #ElExpression : { Token t; } { - t = - { - jjtThis.setImage(expressionContent(t.image)); + t = + { + jjtThis.setImage(expressionContent(t.image)); return t.image; } } @@ -393,7 +393,7 @@ void CData() : * A XML element, either with a single empty tag, or with a starting and closing tag * with optional contained content. */ -void Element() : +void Element() : { Token startTag; Token endTag; @@ -402,38 +402,38 @@ void Element() : { ( ( - + startTag = { tagName = startTag.image; jjtThis.setName(tagName); tagRegister.openTag(jjtThis); } ) (Attribute())* - ( + ( ( { jjtThis.setEmpty(false);} (Content()) - - ( + + ( endTag = {tagRegister.closeTag(endTag.image);} )? ) - | + | ( { jjtThis.setEmpty(true); jjtThis.setUnclosed(false); } - ) + ) ) ) } -void Attribute() : +void Attribute() : { Token t; } { t = { jjtThis.setName(t.image); } ( - + AttributeValue() ) } @@ -443,7 +443,7 @@ void Attribute() : * EL expressions * are parsed as sub-nodes of the AttributeValue node. */ -void AttributeValue() : +void AttributeValue() : { StringBuffer content = new StringBuffer(); String tmp; @@ -452,29 +452,29 @@ void AttributeValue() : { ( ( - ( ( tmp = UnparsedTextNoDoubleQuotes() + ( ( tmp = UnparsedTextNoDoubleQuotes() | tmp = QuoteIndependentAttributeValueContent() ) { content.append(tmp); } )* - ( + ( | t = { content.append(t.image.substring(0, 1)); } - ) + ) ) | ( ( ( tmp = UnparsedTextNoSingleQuotes() | tmp = QuoteIndependentAttributeValueContent() ) { content.append(tmp); } )* - ( + ( | t = { content.append(t.image.substring(0, 1)); } - ) + ) ) | ( ( ( tmp = UnparsedTextNoWhitespace() | tmp = QuoteIndependentAttributeValueContent() ) { content.append(tmp); } )* - ( ) + ( ) ) - | + | ) { jjtThis.setImage( content.toString() ); } @@ -500,19 +500,19 @@ void CommentTag() : } { - ( t = { content.append(t.image); } )* + ( t = { content.append(t.image); } )* { jjtThis.setImage(content.toString().trim()); } } - + void Declaration() : { Token t; } { - + t = { jjtThis.setName(t.image); } - (Attribute())* + (Attribute())* } @@ -523,7 +523,7 @@ void DoctypeDeclaration() : t = { jjtThis.setName(t.image); } ()? - (DoctypeExternalId() ()?)? + (DoctypeExternalId() ()?)? } @@ -534,17 +534,17 @@ void DoctypeExternalId() : } { ( - - systemLiteral = + + systemLiteral = { jjtThis.setUri(quoteContent(systemLiteral.image)); } ) - | + | ( - - pubIdLiteral = + + pubIdLiteral = { jjtThis.setPublicId(quoteContent(pubIdLiteral.image)); } - - systemLiteral = + + systemLiteral = { jjtThis.setUri(quoteContent(systemLiteral.image)); } ) } @@ -563,10 +563,11 @@ void HtmlScript() : {token_source.SwitchTo(HtmlScriptContentState);} (t = { content.append(t.image); })* { jjtThis.setImage(content.toString().trim());} + ) | ( ) - ) + ) } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfTokenManager.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfTokenManager.java index caf586e216..afbba717f0 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfTokenManager.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfTokenManager.java @@ -11,7 +11,7 @@ import net.sourceforge.pmd.lang.ast.JavaCharStream; import net.sourceforge.pmd.lang.vf.ast.VfParserTokenManager; /** - * JSP Token Manager implementation. + * VF Token Manager implementation. */ public class VfTokenManager implements TokenManager { private final VfParserTokenManager tokenManager; diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ASTContent.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ASTContent.java deleted file mode 100644 index 2697127e5f..0000000000 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ASTContent.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ -/* Generated By:JJTree: Do not edit this line. ASTContent.java */ - -package net.sourceforge.pmd.lang.vf.ast; - -import net.sourceforge.pmd.lang.vf.ast.VfParser; -import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor; - -public class ASTContent extends AbstractVFNode { - public ASTContent(int id) { - super(id); - } - - public ASTContent(VfParser p, int id) { - super(p, id); - } - - /** - * Accept the visitor. * - */ - public Object jjtAccept(VfParserVisitor visitor, Object data) { - return visitor.visit(this, data); - } -} diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParserVisitorAdapter.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParserVisitorAdapter.java index 9a69e3f7a1..6940daa0aa 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParserVisitorAdapter.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParserVisitorAdapter.java @@ -17,10 +17,6 @@ public class VfParserVisitorAdapter implements VfParserVisitor { return visit((VfNode) node, data); } - public Object visit(ASTContent node, Object data) { - return visit((VfNode) node, data); - } - public Object visit(ASTText node, Object data) { return visit((VfNode) node, data); } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/AbstractVFRule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/AbstractVFRule.java index c39248fad6..589478820c 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/AbstractVFRule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/AbstractVFRule.java @@ -18,7 +18,6 @@ import net.sourceforge.pmd.lang.vf.ast.ASTAttributeValue; import net.sourceforge.pmd.lang.vf.ast.ASTCData; import net.sourceforge.pmd.lang.vf.ast.ASTCommentTag; import net.sourceforge.pmd.lang.vf.ast.ASTCompilationUnit; -import net.sourceforge.pmd.lang.vf.ast.ASTContent; import net.sourceforge.pmd.lang.vf.ast.ASTDeclaration; import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeDeclaration; import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeExternalId; @@ -60,10 +59,6 @@ public abstract class AbstractVFRule extends AbstractRule implements VfParserVis return visit((VfNode) node, data); } - public Object visit(ASTContent node, Object data) { - return visit((VfNode) node, data); - } - public Object visit(ASTText node, Object data) { return visit((VfNode) node, data); } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/basic/BasicVFTestRule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/basic/BasicVFTestRule.java index 966406eaf1..29ffcb4189 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/basic/BasicVFTestRule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/basic/BasicVFTestRule.java @@ -9,7 +9,6 @@ import net.sourceforge.pmd.lang.vf.ast.ASTAttributeValue; import net.sourceforge.pmd.lang.vf.ast.ASTCData; import net.sourceforge.pmd.lang.vf.ast.ASTCommentTag; import net.sourceforge.pmd.lang.vf.ast.ASTCompilationUnit; -import net.sourceforge.pmd.lang.vf.ast.ASTContent; import net.sourceforge.pmd.lang.vf.ast.ASTDeclaration; import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeDeclaration; import net.sourceforge.pmd.lang.vf.ast.ASTDoctypeExternalId; @@ -28,12 +27,6 @@ public class BasicVFTestRule extends AbstractVFRule { return super.visit(node, data); } - @Override - public Object visit(ASTContent node, Object data) { - // TODO Auto-generated method stub - return super.visit(node, data); - } - @Override public Object visit(ASTText node, Object data) { // TODO Auto-generated method stub diff --git a/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/rule/basic/xml/BasicVFTest.xml b/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/rule/basic/xml/BasicVFTest.xml index 62007555d0..194dcf1e2b 100644 --- a/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/rule/basic/xml/BasicVFTest.xml +++ b/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/rule/basic/xml/BasicVFTest.xml @@ -6,15 +6,24 @@ Parse the code ]]> 0 -{!jobInfo} - - - - -]]> + + + {!outOfElement} +
{!inElement}
+ + + +
+ +]]> vf