Skip to main content

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

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



Back to the top