Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写xpath表达式来查找死代码 这是上述JAVA代码的XML:_Java_Xpath_Xsd_Pmd - Fatal编程技术网

如何编写xpath表达式来查找死代码 这是上述JAVA代码的XML:

如何编写xpath表达式来查找死代码 这是上述JAVA代码的XML:,java,xpath,xsd,pmd,Java,Xpath,Xsd,Pmd,Xpath表达式: //MethodDeclaration[count(ResultType)=1]/Block[(../BlockStatement/Statement/IfStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral/@True)='True'和 (.//BlockStatement/Statement/IfStatement/Statement/Block/BlockStatement

Xpath表达式:

//MethodDeclaration[count(ResultType)=1]/Block[(../BlockStatement/Statement/IfStatement/Expression/PrimaryExpression/PrimaryPrefix/Literal/BooleanLiteral/@True)='True'和 (.//BlockStatement/Statement/IfStatement/Statement/Block/BlockStatement/Statement/ReturnStatement/@SingleLine)='true']/BlockStatement[last()]

如何编写
xpath
表达式来查找死代码
在上面的代码中
System.out.println(“在java中”)这一行是死代码如何通过使用
xpath
expression

找到这一块xpath用于选择XML。用于解析Java或任何其他编程语言的工具是完全错误的。此外,死代码确定需要可达性计算,通常被认为是语义分析,而不仅仅是语法分析。您甚至不能在XPath中实现这一点



更新:您现在发布了一个XML格式的来自PDM的。这比让XPath违背原始Java代码要好,但它仍然不足以进行完整的可达性分析。从PDM中需要的是一个,而这似乎不是PDM的一个功能。

XPath用于选择XML。用于解析Java或任何其他编程语言的工具是完全错误的。此外,死代码确定需要可达性计算,通常被认为是语义分析,而不仅仅是语法分析。您甚至不能在XPath中实现这一点



更新:您现在发布了一个XML格式的来自PDM的。这比让XPath违背原始Java代码要好,但它仍然不足以进行完整的可达性分析。您需要从PDM中获得的是一个,而这似乎不是PDM的一个功能。

它甚至没有编译,因为它是一个无法访问的语句Yes Nicolas。很抱歉,上一篇文章现在我添加了编译代码,这段代码显示System.out.println(“java”)的死代码;如何使用xpath查找死代码expression@NicolasFilotto实际上它是编译的。这是故意的
if(true)
if(false)
是允许的,主要用于测试和调试,类似于C预处理器
#if
块。它甚至不编译,因为它是一个无法访问的语句。Yes Nicolas。很抱歉,上一篇文章现在我添加了编译代码,这段代码显示System.out.println(“java”)的死代码;如何使用xpath表达式查找死代码@
public class IdentifyProblemsInCode {
    public void howToDoInJava_method3() {
        System.out.println("how to do");
        if (true) {
            return;
        }
        System.out.println("in java");
    }
}  
<Block BeginColumn="41" BeginLine="4" EndColumn="5" EndLine="10" FindBoundary="false" Image="" SingleLine="false" containsComment="false">
                            <BlockStatement Allocation="false" BeginColumn="9" BeginLine="5" EndColumn="40" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                <Statement BeginColumn="9" BeginLine="5" EndColumn="40" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                    <StatementExpression BeginColumn="9" BeginLine="5" EndColumn="39" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                        <PrimaryExpression BeginColumn="9" BeginLine="5" EndColumn="39" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                            <PrimaryPrefix BeginColumn="9" BeginLine="5" EndColumn="26" EndLine="5" FindBoundary="false" Image="" SingleLine="true" SuperModifier="false" ThisModifier="false">
                                                <Name BeginColumn="9" BeginLine="5" EndColumn="26" EndLine="5" FindBoundary="false" Image="System.out.println" SingleLine="true"/>
                                            </PrimaryPrefix>
                                            <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="27" BeginLine="5" EndColumn="39" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                                <Arguments ArgumentCount="1" BeginColumn="27" BeginLine="5" EndColumn="39" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                                    <ArgumentList BeginColumn="28" BeginLine="5" EndColumn="38" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                                        <Expression BeginColumn="28" BeginLine="5" EndColumn="38" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                                            <PrimaryExpression BeginColumn="28" BeginLine="5" EndColumn="38" EndLine="5" FindBoundary="false" Image="" SingleLine="true">
                                                                <PrimaryPrefix BeginColumn="28" BeginLine="5" EndColumn="38" EndLine="5" FindBoundary="false" Image="" SingleLine="true" SuperModifier="false" ThisModifier="false">
                                                                    <Literal BeginColumn="28" BeginLine="5" CharLiteral="false" EndColumn="38" EndLine="5" FindBoundary="false" FloatLiteral="false" Image="&quot;how to do&quot;" IntLiteral="false" SingleCharacterStringLiteral="false" SingleLine="true" StringLiteral="true"/>
                                                                </PrimaryPrefix>
                                                            </PrimaryExpression>
                                                        </Expression>
                                                    </ArgumentList>
                                                </Arguments>
                                            </PrimarySuffix>
                                        </PrimaryExpression>
                                    </StatementExpression>
                                </Statement>
                            </BlockStatement>
                            <BlockStatement Allocation="false" BeginColumn="9" BeginLine="6" EndColumn="9" EndLine="8" FindBoundary="false" Image="" SingleLine="false">
                                <Statement BeginColumn="9" BeginLine="6" EndColumn="9" EndLine="8" FindBoundary="false" Image="" SingleLine="false">
                                    <IfStatement BeginColumn="9" BeginLine="6" Else="false" EndColumn="9" EndLine="8" FindBoundary="false" Image="" SingleLine="false">
                                        <Expression BeginColumn="13" BeginLine="6" EndColumn="16" EndLine="6" FindBoundary="false" Image="" SingleLine="true">
                                            <PrimaryExpression BeginColumn="13" BeginLine="6" EndColumn="16" EndLine="6" FindBoundary="false" Image="" SingleLine="true">
                                                <PrimaryPrefix BeginColumn="13" BeginLine="6" EndColumn="16" EndLine="6" FindBoundary="false" Image="" SingleLine="true" SuperModifier="false" ThisModifier="false">
                                                    <Literal BeginColumn="13" BeginLine="6" CharLiteral="false" EndColumn="16" EndLine="6" FindBoundary="false" FloatLiteral="false" Image="" IntLiteral="false" SingleCharacterStringLiteral="false" SingleLine="true" StringLiteral="false">
                                                        <BooleanLiteral BeginColumn="13" BeginLine="6" EndColumn="16" EndLine="6" FindBoundary="false" Image="" SingleLine="true" True="true"/>
                                                    </Literal>
                                                </PrimaryPrefix>
                                            </PrimaryExpression>
                                        </Expression>
                                        <Statement BeginColumn="19" BeginLine="6" EndColumn="9" EndLine="8" FindBoundary="false" Image="" SingleLine="false">
                                            <Block BeginColumn="19" BeginLine="6" EndColumn="9" EndLine="8" FindBoundary="false" Image="" SingleLine="false" containsComment="false">
                                                <BlockStatement Allocation="false" BeginColumn="13" BeginLine="7" EndColumn="19" EndLine="7" FindBoundary="false" Image="" SingleLine="true">
                                                    <Statement BeginColumn="13" BeginLine="7" EndColumn="19" EndLine="7" FindBoundary="false" Image="" SingleLine="true">
                                                        <ReturnStatement BeginColumn="13" BeginLine="7" EndColumn="19" EndLine="7" FindBoundary="false" Image="" SingleLine="true"/>
                                                    </Statement>
                                                </BlockStatement>
                                            </Block>
                                        </Statement>
                                    </IfStatement>
                                </Statement>
                            </BlockStatement>
                            <BlockStatement Allocation="false" BeginColumn="9" BeginLine="9" EndColumn="38" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                <Statement BeginColumn="9" BeginLine="9" EndColumn="38" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                    <StatementExpression BeginColumn="9" BeginLine="9" EndColumn="37" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                        <PrimaryExpression BeginColumn="9" BeginLine="9" EndColumn="37" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                            <PrimaryPrefix BeginColumn="9" BeginLine="9" EndColumn="26" EndLine="9" FindBoundary="false" Image="" SingleLine="true" SuperModifier="false" ThisModifier="false">
                                                <Name BeginColumn="9" BeginLine="9" EndColumn="26" EndLine="9" FindBoundary="false" Image="System.out.println" SingleLine="true"/>
                                            </PrimaryPrefix>
                                            <PrimarySuffix ArgumentCount="1" Arguments="true" ArrayDereference="false" BeginColumn="27" BeginLine="9" EndColumn="37" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                                <Arguments ArgumentCount="1" BeginColumn="27" BeginLine="9" EndColumn="37" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                                    <ArgumentList BeginColumn="28" BeginLine="9" EndColumn="36" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                                        <Expression BeginColumn="28" BeginLine="9" EndColumn="36" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                                            <PrimaryExpression BeginColumn="28" BeginLine="9" EndColumn="36" EndLine="9" FindBoundary="false" Image="" SingleLine="true">
                                                                <PrimaryPrefix BeginColumn="28" BeginLine="9" EndColumn="36" EndLine="9" FindBoundary="false" Image="" SingleLine="true" SuperModifier="false" ThisModifier="false">
                                                                    <Literal BeginColumn="28" BeginLine="9" CharLiteral="false" EndColumn="36" EndLine="9" FindBoundary="false" FloatLiteral="false" Image="&quot;in java&quot;" IntLiteral="false" SingleCharacterStringLiteral="false" SingleLine="true" StringLiteral="true"/>
                                                                </PrimaryPrefix>
                                                            </PrimaryExpression>
                                                        </Expression>
                                                    </ArgumentList>
                                                </Arguments>
                                            </PrimarySuffix>
                                        </PrimaryExpression>
                                    </StatementExpression>
                                </Statement>
                            </BlockStatement>
                        </Block>