Title: CrossArtefact Information Retrieval
1Cross-Artefact Information Retrieval
- Michael Eichberg
- Klaus Ostermann
- Mira Mezini
- Thorsten Schäfer
2outline
- motivation why do we need cross-artefact
analysis - the tools architecture
- the database
- how to retrieve information introduction to
XQuery - integration in Eclipse
- Examplesdetecting bad smells / violations of
best practices / errors
3a Projects Artefacts are diverse
.properties
XML
Java
4and the stored information is related
5Are these two types related?
public interface Test extends EJBObject
String getText()
?
public class TestBean implements SessionBean
public String getText()
6Are these two types related?
Yes!
public interface Test extends EJBObject
String getText()
?
public class TestBean implements SessionBean
public String getText()
Deployment Descriptor
ltenterprise-beansgt ltsessiongt ltejb-namegtHel
loWorldTestBeanlt/ejb-namegt lthomegtde.tud.xirc.pla
yground.TestHomelt/homegt ltremotegtde.tud.xirc.play
ground.Testlt/remotegt ltejb-classgtde.tud.xirc.play
ground.TestBeanlt/ejb-classgt ltsession-typegtStatel
esslt/session-typegt lttransaction-typegtContainerlt/
transaction-typegt lt/sessiongt lt/enterprise-beansgt
7What is the transaction attribute?
ltenterprise-beansgt ltsessiongt ltejb-namegtHelloWor
ldTestBeanlt/ejb-namegt lthomegtde.tud.xirc.playgrou
nd.TestHomelt/homegt ltremotegtde.tud.xirc.playgroun
d.Testlt/remotegt ltejb-classgtde.tud.xirc.playgroun
d.TestBeanlt/ejb-classgt ltsession-typegtStatelesslt/
session-typegt lttransaction-typegtContainerlt/trans
action-typegt lt/sessiongt lt/enterprise-beansgt ltcont
ainer-transactiongt ltmethodgt ltejb-namegtHelloWorl
dTestBeanlt/ejb-namegt ltmethod-namegtgetTextlt/metho
d-namegt lt/methodgt lttrans-attributegtRequiredlt/tra
ns-attributegt lt/container-transactiongt
Java Code
public interface Test extends EJBObject
String getText() throws RemoteException Str
ing getValue() throws RemoteException String
getValue(int i) throws RemoteException String
getNoValue() throws RemoteException
Deployment Descriptor
8What is the transaction attribute?
ltenterprise-beansgt ltsessiongt ltejb-namegtHelloWor
ldTestBeanlt/ejb-namegt lthomegtde.tud.xirc.playgrou
nd.TestHomelt/homegt ltremotegtde.tud.xirc.playgroun
d.Testlt/remotegt ltejb-classgtde.tud.xirc.playgroun
d.TestBeanlt/ejb-classgt ltsession-typegtStatelesslt/
session-typegt lttransaction-typegtContainerlt/trans
action-typegt lt/sessiongt lt/enterprise-beansgt ltcont
ainer-transactiongt ltmethodgt ltejb-namegtHelloWorl
dTestBeanlt/ejb-namegt ltmethod-namegtgetTextlt/metho
d-namegt lt/methodgt lttrans-attributegtRequiredlt/tra
ns-attributegt lt/container-transactiongt
ltenterprise-beansgt ltsessiongt ltejb-namegtHelloWor
ldTestBeanlt/ejb-namegt lthomegtde.tud.xirc.playgrou
nd.TestHomelt/homegt ltremotegtde.tud.xirc.playgroun
d.Testlt/remotegt ltejb-classgtde.tud.xirc.playgroun
d.TestBeanlt/ejb-classgt ltsession-typegtStatelesslt/
session-typegt lttransaction-typegtContainerlt/trans
action-typegt lt/sessiongt lt/enterprise-beansgt ltcont
ainer-transactiongt ltmethodgt ltejb-namegtHelloWorl
dTestBeanlt/ejb-namegt ltmethod-namegtgetTextlt/metho
d-namegt lt/methodgt lttrans-attributegtRequiredlt/tra
ns-attributegt lt/container-transactiongt
searching the deployment descriptor in the local
FS
Java Code
public interface Test extends EJBObject
String getText() throws RemoteException Str
ing getValue() throws RemoteException String
getValue(int i) throws RemoteException String
getNoValue() throws RemoteException
Deployment Descriptor
9the Architecture of XIRC
Project Sources
.java .class
Query
.jar
XIRC XML-Database
.properties
.xml
10the XML-Database (excerpt)
- ltdball xmlnsdb"http//.../XMLDB(5/20/04)"gt
- ltdbdocument type"source" documentID"file/D/.
../HelloWorld/bin/test/Test.class"
tag"de.tud.xirc.processor.input.ClassFileInputPro
cessor"gt - ltclass xmlns"http//.../BAT2-Java1.5(12/7/04)"
name"test.Test" visibility"public" gt - ltinheritsgt ltclass name"java.lang.Object" /gt
lt/inheritsgt - ltmethod name"ltinitgt" visibility"public" ...gt
- ltsignaturegt ltreturns type"void" /gt lt/signaturegt
- ltcodegt
- ltload index"0" lineNumber"15" /gt
- ltinvoke declaringClassName"java.lang.Object m
ethodName"ltinitgt" specialMethod"true" ...gt - ltsignaturegt ltreturns type"void" /gt
lt/signaturegt - lt/invokegt
- ltreturn lineNumber"15" /gt
- lt/codegt
- lt/methodgt
- lt/classgt
- lt/dbdocumentgt
- lt/dballgt
11a View of the Database in Eclipse
12using XQuery for Information Retrieval
- functional query language especially well suited
for XML Datasources - integrates well with other XML technologies(e.g.
Namespaces) - still under development (but already widely
adopted)
13XQuery Path Expressions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
/
14XQuery Path Expressions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
/ dball
15XQuery Path Expressions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
/ dball/ dbdocument/
16XQuery Path Expressions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
/ dball/ dbdocument/ class
17XQuery Path Expressions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
/ dball/ dbdocument/ class _at_name
test.SubTest
18XQuery Function Variable Definitions
ltdballgt ltdbdocumentgt ltclass name"test.Test"
visibility"public" gt ltinheritsgt ltclass
name"java.lang.Object"/gt lt/inheritsgt lt/classgt lt/
dbdocumentgt ltdbdocumentgt ltclass
name"test.SubTest" visibility"public"
gt ltinheritsgt ltclass nametest.Test"/gt
lt/inheritsgt lt/classgt lt/dbdocumentgt lt/dballgt
supertypes( / dball/dbdocument/ class_at_name
test.SubTest )
declare function supertypes(classes as
element()) as element() let supertypes
xircall/(classinterface) _at_nameclasse
s/inherits/(classinterface)/_at_name return
if (empty(supertypes)) then
classes else classes union
supertypes(supertypes)
19XQuery Set Operations
select all classes that do not define the
toString method
let all xircproject-sources/class_at_abstract
"false" return all except
all/method _at_name"toString" and
empty(./signature/parameter) ( and
./signature/returns/_at_type "java.lang.String"
) /..
20Bad Smells
21a Cross-Artefact Query
detect all methods with bean managed transactions
(BMT) for which container managed transactions
are specified (CMT)
- declare function EJBsWithCMT() as element()
- let ejbname /ejb-jar/enterprise-beans
- /(session message-driven)/transaction-type
- ./text() "Container"/../ejb-class/text()
- return /class_at_name ejbname
-
- declare function methodsWithBMT() as element()
- //invoke_at_declaringClassName
"javax.transaction.UserTransaction"/ - ancestormethod
-
- methodsWithBMT() intersect EJBsWithCMT()//method
22a Cross-Artefact Query
detect all methods with bean managed transactions
(BMT) for which container managed transactions
are specified (CMT)
- declare function EJBsWithCMT() as element()
- let ejbname //ejb-jar/enterprise-beans
- /(session message-driven)/transaction-type
- ./text() "Container"/../ejb-class/text()
- return //class_at_name ejbname
-
- declare function methodsWithBMT() as element()
- //invoke_at_declaringClassName
"javax.transaction.UserTransaction"/ - ancestormethod
-
- methodsWithBMT() intersect EJBsWithCMT()//method
ltenterprise-beansgt ltsessiongt ltejb-namegtHelloWor
ldTestBeanlt/ejb-namegt lthomegtde.tud.xirc.playgrou
nd.TestHomelt/homegt ltremotegtde.tud.xirc.playgroun
d.Testlt/remotegt ltejb-classgtde.tud.xirc.playgroun
d.TestBeanlt/ejb-classgt ltsession-typegtStatelesslt/
session-typegt lttransaction-typegtContainerlt/trans
action-typegt lt/sessiongt lt/enterprise-beansgt
23a Cross-Artefact Query
detect all methods with bean managed transactions
(BMT) for which container managed transactions
are specified (CMT)
- declare function EJBsWithCMT() as element()
- let ejbname //ejb-jar/enterprise-beans
- /(session message-driven)/transaction-type
- ./text() "Container"/../ejb-class/text()
- return //class_at_name ejbname
-
- declare function methodsWithBMT() as element()
- //invoke_at_declaringClassName
"javax.transaction.UserTransaction"/ - ancestormethod
-
- methodsWithBMT() intersect EJBsWithCMT()//method
24a Cross-Artefact Query
detect all methods with bean managed transactions
(BMT) for which container managed transactions
are specified (CMT)
- declare function EJBsWithCMT() as element()
- let ejbname //ejb-jar/enterprise-beans
- /(session message-driven)/transaction-type
- ./text() "Container"/../ejb-class/text()
- return //class_at_name ejbname
-
- declare function methodsWithBMT() as element()
- //invoke_at_declaringClassName
"javax.transaction.UserTransaction"/ - ancestormethod
-
- methodsWithBMT() intersect EJBsWithCMT()//method
25Bad Smells
26performance?
- good but could be improved
- XML database with 2833 class entries(all public
classes and interfaces of all Java5 APIs, except
for classes in the javax.swing. and java.awt.
packages) The evaluation of 48 queries against
the project code generated 51 warnings and 2
errors and was executed in 3.56 seconds. - To keep the XIRC database for this project in
memory approximately 40 MB are required.
27a Query Container
- defines one to multiple related queries
- can define a context defining query(makes sense
only for query containers defining multiple
related queries) - Defines the scope for the evaluation
- DB scoped queries
- easier to develop
- slower for incremental builds
- Document scoped
- very fast with incremental builds
- query is not allowed to take other non-library
documents into account
28a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
29a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
30a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
31a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
32a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
33a Query Container - Example
- ltimplementation_restriction_containergt
- ltscopegtdocumentlt/scopegt
- ltbase-urigtHERElt/base-urigt
- ltcontext_definition_typegtquerylt/context_definition
_typegt - ltcontext_definitiongt
- declare namespace bat "http//.../BAT2-Java1.5
(12/7/04)" - ._at_type"source"/batclass/batmethod/batcode
- lt/context_definitiongt
- ltimplementation_restriction id"UsageOfSystemErrOr
SystemOut"gt - lttitlegtuse of System.err or System.outlt/titlegt
- ltdescriptiongtuse a logging api lt/descriptiongt
- ltseveritygtinfolt/severitygt
- ltquerygt
- declare default element namespace
"http//.../BAT2-Java1.5(12/7/04)" - .//get_at_declaringClassName"java.lang.System"
- and (_at_fieldName"out" or _at_fieldName"err")
34Q A
Q A