Search code examples
javaeclipsecloneeclipse-jdt

How to clone JDT ICompilationUnit


I need to get a copy (deep clone) from org.eclipse.jdt.core.ICompilationUnit. Any suggestion?


Solution

  • Depending on what you need the clone for, getWorkingCopy(...) may be the simple answer. But note, that ICompilationUnits, like all IJavaElements are only handles, computing their details only on demand. Thus, a clone will be little more than a new reference to the same underlying structure.

    PS: If you use working copies, don't forget to discard them, when no longer needed.