Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation Alex Smirnoff (alexsmr@sympatico.ca) - part of the changes to support Java-like extension (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=71460) /
  
  package org.eclipse.jdt.internal.core;
  
  import java.util.*;
  
  import  org.eclipse.core.resources.*;
  import  org.eclipse.core.runtime.*;
  
  import  org.eclipse.jface.text.BadLocationException;
  import  org.eclipse.jface.text.IDocument;
  
  import  org.eclipse.text.edits.MalformedTreeException;
  import  org.eclipse.text.edits.TextEdit;
  import  org.eclipse.text.edits.UndoEdit;

See also:
ICompilationUnit
  
  public class CompilationUnit extends Openable implements ICompilationUnit, org.eclipse.jdt.internal.compiler.env.ICompilationUnitSuffixConstants {
Internal synonym for deprecated constant AST.JSL2 to alleviate deprecation warnings.

Deprecated:
  
  	/*package*/ static final int JLS2_INTERNAL = .;
  
  	private static final IImportDeclaration[] NO_IMPORTS = new IImportDeclaration[0];
  
  	protected String name;
  	public WorkingCopyOwner owner;

Constructs a handle to a compilation unit with the given name in the specified package for the specified owner
  
  public CompilationUnit(PackageFragment parentString nameWorkingCopyOwner owner) {
  	super(parent);
  	this. = name;
  	this. = owner;
  }
  
  
  /*
   * @see ICompilationUnit#applyTextEdit(TextEdit, IProgressMonitor)
   */
  public UndoEdit applyTextEdit(TextEdit edit, IProgressMonitor monitorthrows JavaModelException {
  	IBuffer buffer = getBuffer();
  	if (buffer instanceof IBuffer.ITextEditCapability) {
  		return ((IBuffer.ITextEditCapabilitybuffer).applyTextEdit(editmonitor);
  	} else if (buffer != null) {
  		IDocument document = buffer instanceof IDocument ? (IDocument) buffer : new DocumentAdapter(buffer);
  		try {
  			UndoEdit undoEditedit.apply(document);
  			return undoEdit;
  		} catch (MalformedTreeException e) {
  		} catch (BadLocationException e) {
  		}
  	}
  	return null// can not happen, there are no compilation units without buffer
  }
  
  /*
   * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
   */
  public void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitorthrows JavaModelException {
  	JavaModelManager manager = JavaModelManager.getJavaModelManager();
  	JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo = manager.getPerWorkingCopyInfo(thisfalse/*don't create*/true /*record usage*/null/*no problem requestor needed*/);
  	if (perWorkingCopyInfo == null) {
  		// close cu and its children
  		close();
  
  		BecomeWorkingCopyOperation operation = new BecomeWorkingCopyOperation(thisproblemRequestor);
 		operation.runOperation(monitor);
 	}
 }
 /*
  * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
  */
 public void becomeWorkingCopy(IProgressMonitor monitorthrows JavaModelException {
 	IProblemRequestor requestor = this. == null ? null : this..getProblemRequestor(this);
 	becomeWorkingCopy(requestormonitor);
 }
 protected boolean buildStructure(OpenableElementInfo infofinal IProgressMonitor pmMap newElements, IResource underlyingResourcethrows JavaModelException {
 
 	// ensure buffer is opened
 	if (buffer == null) {
 		openBuffer(pmunitInfo); // open buffer independently from the info, since we are building the info
 	}
 
 	// generate structure and compute syntax problems if needed
 	CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(thisunitInfonewElements);
 	IJavaProject project = getJavaProject();
 
 	boolean createAST;
 	boolean resolveBindings;
 	int reconcileFlags;
 	HashMap problems;
 	if (info instanceof ASTHolderCUInfo) {
 		ASTHolderCUInfo astHolder = (ASTHolderCUInfoinfo;
 		createAST = astHolder.astLevel != NO_AST;
 		resolveBindings = astHolder.resolveBindings;
 		reconcileFlags = astHolder.reconcileFlags;
 		problems = astHolder.problems;
 	} else {
 		createAST = false;
 		resolveBindings = false;
 		reconcileFlags = 0;
 		problems = null;
 	}
 
 	boolean computeProblems = perWorkingCopyInfo != null && perWorkingCopyInfo.isActive() && project != null && JavaProject.hasJavaNature(project.getProject());
 	IProblemFactory problemFactory = new DefaultProblemFactory();
 	Map options = project == null ? JavaCore.getOptions() : project.getOptions(true);
 	if (!computeProblems) {
 		// disable task tags checking to speed up parsing
 		options.put(.""); //$NON-NLS-1$
 	}
 	CompilerOptions compilerOptions = new CompilerOptions(options);
 	compilerOptions.ignoreMethodBodies = (reconcileFlags & .) != 0;
 		requestor,
 		problemFactory,
 		compilerOptions,
 		true/*report local declarations*/,
 		!createAST /*optimize string literals only if not creating a DOM AST*/);
 	parser.reportOnlyOneSyntaxError = !computeProblems;
 	parser.setMethodsFullRecovery(true);
 
 	if (!computeProblems && !resolveBindings && !createAST// disable javadoc parsing if not computing problems, not resolving and not creating ast
 		parser.javadocParser.checkDocComment = false;
 	requestor.parser = parser;
 
 	// update timestamp (might be IResource.NULL_STAMP if original does not exist)
 	if (underlyingResource == null) {
 		underlyingResource = getResource();
 	}
 	// underlying resource is null in the case of a working copy on a class file in a jar
 	if (underlyingResource != null)
 		unitInfo.timestamp = ((IFile)underlyingResource).getModificationStamp();
 
 	// compute other problems if needed
 	CompilationUnitDeclaration compilationUnitDeclaration = null;
 	try {
 		if (computeProblems) {
 			if (problems == null) {
 				// report problems to the problem requestor
 				problems = new HashMap();
 				compilationUnitDeclaration = CompilationUnitProblemFinder.process(sourceparserthis.problemscreateASTreconcileFlagspm);
 				try {
 					perWorkingCopyInfo.beginReporting();
 					for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) {
 						CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
 						if (categorizedProblems == nullcontinue;
 						for (int i = 0, length = categorizedProblems.lengthi < lengthi++) {
 							perWorkingCopyInfo.acceptProblem(categorizedProblems[i]);
 						}
 					}
 				} finally {
 					perWorkingCopyInfo.endReporting();
 				}
 			} else {
 				// collect problems
 				compilationUnitDeclaration = CompilationUnitProblemFinder.process(sourceparserthis.problemscreateASTreconcileFlagspm);
 			}
 		} else {
 			compilationUnitDeclaration = parser.parseCompilationUnit(sourcetrue /*full parse to find local elements*/pm);
 		}
 
 		if (createAST) {
 			int astLevel = ((ASTHolderCUInfoinfo).;
 			org.eclipse.jdt.core.dom.CompilationUnit cu = AST.convertCompilationUnit(astLevelcompilationUnitDeclarationoptionscomputeProblemssourcereconcileFlagspm);
 			((ASTHolderCUInfoinfo). = cu;
 		}
 	} finally {
 	    if (compilationUnitDeclaration != null) {
 	        compilationUnitDeclaration.cleanUp();
 	    }
 	}
 
 	return unitInfo.isStructureKnown();
 }
 /*
  * Clone this handle so that it caches its contents in memory.
  * DO NOT PASS TO CLIENTS
  */
 	return new CompilationUnit((PackageFragmentthis.this.this.) {
 		private char[] cachedContents;
 		public char[] getContents() {
 			if (this. == null)
 			return this.;
 		}
 			return CompilationUnit.this;
 		}
 	};
 }
 /*
  * @see Openable#canBeRemovedFromCache
  */
 public boolean canBeRemovedFromCache() {
 	if (getPerWorkingCopyInfo() != nullreturn false// working copies should remain in the cache until they are destroyed
 	return super.canBeRemovedFromCache();
 }
 /*
  * @see Openable#canBufferBeRemovedFromCache
  */
 public boolean canBufferBeRemovedFromCache(IBuffer buffer) {
 	if (getPerWorkingCopyInfo() != nullreturn false// working copy buffers should remain in the cache until working copy is destroyed
 	return super.canBufferBeRemovedFromCache(buffer);
 }/*
  * @see IOpenable#close
  */
 public void close() throws JavaModelException {
 	if (getPerWorkingCopyInfo() != nullreturn// a working copy must remain opened until it is discarded
 	super.close();
 }
 /*
  * @see Openable#closing
  */
 protected void closing(Object info) {
 	if (getPerWorkingCopyInfo() == null) {
 		super.closing(info);
 	} // else the buffer of a working copy must remain open for the lifetime of the working copy
 }

Deprecated:
See also:
ICodeAssist.codeComplete(int, ICompletionRequestor)
 
 public void codeComplete(int offsetICompletionRequestor requestorthrows JavaModelException {
 }

Deprecated:
See also:
ICodeAssist.codeComplete(int, ICompletionRequestor, WorkingCopyOwner)
 
 public void codeComplete(int offsetICompletionRequestor requestorWorkingCopyOwner workingCopyOwnerthrows JavaModelException {
 	if (requestor == null) {
 		throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$
 	}
 	codeComplete(offsetnew org.eclipse.jdt.internal.codeassist.CompletionRequestorWrapper(requestor), workingCopyOwner);
 }

Deprecated:
- use codeComplete(int, ICompletionRequestor)
See also:
ICodeAssist.codeComplete(int, ICodeCompletionRequestor)
 
 public void codeComplete(int offsetfinal ICodeCompletionRequestor requestorthrows JavaModelException {
 
 	if (requestor == null){
 		return;
 	}
 		offset,
 			public void acceptAnonymousType(char[] superTypePackageName,char[] superTypeName,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] completionName,int modifiers,int completionStart,int completionEndint relevance){
 				// ignore
 			}
 			public void acceptClass(char[] packageNamechar[] classNamechar[] completionNameint modifiersint completionStartint completionEndint relevance) {
 				requestor.acceptClass(packageNameclassNamecompletionNamemodifierscompletionStartcompletionEnd);
 			}
 			public void acceptError(IProblem error) {
 				// was disabled in 1.0
 			}
 			public void acceptField(char[] declaringTypePackageNamechar[] declaringTypeNamechar[] fieldNamechar[] typePackageNamechar[] typeNamechar[] completionNameint modifiersint completionStartint completionEndint relevance) {
 				requestor.acceptField(declaringTypePackageNamedeclaringTypeNamefieldNametypePackageNametypeNamecompletionNamemodifierscompletionStartcompletionEnd);
 			}
 			public void acceptInterface(char[] packageName,char[] interfaceName,char[] completionName,int modifiers,int completionStart,int completionEndint relevance) {
 				requestor.acceptInterface(packageNameinterfaceNamecompletionNamemodifierscompletionStartcompletionEnd);
 			}
 			public void acceptKeyword(char[] keywordName,int completionStart,int completionEndint relevance){
 				requestor.acceptKeyword(keywordNamecompletionStartcompletionEnd);
 			}
 			public void acceptLabel(char[] labelName,int completionStart,int completionEndint relevance){
 				requestor.acceptLabel(labelNamecompletionStartcompletionEnd);
 			}
 			public void acceptLocalVariable(char[] localVarName,char[] typePackageName,char[] typeName,int modifiers,int completionStart,int completionEndint relevance){
 				// ignore
 			}
 			public void acceptMethod(char[] declaringTypePackageName,char[] declaringTypeName,char[] selector,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] returnTypePackageName,char[] returnTypeName,char[] completionName,int modifiers,int completionStart,int completionEndint relevance){
 				// skip parameter names
 				requestor.acceptMethod(declaringTypePackageNamedeclaringTypeNameselectorparameterPackageNamesparameterTypeNamesreturnTypePackageNamereturnTypeNamecompletionNamemodifierscompletionStartcompletionEnd);
 			}
 			public void acceptMethodDeclaration(char[] declaringTypePackageName,char[] declaringTypeName,char[] selector,char[][] parameterPackageNames,char[][] parameterTypeNames,char[][] parameterNames,char[] returnTypePackageName,char[] returnTypeName,char[] completionName,int modifiers,int completionStart,int completionEndint relevance){
 				// ignore
 			}
 			public void acceptModifier(char[] modifierName,int completionStart,int completionEndint relevance){
 				requestor.acceptModifier(modifierNamecompletionStartcompletionEnd);
 			}
 			public void acceptPackage(char[] packageName,char[] completionName,int completionStart,int completionEndint relevance){
 				requestor.acceptPackage(packageNamecompletionNamecompletionStartcompletionEnd);
 			}
 			public void acceptType(char[] packageName,char[] typeName,char[] completionName,int completionStart,int completionEndint relevance){
 				requestor.acceptType(packageNametypeNamecompletionNamecompletionStartcompletionEnd);
 			}
 			public void acceptVariableName(char[] typePackageName,char[] typeName,char[] varName,char[] completionName,int completionStart,int completionEndint relevance){
 				// ignore
 			}
 		});
 }
 
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor)
  */
 public void codeComplete(int offsetCompletionRequestor requestorthrows JavaModelException {
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.core.runtime.IProgressMonitor)
  */
 public void codeComplete(int offsetCompletionRequestor requestor, IProgressMonitor monitorthrows JavaModelException {
 	codeComplete(offsetrequestor.monitor);
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner)
  */
 public void codeComplete(int offsetCompletionRequestor requestorWorkingCopyOwner workingCopyOwnerthrows JavaModelException {
 	codeComplete(offsetrequestorworkingCopyOwnernull);
 }
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.ICodeAssist#codeComplete(int, org.eclipse.jdt.core.CompletionRequestor, org.eclipse.jdt.core.WorkingCopyOwner, org.eclipse.core.runtime.IProgressMonitor)
  */
 public void codeComplete(int offsetCompletionRequestor requestorWorkingCopyOwner workingCopyOwner, IProgressMonitor monitorthrows JavaModelException {
 			this,
 			offset,
 			requestor,
 			workingCopyOwner,
 			this,
 			monitor);
 }

See also:
ICodeAssist.codeSelect(int, int)
 
 public IJavaElement[] codeSelect(int offsetint lengththrows JavaModelException {
 	return codeSelect(offsetlength.);
 }

See also:
ICodeAssist.codeSelect(int, int, WorkingCopyOwner)
 
 public IJavaElement[] codeSelect(int offsetint lengthWorkingCopyOwner workingCopyOwnerthrows JavaModelException {
 	return super.codeSelect(thisoffsetlengthworkingCopyOwner);
 }

Deprecated:
See also:
IWorkingCopy.commit(boolean, IProgressMonitor)
 
 public void commit(boolean force, IProgressMonitor monitorthrows JavaModelException {
 	commitWorkingCopy(forcemonitor);
 }

See also:
ICompilationUnit.commitWorkingCopy(boolean, IProgressMonitor)
 
 public void commitWorkingCopy(boolean force, IProgressMonitor monitorthrows JavaModelException {
 	op.runOperation(monitor);
 }

See also:
ISourceManipulation.copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
 
 public void copy(IJavaElement containerIJavaElement siblingString renameboolean force, IProgressMonitor monitorthrows JavaModelException {
 	if (container == null) {
 	}
 	IJavaElement[] elements = new IJavaElement[] {this};
 	IJavaElement[] containers = new IJavaElement[] {container};
 	String[] renamings = null;
 	if (rename != null) {
 		renamings = new String[] {rename};
 	}
 	getJavaModel().copy(elementscontainersnullrenamingsforcemonitor);
 }
Returns a new element info for this element.
 
 protected Object createElementInfo() {
 }

See also:
ICompilationUnit.createImport(String, IJavaElement, IProgressMonitor)
 
 public IImportDeclaration createImport(String importNameIJavaElement sibling, IProgressMonitor monitorthrows JavaModelException {
 	return createImport(importNamesibling.monitor);
 }

Since:
3.0
See also:
ICompilationUnit.createImport(String, IJavaElement, int, IProgressMonitor)
 
 public IImportDeclaration createImport(String importNameIJavaElement siblingint flags, IProgressMonitor monitorthrows JavaModelException {
 	CreateImportOperation op = new CreateImportOperation(importNamethisflags);
 	if (sibling != null) {
 		op.createBefore(sibling);
 	}
 	op.runOperation(monitor);
 	return getImport(importName);
 }

See also:
ICompilationUnit.createPackageDeclaration(String, IProgressMonitor)
 
 public IPackageDeclaration createPackageDeclaration(String pkg, IProgressMonitor monitorthrows JavaModelException {
 
 	op.runOperation(monitor);
 	return getPackageDeclaration(pkg);
 }

See also:
ICompilationUnit.createType(String, IJavaElement, boolean, IProgressMonitor)
 
 public IType createType(String contentIJavaElement siblingboolean force, IProgressMonitor monitorthrows JavaModelException {
 	if (!exists()) {
 		//autogenerate this compilation unit
 		String source = ""//$NON-NLS-1$
 		if (!pkg.isDefaultPackage()) {
 			//not the default package...add the package declaration
 			String lineSeparator = Util.getLineSeparator(null/*no existing source*/getJavaProject());
 			source = "package " + pkg.getElementName() + ";"  + lineSeparator + lineSeparator//$NON-NLS-1$ //$NON-NLS-2$
 		}
 		CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkgthis.sourceforce);
 		op.runOperation(monitor);
 	}
 	CreateTypeOperation op = new CreateTypeOperation(thiscontentforce);
 	if (sibling != null) {
 		op.createBefore(sibling);
 	}
 	op.runOperation(monitor);
 	return (ITypeop.getResultElements()[0];
 }

See also:
ISourceManipulation.delete(boolean, IProgressMonitor)
 
 public void delete(boolean force, IProgressMonitor monitorthrows JavaModelException {
 	IJavaElement[] elementsnew IJavaElement[] {this};
 	getJavaModel().delete(elementsforcemonitor);
 }

Deprecated:
See also:
IWorkingCopy.destroy()
 
 public void destroy() {
 	try {
 	} catch (JavaModelException e) {
 	}
 }
 /*
  * @see ICompilationUnit#discardWorkingCopy
  */
 public void discardWorkingCopy() throws JavaModelException {
 	// discard working copy and its children
 	op.runOperation(null);
 }
Returns true if this handle represents the same Java element as the given handle.

See also:
Object.equals(java.lang.Object)
 
 public boolean equals(Object obj) {
 	if (!(obj instanceof CompilationUnit)) return false;
 	return this..equals(other.owner) && super.equals(obj);
 }

See also:
ICompilationUnit.findElements(IJavaElement)
 
 public IJavaElement[] findElements(IJavaElement element) {
 	ArrayList children = new ArrayList();
 	while (element != null && element.getElementType() != .) {
 		children.add(element);
 		element = element.getParent();
 	}
 	if (element == nullreturn null;
 	IJavaElement currentElement = this;
 	for (int i = children.size()-1; i >= 0; i--) {
 		SourceRefElement child = (SourceRefElement)children.get(i);
 		switch (child.getElementType()) {
 				currentElement = ((ICompilationUnit)currentElement).getPackageDeclaration(child.getElementName());
 				break;
 				currentElement = ((ICompilationUnit)currentElement).getImportContainer();
 				break;
 				currentElement = ((IImportContainer)currentElement).getImport(child.getElementName());
 				break;
 				switch (currentElement.getElementType()) {
 						currentElement = ((ICompilationUnit)currentElement).getType(child.getElementName());
 						break;
 						currentElement = ((IType)currentElement).getType(child.getElementName());
 						break;
 						currentElement =  ((IMember)currentElement).getType(child.getElementName(), child.occurrenceCount);
 						break;
 				}
 				break;
 				currentElement = ((IType)currentElement).getInitializer(child.occurrenceCount);
 				break;
 				currentElement = ((IType)currentElement).getField(child.getElementName());
 				break;
 				currentElement = ((IType)currentElement).getMethod(child.getElementName(), ((IMethod)child).getParameterTypes());
 				break;
 		}
 
 	}
 	if (currentElement != null && currentElement.exists()) {
 		return new IJavaElement[] {currentElement};
 	} else {
 		return null;
 	}
 }

See also:
ICompilationUnit.findPrimaryType()
 
 public IType findPrimaryType() {
 	IType primaryTypegetType(typeName);
 	if (primaryType.exists()) {
 		return primaryType;
 	}
 	return null;
 }

Deprecated:
See also:
IWorkingCopy.findSharedWorkingCopy(IBufferFactory)
 
 
 	// if factory is null, default factory must be used
 	if (factory == nullfactory = getBufferManager().getDefaultBufferFactory();
 
 	return findWorkingCopy(BufferFactoryWrapper.create(factory));
 }

See also:
ICompilationUnit.findWorkingCopy(WorkingCopyOwner)
 
 public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner) {
 	CompilationUnit cu = new CompilationUnit((PackageFragment)this.getElementName(), workingCopyOwner);
 	if (workingCopyOwner == .) {
 		return cu;
 	} else {
 		// must be a working copy
 		if (perWorkingCopyInfo != null) {
 			return perWorkingCopyInfo.getWorkingCopy();
 		} else {
 			return null;
 		}
 	}
 }

See also:
ICompilationUnit.getAllTypes()
 
 public IType[] getAllTypes() throws JavaModelException {
 	IJavaElement[] types = getTypes();
 	int i;
 	ArrayList allTypes = new ArrayList(types.length);
 	ArrayList typesToTraverse = new ArrayList(types.length);
 	for (i = 0; i < types.lengthi++) {
 		typesToTraverse.add(types[i]);
 	}
 	while (!typesToTraverse.isEmpty()) {
 		IType type = (ITypetypesToTraverse.get(0);
 		typesToTraverse.remove(type);
 		allTypes.add(type);
 		types = type.getTypes();
 		for (i = 0; i < types.lengthi++) {
 			typesToTraverse.add(types[i]);
 		}
 	}
 	IType[] arrayOfAllTypes = new IType[allTypes.size()];
 	allTypes.toArray(arrayOfAllTypes);
 	return arrayOfAllTypes;
 }

See also:
IMember.getCompilationUnit()
 
 	return this;
 }

See also:
org.eclipse.jdt.internal.compiler.env.ICompilationUnit.getContents()
 
 public char[] getContents() {
 	IBuffer buffer = getBufferManager().getBuffer(this);
 	if (buffer == null) {
 		// no need to force opening of CU to get the content
 		// also this cannot be a working copy, as its buffer is never closed while the working copy is alive
 		IFile file = (IFile) getResource();
 		// Get encoding from file
 		String encoding;
 		try {
 			encoding = file.getCharset();
 		} catch(CoreException ce) {
 			// do not use any encoding
 			encoding = null;
 		}
 		try {
 			return Util.getResourceContentsAsCharArray(fileencoding);
 		} catch (JavaModelException e) {
 			if (JavaModelManager.getJavaModelManager()..get() == .) {
 				IOException ioException =
 				throw new AbortCompilationUnit(nullioExceptionencoding);
 			} else {
 				Util.log(e, Messages.bind(.file.getFullPath().toString()));
 			}
 		}
 	}
 	char[] contents = buffer.getCharacters();
 	if (contents == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129814
 		if (JavaModelManager.getJavaModelManager()..get() == .) {
 			IFile file = (IFile) getResource();
 			// Get encoding from file
 			String encoding;
 			try {
 				encoding = file.getCharset();
 			} catch(CoreException ce) {
 				// do not use any encoding
 				encoding = null;
 			}
 			throw new AbortCompilationUnit(nullioExceptionencoding);
 		}
 	}
 	return contents;
 }
A compilation unit has a corresponding resource unless it is contained in a jar.

See also:
IJavaElement.getCorrespondingResource()
 
 public IResource getCorrespondingResource() throws JavaModelException {
 	if (root == null || root.isArchive()) {
 		return null;
 	} else {
 	}
 }

See also:
ICompilationUnit.getElementAt(int)
 
 public IJavaElement getElementAt(int positionthrows JavaModelException {
 
 	if (e == this) {
 		return null;
 	} else {
 		return e;
 	}
 }
 public String getElementName() {
 	return this.;
 }

See also:
IJavaElement
 
 public int getElementType() {
 }

See also:
org.eclipse.jdt.internal.compiler.env.IDependent.getFileName()
 
 public char[] getFileName(){
 	return getPath().toString().toCharArray();
 }
 
 /*
  * @see JavaElement
  */
 public IJavaElement getHandleFromMemento(String tokenMementoTokenizer mementoWorkingCopyOwner workingCopyOwner) {
 	switch (token.charAt(0)) {
 			return container.getHandleFromMemento(tokenmementoworkingCopyOwner);
 			if (!memento.hasMoreTokens()) return this;
 			String pkgName = memento.nextToken();
 			return pkgDecl.getHandleFromMemento(mementoworkingCopyOwner);
 		case :
 			if (!memento.hasMoreTokens()) return this;
 			String typeName = memento.nextToken();
 			JavaElement type = (JavaElement)getType(typeName);
 			return type.getHandleFromMemento(mementoworkingCopyOwner);
 	}
 	return null;
 }

See also:
JavaElement.getHandleMementoDelimiter()
 
 protected char getHandleMementoDelimiter() {
 }

See also:
ICompilationUnit.getImport(String)
 
 public IImportDeclaration getImport(String importName) {
 	return getImportContainer().getImport(importName);
 }

See also:
ICompilationUnit.getImportContainer()
 
 	return new ImportContainer(this);
 }


See also:
ICompilationUnit.getImports()
 
 	JavaModelManager manager = JavaModelManager.getJavaModelManager();
 	Object info = manager.getInfo(container);
 	if (info == null) {
 		if (manager.getInfo(this) != null)
 			// CU was opened, but no import container, then no imports
 			return ;
 		else {
 			open(null); // force opening of CU
 			info = manager.getInfo(container);
 			if (info == null)
 				// after opening, if no import container, then no imports
 				return ;
 		}
 	}
 	IJavaElement[] elements = ((ImportContainerInfoinfo).;
 	int length = elements.length;
 	IImportDeclaration[] imports = new IImportDeclaration[length];
 	System.arraycopy(elements, 0, imports, 0, length);
 	return imports;
 }

See also:
IMember.getTypeRoot()
 
 public ITypeRoot getTypeRoot() {
 	return this;
 }

See also:
org.eclipse.jdt.internal.compiler.env.ICompilationUnit.getMainTypeName()
 
 public char[] getMainTypeName(){
 }

Deprecated:
See also:
IWorkingCopy.getOriginal(IJavaElement)
 
 public IJavaElement getOriginal(IJavaElement workingCopyElement) {
 	// backward compatibility
 	if (!isWorkingCopy()) return null;
 	if (cu == null || !this..equals(cu.owner)) {
 		return null;
 	}
 
 	return workingCopyElement.getPrimaryElement();
 }

Deprecated:
See also:
IWorkingCopy.getOriginalElement()
 
 	// backward compatibility
 	if (!isWorkingCopy()) return null;
 
 	return getPrimaryElement();
 }
 /*
  * @see ICompilationUnit#getOwner()
  */
 	return isPrimary() || !isWorkingCopy() ? null : this.;
 }

See also:
ICompilationUnit.getPackageDeclaration(String)
 
 	return new PackageDeclaration(thispkg);
 }

See also:
ICompilationUnit.getPackageDeclarations()
 
 	IPackageDeclaration[] arraynew IPackageDeclaration[list.size()];
 	list.toArray(array);
 	return array;
 }

See also:
org.eclipse.jdt.internal.compiler.env.ICompilationUnit.getPackageName()
 
 public char[][] getPackageName() {
 	PackageFragment packageFragment = (PackageFragmentgetParent();
 	if (packageFragment == nullreturn .;
 	return Util.toCharArrays(packageFragment.names);
 }

See also:
IJavaElement.getPath()
 
 public IPath getPath() {
 	if (root == nullreturn new Path(getElementName()); // working copy not in workspace
 	if (root.isArchive()) {
 		return root.getPath();
 	} else {
 		return getParent().getPath().append(getElementName());
 	}
 }
 /*
  * Returns the per working copy info for the receiver, or null if none exist.
  * Note: the use count of the per working copy info is NOT incremented.
  */
 	return JavaModelManager.getJavaModelManager().getPerWorkingCopyInfo(thisfalse/*don't create*/false/*don't record usage*/null/*no problem requestor needed*/);
 }
 /*
  * @see ICompilationUnit#getPrimary()
  */
 }
 /*
  * @see JavaElement#getPrimaryElement(boolean)
  */
 public IJavaElement getPrimaryElement(boolean checkOwner) {
 	if (checkOwner && isPrimary()) return this;
 }
 /*
  * @see Openable#resource(PackageFragmentRoot)
  */
 public IResource resource(PackageFragmentRoot root) {
 	if (root == nullreturn null// working copy not in workspace
 	return ((IContainer) ((Openablethis.).resource(root)).getFile(new Path(getElementName()));
 }

See also:
ISourceReference.getSource()
 
 public String getSource() throws JavaModelException {
 	IBuffer buffer = getBuffer();
 	if (buffer == nullreturn ""//$NON-NLS-1$
 	return buffer.getContents();
 }

See also:
ISourceReference.getSourceRange()
 
 }

See also:
ICompilationUnit.getType(String)
 
 public IType getType(String typeName) {
 	return new SourceType(thistypeName);
 }

See also:
ICompilationUnit.getTypes()
 
 public IType[] getTypes() throws JavaModelException {
 	IType[] arraynew IType[list.size()];
 	list.toArray(array);
 	return array;
 }

See also:
IJavaElement
 
 public IResource getUnderlyingResource() throws JavaModelException {
 	if (isWorkingCopy() && !isPrimary()) return null;
 	return super.getUnderlyingResource();
 }

Deprecated:
See also:
IWorkingCopy.getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
 
 public IJavaElement getSharedWorkingCopy(IProgressMonitor pmIBufferFactory factoryIProblemRequestor problemRequestorthrows JavaModelException {
 
 	// if factory is null, default factory must be used
 	if (factory == nullfactory = getBufferManager().getDefaultBufferFactory();
 
 	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestorpm);
 }

Deprecated:
See also:
IWorkingCopy.getWorkingCopy()
 
 	return getWorkingCopy(null);
 }

See also:
ICompilationUnit.getWorkingCopy(IProgressMonitor)
 
 public ICompilationUnit getWorkingCopy(IProgressMonitor monitorthrows JavaModelException {
 	return getWorkingCopy(new WorkingCopyOwner() {/*non shared working copy*/}, null/*no problem requestor*/monitor);
 }

See also:
ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
 
 public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProgressMonitor monitorthrows JavaModelException {
 	return getWorkingCopy(workingCopyOwnernullmonitor);
 }

Deprecated:
See also:
IWorkingCopy.getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
 
 public IJavaElement getWorkingCopy(IProgressMonitor monitorIBufferFactory factoryIProblemRequestor problemRequestorthrows JavaModelException {
 	return getWorkingCopy(BufferFactoryWrapper.create(factory), problemRequestormonitor);
 }

Deprecated:
See also:
ICompilationUnit.getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
 
 public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwnerIProblemRequestor problemRequestor, IProgressMonitor monitorthrows JavaModelException {
 	if (!isPrimary()) return this;
 
 	JavaModelManager manager = JavaModelManager.getJavaModelManager();
 
 	CompilationUnit workingCopy = new CompilationUnit((PackageFragment)getParent(), getElementName(), workingCopyOwner);
 	JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo =
 		manager.getPerWorkingCopyInfo(workingCopyfalse/*don't create*/true/*record usage*/null/*not used since don't create*/);
 	if (perWorkingCopyInfo != null) {
 		return perWorkingCopyInfo.getWorkingCopy(); // return existing handle instead of the one created above
 	}
 	BecomeWorkingCopyOperation op = new BecomeWorkingCopyOperation(workingCopyproblemRequestor);
 	op.runOperation(monitor);
 	return workingCopy;
 }

See also:
Openable.hasBuffer()
 
 protected boolean hasBuffer() {
 	return true;
 }
 /*
  * @see ICompilationUnit#hasResourceChanged()
  */
 public boolean hasResourceChanged() {
 	if (!isWorkingCopy()) return false;
 
	// if resource got deleted, then #getModificationStamp() will answer IResource.NULL_STAMP, which is always different from the cached
	// timestamp
	Object info = JavaModelManager.getJavaModelManager().getInfo(this);
	if (info == nullreturn false;
	IResource resource = getResource();
	if (resource == nullreturn false;
	return ((CompilationUnitElementInfo)info). != resource.getModificationStamp();
public boolean ignoreOptionalProblems() {

Deprecated:
See also:
IWorkingCopy.isBasedOn(IResource)
public boolean isBasedOn(IResource resource) {
	if (!isWorkingCopy()) return false;
	if (!getResource().equals(resource)) return false;

See also:
IOpenable.isConsistent()
public boolean isConsistent() {
public boolean isPrimary() {

See also:
Openable.isSourceElement()
protected boolean isSourceElement() {
	return true;
protected IStatus validateCompilationUnit(IResource resource) {
	// root never null as validation is not done for working copies
	try {
catch (JavaModelException e) {
	if (resource != null) {
		char[][] inclusionPatterns = ((PackageFragmentRoot)root).fullInclusionPatternChars();
		char[][] exclusionPatterns = ((PackageFragmentRoot)root).fullExclusionPatternChars();
		if (Util.isExcluded(resourceinclusionPatternsexclusionPatterns))
		if (!resource.isAccessible())
 * @see ICompilationUnit#isWorkingCopy()
 */
public boolean isWorkingCopy() {
	// For backward compatibility, non primary working copies are always returning true; in removal
	// delta, clients can still check that element was a working copy before being discarded.
	return !isPrimary() || getPerWorkingCopyInfo() != null;

See also:
IOpenable.makeConsistent(IProgressMonitor)
public void makeConsistent(IProgressMonitor monitorthrows JavaModelException {
	makeConsistent(NO_AST, false/*don't resolve bindings*/, 0 /* don't perform statements recovery */null/*don't collect problems but report them*/monitor);
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(int astLevelboolean resolveBindingsint reconcileFlagsHashMap problems, IProgressMonitor monitorthrows JavaModelException {
	if (isConsistent()) return null;
	try {
		// 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 (astLevel != NO_AST || problems != null) {
			info.astLevel = astLevel;
			info.resolveBindings = resolveBindings;
			info.reconcileFlags = reconcileFlags;
			info.problems = problems;
			openWhenClosed(infotruemonitor);
			org.eclipse.jdt.core.dom.CompilationUnit result = info.ast;
			info.ast = null;
			return result;
else {
			return null;
finally {

See also:
ISourceManipulation.move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
public void move(IJavaElement containerIJavaElement siblingString renameboolean force, IProgressMonitor monitorthrows JavaModelException {
	if (container == null) {
	IJavaElement[] elementsnew IJavaElement[] {this};
	IJavaElement[] containersnew IJavaElement[] {container};
	String[] renamingsnull;
	if (rename != null) {
		renamingsnew String[] {rename};
	getJavaModel().move(elementscontainersnullrenamingsforcemonitor);

See also:
Openable.openBuffer(IProgressMonitor, Object)
protected IBuffer