Hi, I wrote a little function to find the dependencies between
typedeclarations. Unfortuntately, I cannot access the caller
typeDeclaration.Instead, only a reference to the target type declaration is
returned. Below you find a code snipped and an example output. The number of
references is correct. However, im not able to access the caller type
declaration. Maybe you got an idea.
System.out.println(" --> found Reference from type : " +
classtypeSource.getName());
}
}
}
Output example:
search Reference for type : Address
--> found Reference from type : Address
--> found Reference from type : Address
--> found Reference from type : Address
search Reference for type : CustomerView
.......
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So you want to get the enclosing type declarations of type references to a
given type declaration. I think it should work if you replace the innermost
loop with
Hi, I wrote a little function to find the dependencies between
typedeclarations. Unfortuntately, I cannot access the caller
typeDeclaration.Instead, only a reference to the target type declaration is
returned. Below you find a code snipped and an example output. The number of
references is correct. However, im not able to access the caller type
declaration. Maybe you got an idea.
thanks fred
public void getDependencies()
{
CrossReferenceServiceConfiguration crsc =
CrossReferenceServiceConfigurationFactory.getInstance();
SourceFileRepository sfr = crsc.getSourceFileRepository();
List<CompilationUnit> allCompilationUnitsFromPath;
allCompilationUnitsFromPath = sfr.getCompilationUnits();
for (CompilationUnit compilationUnit : allCompilationUnitsFromPath)
{
for (int i = 0; i < compilationUnit.getTypeDeclarationCount(); i++)
{
TypeDeclaration typeDeclarationTarget = compilationUnit
.getTypeDeclarationAt(i);
System.out.println("search Reference for type : " +
typeDeclarationTarget.getName());
CrossReferenceSourceInfo crossReferenceSourceInfo =
crsc.getCrossReferenceSourceInfo();
List<TypeReference> typeReferences = crossReferenceSourceInfo
.getReferences(typeDeclarationTarget);
for (TypeReference typeDeclarationReferenceSource : typeReferences)
{
TypeDeclaration classtypeSource = (TypeDeclaration) crsc
.getCrossReferenceSourceInfo().getType(typeDeclarationReferenceSource);
System.out.println(" --> found Reference from type : " +
classtypeSource.getName());
}
}
}
Output example:
search Reference for type : Address
--> found Reference from type : Address
--> found Reference from type : Address
--> found Reference from type : Address
search Reference for type : CustomerView
.......
Hi,
So you want to get the enclosing type declarations of type references to a
given type declaration. I think it should work if you replace the innermost
loop with
TypeDeclaration classtypeSource =
recoder.kit.MiscKit.getParentTypeDeclaration(typeReference);
System.out.println...
Hope this helps!
/Tobias
Hi,
your hint works perfectly fine. Thanks for your help...
cheers
frederik