2016-07-21 20 views
0

我在類A中有一個方法m1,它具有類型爲B的變量b,並且m1通過調用b.m2來調用類B中的方法m2(... )。現在,方法m2不是在類B中實現的,而是在派生了B的類C中實現的。如果您在該場景中運行jQAssistant,如果所有三個類都屬於相同的工件,我會得到以下關係: (A) - [:DECLARES] - >(m1) - [:INVOKES] - >(m2)< - [: (B)< - [:EXTENDS] - (C) 和(C) - [:聲明] - >(m2')。 請注意,(B) - [:DECLARES] - >(m2)是一種合成聲明,因爲m2並非由B真正聲明,而是繼承。classPath:Resolve在某些情況下無法正確解析方法調用

但假設A類屬於與B類和C類不同的工件,那麼解析機制不會生成解析類B中的合成聲明。更確切地說,掃描A的工件將生成: (A ) - [:DECLARES] - >(m1) - [:INVOKES] - >(m2'')< - [:DECLARES] - (B')。 並通過classPath解析:Resolve將創建: (B') - [:RESOLVES_TO] - >(B),但不會有(B) - [:DECLARES] - >(m2),因此m2''無法解決到m2。因此,INVOKES關係也無法解決。

+0

聽起來好像必須是固定的一個問題,我可以問你創建一個GitHub上?乾杯,德克 –

回答

0

對我來說,下面的概念工作:

<concept id="missingResolves:AddInheritedMethodsToResolvedTypes"> 
    <requiresConcept refId="classpath:ResolveMember"/> 
    <description>Sometimes the method needed to resolve a method m1 declared in a type t1 is not directly declared in the resolved type t2, but just inherited by t2, then we add this method to t2 (as synthetic-declare).</description> 
    <cypher><![CDATA[ 
    MATCH (t1:Type)-[:RESOLVES_TO]->(t2:Type), (t1)-[:DECLARES]->(m1:Method) 
    WHERE NOT (m1)-[:RESOLVES_TO]->() 
    WITH DISTINCT t2, m1.signature AS methodSignature 
    MERGE (t2)-[:DECLARES {synthetic: true}]->(m2:Method {signature: methodSignature}) 
    RETURN t2.name as type, methodSignature ORDER BY t2.name, methodSignature 
    ]]></cypher> 
</concept> 

<concept id="missingResolves:ResolveMethodsUsingInheritedMethodsInResolvedTypes"> 
    <requiresConcept refId="missingResolves:AddInheritedMethodsToResolvedTypes"/> 
    <description>Uses the synthetic methods added by the "AddInheritedMethodsToResolvedTypes" concept to add missing method resolves.</description> 
    <cypher><![CDATA[ 
    MATCH (t1:Type)-[:RESOLVES_TO]->(t2:Type), (t1)-[:DECLARES]->(m1:Method) 
    WHERE NOT (m1)-[:RESOLVES_TO]->() 
    WITH t1, t2, m1 MATCH (t2)-[:DECLARES {synthetic: true}]->(m2:Method) 
    WHERE m1.signature = m2.signature 
    MERGE (m1)-[:RESOLVES_TO {resolved:true}]->(m2) 
    RETURN count(m1) as ResolvedMethods 
    ]]></cypher> 
</concept> 

<concept id="missingResolves:ResolveInvokesAgain"> 
    <requiresConcept refId="classpath:ResolveInvokes"/> 
    <requiresConcept refId="missingResolves:ResolveMethodsUsingInheritedMethodsInResolvedTypes"/> 
    <description>Resolve method invocations again (same as in original jQAssistant).</description> 
    <cypher><![CDATA[ 
    MATCH (m:Method)-[i:INVOKES]->(m1:Method)-[:RESOLVES_TO]->(m2:Method) 
    WHERE NOT (m)-[:INVOKES{lineNumber:i.lineNumber,resolved:true}]->(m2) 
    MERGE (m)-[:INVOKES{lineNumber:i.lineNumber,resolved:true}]->(m2) 
    RETURN count(i) as ResolvedInvocations  
    ]]></cypher> 
</concept> 

<concept id="missingResolves:Correct"> 
    <requiresConcept refId="classpath:Resolve"/> 
    <requiresConcept refId="missingResolves:ResolveInvokesAgain"/> 
    <description>Performs a complete corrected resolve.</description> 
    <cypher><![CDATA[ 
    MATCH()-[r:RESOLVES_TO]->() RETURN count(r) as ResolvedElements 
    ]]></cypher> 
</concept> 
相關問題