Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cme-dev] extraction: the sequel

Hi Karel,

It's good to hear from you, and to see that you have made so much progress!

I assume that the AST and related interfaces you are referring to are from
the Eclipse JDT. I am not a JDT expert, but I believe that given a
CompilationUnit you can get the type defined within it, and from that the
members, etc., by name rather than by line number. If I remember correctly,
there are a number of "handle-only" methods the JDT provides for specifying
"handles" to elements that can later be used to access them. So I am going
to assume that each separate artifact you have within a file can be
identified in some more stable way (e.g., by name) by a handle in the JDT
domain, and then discuss how to make use of that within the CME. If this
assumption is wrong, please elaborate. (There is also the issue of whether,
perhaps, each file should be a single Artifact associated with a ConMan
CompoundUnit, like we do for Java classes and interfaces, rather than
having multiple artifacts per file. If the elements you have as separate
artifacts are identifiable by JDT handles then this might work out fine; if
they are more fine-grained than that, then I really have my doubts about
treating them as separate artifacts).

As you probably noted, the CME accepts Object for location, because much of
it doesn't actually use location, and we wanted this to be open. In the
snippet you enclosed in your message, you used CABMethoidOccurrences to
represent your locations, probably because they are the objects in the
existing CME tools that deal with fine-grained elements. But I think in
your case it would be better to create your own location objects, that can
contain whatever information you need, specifically a JDT handle. I believe
this includes the project, so you shouldn't even have to iterate over
projects. Actually, such JDTLocation objects would be generally useful to
anyone else working on JDT artifacts.

I hope this helps. If I haven't really answered you question, please
explain a bit more about what sort of ASTNodes you are treating as separate
artifacts, and why you need to do that.

Regards, Harold




                                                                           
             Karel Bernolet                                                
             <kbernole@xxxxxx.                                             
             be>                                                        To 
             Sent by:                  cme-dev@xxxxxxxxxxx                 
             cme-dev-admin@ecl                                          cc 
             ipse.org                                                      
                                                                   Subject 
                                       [cme-dev] extraction: the sequel    
             12/10/2004 06:11                                              
             PM                                                            
                                                                           
                                                                           
             Please respond to                                             
                  cme-dev                                                  
                                                                           
                                                                           




Hello, me again ..

I've been quite busy to support extracting concerns towards JAsCo
Artifacts.
I am now able to extract the needed information and build the correct
aspects and connectors (still with limitations, but I expect and do hope
that those are only a matter of writing to the code).
When the concern (and thus the aspect) need access to a field, an
appropriate getField method is generated.
The last thing I still have to do is to remove the concern (and related
expressions) from the source code. That works quite well until I have to
extract a concern that has multiple artifacts in the same file.
The reason is that I use the linenumber kept in an artifact to determine
the appropriate ASTNode.
After removing the first artifact from the file, that file is being
rewritten, which invalidates the linenumber encapsulated in that
artifact.
Is there any other way to access the ASTNode related to an artifact?

this is the code I have at the moment:

 ConmanBuilder cb = ConmanBuilder.getConmanBuilder();
 List projects = cb.getCmeProjects();
 for (Iterator iter = _cme.iterator(); iter.hasNext();) {
  try {
   Unit u = (Unit) iter.next();
   Artifact a = u.getDefinition();
   CABMethoidOccurrence cmo =
    (CABMethoidOccurrence) a.getLocation();
   File file = cmo.getFile();
   IFile ifile = null;
   for (Iterator projectIterator = projects.iterator();
    projectIterator.hasNext();
    ) {
    IProject project = (IProject) projectIterator.next();
    IFile tmp =
     project.getFile(file.getPath().replaceAll("null/", ""));
    if (tmp.exists())
     ifile = tmp;
   }
   ICompilationUnit icu =
    JavaCore.createCompilationUnitFrom(ifile);
   CompilationUnit cu = AST.parseCompilationUnit(icu, true);
   ASTFindNode afn = new ASTFindNode(cmo.getLineNumber(), cu);
   cu.accept(afn);

some explanation:
I need to make an ICompilationUnit from each source file to be able to
make a CompilationUnit (ASTNode).
To make such an ICompilationUnit, I need the correct IFile. this can
(only?) be done by requesting the file from the correct IProject.
Therefore I iterate through all the projects currently in the CME
workspace.
The strange replaceAll("null/","") is because all filenames seem to have
a null somewhere in their path (after my home dir). I do think that null
appears because I am testing everything in a run-time workbench.
After I have that CompilationUnit (out of the IFile) I use a visitor
which takes a linenumber and a CompilationUnit to find the correct
ASTNode (visiter = ASTFindNode).

the actual refactorings are done after this code.

To conclude, the problem is that the linenumbers in the artifacts are
not getting update with the corresponding ICompilationUnits.
Is there any way to update those linenumbers, or to access the
corresponding ASTNode without using linenumbers?

if this explanation was not clear enough, or did not provide enough
information, please ask me more.

many thanks,
Karel

_______________________________________________
cme-dev mailing list
cme-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cme-dev




Back to the top