X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java index 56c944e..feeabcc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/CompilationUnit.java @@ -17,6 +17,7 @@ import java.util.Map; import net.sourceforge.phpdt.core.IBuffer; import net.sourceforge.phpdt.core.IBufferFactory; import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.IImportDeclaration; import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.IJavaModelStatusConstants; import net.sourceforge.phpdt.core.IJavaProject; @@ -24,7 +25,6 @@ import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.IMethod; import net.sourceforge.phpdt.core.IOpenable; import net.sourceforge.phpdt.core.IPackageDeclaration; -import net.sourceforge.phpdt.core.IPackageFragment; import net.sourceforge.phpdt.core.IPackageFragmentRoot; import net.sourceforge.phpdt.core.IParent; import net.sourceforge.phpdt.core.IProblemRequestor; @@ -52,20 +52,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; -import net.sourceforge.phpdt.internal.core.JavaModelManager; -//import net.sourceforge.phpdt.core.dom.AST; -import net.sourceforge.phpdt.internal.core.ReconcileWorkingCopyOperation; - -import net.sourceforge.phpdt.internal.core.DiscardWorkingCopyOperation; - -import net.sourceforge.phpdt.internal.core.CompilationUnitElementInfo; -import net.sourceforge.phpdt.internal.core.JavaModelStatus; - -import net.sourceforge.phpdt.internal.core.BufferManager; -import net.sourceforge.phpdt.internal.core.DefaultWorkingCopyOwner; -import net.sourceforge.phpdt.internal.core.Openable; - -import net.sourceforge.phpdt.internal.core.PackageFragment; /** * @see ICompilationUnit @@ -233,7 +219,8 @@ protected boolean buildStructure(OpenableElementInfo info, final IProgressMonito * @see IWorkingCopy#commit(boolean, IProgressMonitor) */ public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException { - throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this)); + commitWorkingCopy(force, monitor); +// throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this)); } /** * @see ICompilationUnit#commitWorkingCopy(boolean, IProgressMonitor) @@ -454,31 +441,31 @@ public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) { } } } -protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { - -// if (getParent() instanceof JarPackageFragment) { -// // ignore .java files in jar -// throw newNotPresentException(); -// } else { - // put the info now, because getting the contents requires it - JavaModelManager.getJavaModelManager().putInfo(this, info); - CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; - - // generate structure - CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements); - IProblemFactory factory = new DefaultProblemFactory(); - SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true))); -// SourceElementParser parser = new SourceElementParser(requestor, factory); - requestor.parser = parser; - parser.parseCompilationUnit(this, false); - if (isWorkingCopy()) { - CompilationUnit original = (CompilationUnit) getOriginalElement(); - // might be IResource.NULL_STAMP if original does not exist - unitInfo.timestamp = ((IFile) original.getResource()).getModificationStamp(); - } - return unitInfo.isStructureKnown(); -// } -} +//protected boolean generateInfos(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { +// +//// if (getParent() instanceof JarPackageFragment) { +//// // ignore .java files in jar +//// throw newNotPresentException(); +//// } else { +// // put the info now, because getting the contents requires it +// JavaModelManager.getJavaModelManager().putInfo(this, info); +// CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info; +// +// // generate structure +// CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo, newElements); +// IProblemFactory factory = new DefaultProblemFactory(); +// SourceElementParser parser = new SourceElementParser(requestor, factory, new CompilerOptions(getJavaProject().getOptions(true))); +//// SourceElementParser parser = new SourceElementParser(requestor, factory); +// requestor.parser = parser; +// parser.parseCompilationUnit(this, false); +// if (isWorkingCopy()) { +// CompilationUnit original = (CompilationUnit) getOriginalElement(); +// // might be IResource.NULL_STAMP if original does not exist +// unitInfo.timestamp = ((IFile) original.getResource()).getModificationStamp(); +// } +// return unitInfo.isStructureKnown(); +//// } +//} /** * @see ICompilationUnit#getAllTypes() */ @@ -564,15 +551,16 @@ protected char getHandleMementoDelimiter() { /** * @see ICompilationUnit#getImport(String) */ -//public IImportDeclaration getImport(String name) { -// return new ImportDeclaration(getImportContainer(), name); -//} -///** -// * @see ICompilationUnit#getImportContainer() -// */ -//public IImportContainer getImportContainer() { -// return new ImportContainer(this); -//} +public IImportDeclaration getImport(String importName) { + return new ImportDeclaration((ImportContainer)getImportContainer(), importName); +} + +/** + * @see ICompilationUnit#getImportContainer() + */ +public ImportContainer getImportContainer() { + return new ImportContainer(this); +} /** @@ -1108,7 +1096,7 @@ public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) t // } ReconcileWorkingCopyOperation op = new ReconcileWorkingCopyOperation(this, createAST, astLevel, forceProblemDetection, workingCopyOwner); op.runOperation(monitor); -// return op.ast; +// return op.ast; return null; } @@ -1124,12 +1112,20 @@ public void rename(String name, boolean force, IProgressMonitor monitor) throws String[] renamings= new String[] {name}; getJavaModel().rename(elements, dests, renamings, force, monitor); } -/** - * Does nothing - this is not a working copy. - * - * @see IWorkingCopy#restore() + +/* + * @see ICompilationUnit */ public void restore () throws JavaModelException { + + if (!isWorkingCopy()) return; + + CompilationUnit original = (CompilationUnit) getOriginalElement(); + IBuffer buffer = this.getBuffer(); + if (buffer == null) return; + buffer.setContents(original.getContents()); + updateTimeStamp(original); + makeConsistent(null); } /** * @see ICodeAssist#codeComplete(int, ICodeCompletionRequestor) @@ -1209,6 +1205,7 @@ public void restore () throws JavaModelException { // (IPackageFragment)((JavaElement)parent).rootedAt(project), // name); //} + /* * Assume that this is a working copy */