X-Git-Url: http://git.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 2fb069d..4d7be34 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 @@ -1,10 +1,10 @@ /******************************************************************************* * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials + * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -16,7 +16,9 @@ import java.util.Map; import net.sourceforge.phpdt.core.IBuffer; import net.sourceforge.phpdt.core.IBufferFactory; +import net.sourceforge.phpdt.core.ICodeAssist; import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.IImportContainer; import net.sourceforge.phpdt.core.IImportDeclaration; import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.IJavaModelStatusConstants; @@ -40,10 +42,11 @@ import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.jdom.IDOMNode; import net.sourceforge.phpdt.internal.compiler.IProblemFactory; import net.sourceforge.phpdt.internal.compiler.SourceElementParser; +import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration; import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions; import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; +import net.sourceforge.phpdt.internal.core.util.MementoTokenizer; import net.sourceforge.phpdt.internal.core.util.Util; -import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -60,10 +63,9 @@ import org.eclipse.core.runtime.Path; public class CompilationUnit extends Openable implements ICompilationUnit, net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit { public WorkingCopyOwner owner; - /** * Constructs a handle to a compilation unit with the given name in the specified package for the specified owner - * + * * @exception IllegalArgumentException * if the name of the compilation unit does not end with ".java" */ @@ -76,7 +78,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, * Accepts the given visitor onto the parsed tree of this compilation unit, after having runned the name resolution. The visitor's * corresponding visit method is called with the corresponding parse tree. If the visitor returns true, * this method visits this parse node's members. - * + * * @param visitor * the visitor * @exception JavaModelException @@ -162,7 +164,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, if (underlyingResource == null) { underlyingResource = getResource(); } - + SourceElementParser parser = new SourceElementParser(requestor, problemFactory, new CompilerOptions(options)); //, true/*report local declarations*/); @@ -193,7 +195,6 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // update timestamp (might be IResource.NULL_STAMP if original does not exist) unitInfo.timestamp = ((IFile) underlyingResource).getModificationStamp(); - // compute other problems if needed CompilationUnitDeclaration compilationUnitDeclaration = null; try { @@ -206,7 +207,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // if (info instanceof ASTHolderCUInfo) { // int astLevel = ((ASTHolderCUInfo) info).astLevel; - // org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, unit, contents, options, pm); + // net.sourceforge.phpdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevel, unit, contents, options, pm); // ((ASTHolderCUInfo) info).ast = cu; // } } finally { @@ -222,7 +223,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // * @see ICodeAssist#codeComplete(int, ICompletionRequestor) // */ //public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException { - // codeComplete(this, isWorkingCopy() ? (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, + // codeComplete(this, isWorkingCopy() ? (net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit) getOriginalElement() : this, // offset, requestor); //} /** @@ -303,8 +304,8 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // String source = ""; //$NON-NLS-1$ // if (pkg.getElementName().length() > 0) { // //not the default package...add the package declaration - // source = "package " + pkg.getElementName() + ";" + org.eclipse.jdt.internal.compiler.util.ProjectPrefUtil.LINE_SEPARATOR + - // org.eclipse.jdt.internal.compiler.util.ProjectPrefUtil.LINE_SEPARATOR; //$NON-NLS-1$ //$NON-NLS-2$ + // source = "package " + pkg.getElementName() + ";" + net.sourceforge.phpdt.internal.compiler.util.ProjectPrefUtil.LINE_SEPARATOR + + // net.sourceforge.phpdt.internal.compiler.util.ProjectPrefUtil.LINE_SEPARATOR; //$NON-NLS-1$ //$NON-NLS-2$ // } // CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkg, fName, source, force); // runOperation(op, monitor); @@ -347,7 +348,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, /** * Returns true if this handle represents the same Java element as the given handle. - * + * * @see Object#equals(java.lang.Object) */ public boolean equals(Object obj) { @@ -534,7 +535,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, } /** - * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents() + * @see net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit#getContents() */ public char[] getContents() { try { @@ -547,7 +548,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, /** * A compilation unit has a corresponding resource unless it is contained in a jar. - * + * * @see IJavaElement#getCorrespondingResource() */ public IResource getCorrespondingResource() throws JavaModelException { @@ -582,47 +583,68 @@ public class CompilationUnit extends Openable implements ICompilationUnit, public char[] getFileName() { return getElementName().toCharArray(); } + /* + * @see JavaElement + */ + public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner) { + switch (token.charAt(0)) { + case JEM_COUNT: + return getHandleUpdatingCountFromMemento(memento, workingCopyOwner); + case JEM_IMPORTDECLARATION: + JavaElement container = (JavaElement)getImportContainer(); + return container.getHandleFromMemento(token, memento, workingCopyOwner); + case JEM_PACKAGEDECLARATION: + String pkgName = memento.nextToken(); + JavaElement pkgDecl = (JavaElement)getPackageDeclaration(pkgName); + return pkgDecl.getHandleFromMemento(memento, workingCopyOwner); + case JEM_TYPE: + String typeName = memento.nextToken(); + JavaElement type = (JavaElement)getType(typeName); + return type.getHandleFromMemento(memento, workingCopyOwner); + } + return null; + } /** * @see JavaElement#getHandleMementoDelimiter() */ protected char getHandleMementoDelimiter() { - return JavaElement.JEM_COMPILATIONUNIT; + return JavaElement.JEM_COMPILATIONUNIT; } - /** * @see ICompilationUnit#getImport(String) */ public IImportDeclaration getImport(String importName) { - return new ImportDeclaration((ImportContainer) getImportContainer(), importName); + return new ImportDeclaration((ImportContainer)getImportContainer(), importName); } - /** * @see ICompilationUnit#getImportContainer() */ - public ImportContainer getImportContainer() { - return new ImportContainer(this); + public IImportContainer getImportContainer() { + return new ImportContainer(this); } + /** * @see ICompilationUnit#getImports() */ - //public IImportDeclaration[] getImports() throws JavaModelException { - // IImportContainer container= getImportContainer(); - // if (container.exists()) { - // IJavaElement[] elements= container.getChildren(); - // IImportDeclaration[] imprts= new IImportDeclaration[elements.length]; - // System.arraycopy(elements, 0, imprts, 0, elements.length); - // return imprts; - // } else if (!exists()) { - // throw newNotPresentException(); - // } else { - // return new IImportDeclaration[0]; - // } - // - //} + public IImportDeclaration[] getImports() throws JavaModelException { + IImportContainer container= getImportContainer(); + if (container.exists()) { + IJavaElement[] elements= container.getChildren(); + IImportDeclaration[] imprts= new IImportDeclaration[elements.length]; + System.arraycopy(elements, 0, imprts, 0, elements.length); + return imprts; + } else if (!exists()) { + throw newNotPresentException(); + } else { + return new IImportDeclaration[0]; + } + + } + /** - * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getMainTypeName() + * @see net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit#getMainTypeName() */ public char[] getMainTypeName() { String name = getElementName(); @@ -684,7 +706,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, } /** - * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getPackageName() + * @see net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit#getPackageName() */ public char[][] getPackageName() { return null; @@ -787,17 +809,17 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // */ //public IJavaElement getSharedWorkingCopy(IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) // throws JavaModelException { - // + // // // if factory is null, default factory must be used // if (factory == null) factory = this.getBufferManager().getDefaultBufferFactory(); // // JavaModelManager manager = JavaModelManager.getJavaModelManager(); - // + // // // In order to be shared, working copies have to denote the same compilation unit // // AND use the same buffer factory. // // Assuming there is a little set of buffer factories, then use a 2 level Map cache. // Map sharedWorkingCopies = manager.sharedWorkingCopies; - // + // // Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); // if (perFactoryWorkingCopies == null){ // perFactoryWorkingCopies = new HashMap(); @@ -896,7 +918,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, /** * If I am not open, return true to avoid parsing. - * + * * @see IParent#hasChildren() */ public boolean hasChildren() throws JavaModelException { @@ -951,7 +973,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, } /** - * + * * @see IOpenable */ public boolean isOpen() { @@ -1015,7 +1037,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // ASTHolderCUInfo info = new ASTHolderCUInfo(); // info.astLevel = astLevel; // openWhenClosed(info, monitor); - // org.eclipse.jdt.core.dom.CompilationUnit result = info.ast; + // net.sourceforge.phpdt.core.dom.CompilationUnit result = info.ast; // info.ast = null; // return result; // } else { @@ -1027,7 +1049,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, //public net.sourceforge.phpdt.core.dom.CompilationUnit makeConsistent(boolean createAST, int astLevel, IProgressMonitor monitor) // throws JavaModelException { // if (isConsistent()) return null; - // + // // // create a new info and make it the current info // // (this will remove the info and its children just before storing the new infos) // if (createAST) { @@ -1070,7 +1092,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // BufferManager bufManager = getBufferManager(); // IBuffer buffer = getBufferFactory().createBuffer(this); // if (buffer == null) return null; - // + // // // set the buffer source // if (buffer.getCharacters() == null){ // IFile file = (IFile)this.getResource(); @@ -1080,10 +1102,10 @@ public class CompilationUnit extends Openable implements ICompilationUnit, // // // add buffer to buffer cache // bufManager.addBuffer(buffer); - // + // // // listen to buffer changes // buffer.addBufferChangedListener(this); - // + // // return buffer; //} /** @@ -1166,7 +1188,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, * @see ICompilationUnit#reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor) * @since 3.0 */ - //public org.eclipse.jdt.core.dom.CompilationUnit reconcile( + //public net.sourceforge.phpdt.core.dom.CompilationUnit reconcile( public Object reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner workingCopyOwner, IProgressMonitor monitor) throws JavaModelException { @@ -1230,7 +1252,7 @@ public class CompilationUnit extends Openable implements ICompilationUnit, * @deprecated - use codeComplete(int, ICompletionRequestor) */ //public void codeComplete(int offset, final ICodeCompletionRequestor requestor) throws JavaModelException { - // + // // if (requestor == null){ // codeComplete(offset, (ICompletionRequestor)null); // return;