本文整理汇总了Java中org.eclipse.jdt.internal.core.CompilationUnit类的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit类的具体用法?Java CompilationUnit怎么用?Java CompilationUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationUnit类属于org.eclipse.jdt.internal.core包,在下文中一共展示了CompilationUnit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createImportHandle
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Creates an IImportDeclaration from the given import statement
*/
protected IJavaElement createImportHandle(ImportReference importRef) {
char[] importName = CharOperation.concatWith(importRef.getImportName(), '.');
if ((importRef.bits & ASTNode.OnDemand) != 0)
importName = CharOperation.concat(importName, ".*" .toCharArray()); //$NON-NLS-1$
Openable openable = this.currentPossibleMatch.openable;
if (openable instanceof CompilationUnit)
return ((CompilationUnit) openable).getImport(new String(importName));
// binary types do not contain import statements so just answer the top-level type as the element
IType binaryType = ((ClassFile) openable).getType();
String typeName = binaryType.getElementName();
int lastDollar = typeName.lastIndexOf('$');
if (lastDollar == -1) return binaryType;
return createTypeHandle(typeName.substring(0, lastDollar));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:MatchLocator.java
示例2: createTypeHandle
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Creates an IType from the given simple top level type name.
*/
protected IType createTypeHandle(String simpleTypeName) {
Openable openable = this.currentPossibleMatch.openable;
if (openable instanceof CompilationUnit)
return ((CompilationUnit) openable).getType(simpleTypeName);
IType binaryType = ((ClassFile) openable).getType();
String binaryTypeQualifiedName = binaryType.getTypeQualifiedName();
if (simpleTypeName.equals(binaryTypeQualifiedName))
return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type
// type name may be null for anonymous (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=164791)
String classFileName = simpleTypeName.length() == 0 ? binaryTypeQualifiedName : simpleTypeName;
IClassFile classFile = binaryType.getPackageFragment().getClassFile(classFileName + SuffixConstants.SUFFIX_STRING_class);
return classFile.getType();
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:MatchLocator.java
示例3: prepareMoveChange
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareMoveChange(
ChangeInfo changeInfo, org.eclipse.ltk.core.refactoring.Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.MOVE);
for (org.eclipse.ltk.core.refactoring.Change change : ((CompositeChange) ch).getChildren()) {
if (change instanceof MoveCompilationUnitChange) {
MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) change;
String className = moveChange.getCu().getPath().lastSegment();
changeInfo.setPath(
moveChange.getDestinationPackage().getPath().append(className).toString());
changeInfo.setOldPath(
((CompilationUnit) change.getModifiedElement()).getPath().toString());
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:CodeAssist.java
示例4: prepareChangesInfo
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Prepare the information about changes which were applied.
*
* @param changes array of the applied changes
* @param changesInfo prepared list of {@link ChangeInfo}
*/
public void prepareChangesInfo(Change[] changes, List<ChangeInfo> changesInfo) {
for (Change ch : changes) {
if (ch instanceof DynamicValidationStateChange) {
prepareChangesInfo(((DynamicValidationStateChange) ch).getChildren(), changesInfo);
} else {
ChangeInfo changeInfo = DtoFactory.newDto(ChangeInfo.class);
String refactoringName = ch.getName();
if (ch instanceof UndoTextFileChange) {
changeInfo.setName(ChangeInfo.ChangeName.UPDATE);
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
}
if (refactoringName.startsWith("Rename")) {
if (ch instanceof RenameCompilationUnitChange) {
prepareRenameCompilationUnitChange(changeInfo, ch);
} else if (ch instanceof RenamePackageChange) {
prepareRenamePackageChange(changesInfo, changeInfo, ch);
}
}
if (refactoringName.startsWith("Move")) {
prepareMoveChange(changeInfo, ch);
}
changesInfo.add(changeInfo);
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:RefactoringSession.java
示例5: prepareMoveChange
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareMoveChange(ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.MOVE);
if (ch instanceof MoveCompilationUnitChange) {
MoveCompilationUnitChange moveChange = (MoveCompilationUnitChange) ch;
String className = moveChange.getCu().getPath().lastSegment();
changeInfo.setOldPath(
moveChange.getDestinationPackage().getPath().append(className).toString());
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
}
}
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:RefactoringSession.java
示例6: prepareRenameCompilationUnitChange
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
private void prepareRenameCompilationUnitChange(ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.RENAME_COMPILATION_UNIT);
changeInfo.setPath(((CompilationUnit) ch.getModifiedElement()).getPath().toString());
RenameCompilationUnitChange renameChange = (RenameCompilationUnitChange) ch;
changeInfo.setOldPath(
renameChange
.getResourcePath()
.removeLastSegments(1)
.append(renameChange.getNewName())
.toString());
}
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:RefactoringSession.java
示例7: createPackageDeclarationHandle
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Creates an IImportDeclaration from the given import statement
*/
protected IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit) {
if (unit.isPackageInfo()) {
char[] packName = CharOperation.concatWith(unit.currentPackage.getImportName(), '.');
Openable openable = this.currentPossibleMatch.openable;
if (openable instanceof CompilationUnit) {
return ((CompilationUnit) openable).getPackageDeclaration(new String(packName));
}
}
return createTypeHandle(new String(unit.getMainTypeName()));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:MatchLocator.java
示例8: isAffectedByOpenable
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected boolean isAffectedByOpenable(IJavaElementDelta delta, IJavaElement element, int eventType) {
// change to working copy
if (element instanceof CompilationUnit && ((CompilationUnit)element).isWorkingCopy()) {
return super.isAffectedByOpenable(delta, element, eventType);
}
// if no focus, hierarchy is affected if the element is part of the region
if (this.focusType == null) {
return this.region.contains(element);
} else {
return super.isAffectedByOpenable(delta, element, eventType);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:14,代码来源:RegionBasedTypeHierarchy.java
示例9: getContent
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
@SuppressWarnings("restriction")
private static char[] getContent(IType source) throws JavaModelException {
char[] charContent = null;
IOpenable op = source.getOpenable();
if (op instanceof CompilationUnit) {
charContent = ((CompilationUnit) (op)).getContents();
}
if (charContent == null) {
String content = source.getSource();
if (content != null) {
charContent = content.toCharArray();
}
}
return charContent;
}
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:16,代码来源:MarkerUtil.java
示例10: matches
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
@Override
public boolean matches(Object javaElement) {
if (javaElement instanceof IType) {
return super.matches(javaElement);
} else if (javaElement instanceof CompilationUnit) {
// When a java file that is changed is referenced from a ui.xml file,
// eclipse gives a CompilationUnit instead of an IType, so this
// logic is needed for this case.
String enclosingClassName = getFullyQualifiedName();
// if this LogicalType represents an inner class, we want only the outermost
// enclosing class, because the given CompilationUnit represents a
// java file, and hence an outermost class
int dollarIndex = enclosingClassName.indexOf('$');
if (dollarIndex != -1) {
enclosingClassName = enclosingClassName.substring(0, dollarIndex);
}
CompilationUnit cu = ((CompilationUnit) javaElement);
// CompilationUnit class doesn't just give us the full qualified name
// of the top-most class... so we must assemble it ourselves...
IPackageDeclaration[] pkgs;
try {
pkgs = cu.getPackageDeclarations();
} catch (JavaModelException e) {
return false;
}
if (pkgs.length > 0) {
// cu.getElementName() returns a filename, so lop off the extension to get the class name
String className = cu.getElementName().substring(0, cu.getElementName().indexOf('.'));
String cuName = pkgs[0].getElementName() + "." + className;
if (enclosingClassName.equals(cuName)) {
return true;
}
}
}
return false;
}
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:46,代码来源:UiBinderImportReferenceType.java
示例11: createImportContainer
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected ImportContainer createImportContainer(ICompilationUnit parent) {
return new AssistImportContainer((CompilationUnit)parent, this.newElements);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:CompletionUnitStructureRequestor.java
示例12: createPackageDeclaration
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
protected PackageDeclaration createPackageDeclaration(JavaElement parent, String name) {
return new AssistPackageDeclaration((CompilationUnit) parent, name, this.newElements);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:4,代码来源:CompletionUnitStructureRequestor.java
示例13: AssistImportContainer
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
public AssistImportContainer(CompilationUnit parent, Map infoCache) {
super(parent);
this.infoCache = infoCache;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:AssistImportContainer.java
示例14: AssistPackageDeclaration
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
public AssistPackageDeclaration(CompilationUnit parent, String name, Map infoCache) {
super(parent, name);
this.infoCache = infoCache;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:5,代码来源:AssistPackageDeclaration.java
示例15: WorkingCopyDocument
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
super(workingCopy.getPath().toString(), participant);
this.charContents = ((CompilationUnit)workingCopy).getContents();
this.workingCopy = workingCopy;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:6,代码来源:MatchLocator.java
示例16: getAST3
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Returns a resolved AST with {@link AST#JLS3 JLS3} level.
* It is created from the current state of the working copy.
* Creates one if none exists yet.
* Returns <code>null</code> if the current state of the working copy
* doesn't allow the AST to be created (e.g. if the working copy's content
* cannot be parsed).
* <p>
* If the AST level requested during reconciling is not {@link AST#JLS3}
* or if binding resolutions was not requested, then a different AST is created.
* Note that this AST does not become the current AST and it is only valid for
* the requestor.
* </p>
*
* @return the AST created from the current state of the working copy,
* or <code>null</code> if none could be created
* @exception JavaModelException if the contents of the working copy
* cannot be accessed. Reasons include:
* <ul>
* <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @deprecated JLS3 has been deprecated. This method has been replaced by {@link #getAST4()} which returns an AST
* with JLS4 level.
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST3() throws JavaModelException {
if (this.operation.astLevel != AST.JLS3 || !this.operation.resolveBindings) {
// create AST (optionally resolving bindings)
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
parser.setResolveBindings(true);
parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
parser.setSource(this.workingCopy);
parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
}
return this.operation.makeConsistent(this.workingCopy);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:40,代码来源:ReconcileContext.java
示例17: getAST4
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Returns a resolved AST with {@link AST#JLS4 JLS4} level.
* It is created from the current state of the working copy.
* Creates one if none exists yet.
* Returns <code>null</code> if the current state of the working copy
* doesn't allow the AST to be created (e.g. if the working copy's content
* cannot be parsed).
* <p>
* If the AST level requested during reconciling is not {@link AST#JLS4}
* or if binding resolutions was not requested, then a different AST is created.
* Note that this AST does not become the current AST and it is only valid for
* the requestor.
* </p>
*
* @return the AST created from the current state of the working copy,
* or <code>null</code> if none could be created
* @exception JavaModelException if the contents of the working copy
* cannot be accessed. Reasons include:
* <ul>
* <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @deprecated JLS4 has been deprecated. This method has been replaced by {@link #getAST8()} which returns an AST
* with JLS8 level.
* @since 3.7.1
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelException {
if (this.operation.astLevel != AST.JLS4 || !this.operation.resolveBindings) {
// create AST (optionally resolving bindings)
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
parser.setResolveBindings(true);
parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
parser.setSource(this.workingCopy);
parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
}
return this.operation.makeConsistent(this.workingCopy);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:41,代码来源:ReconcileContext.java
示例18: getAST8
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Returns a resolved AST with {@link AST#JLS8 JLS8} level.
* It is created from the current state of the working copy.
* Creates one if none exists yet.
* Returns <code>null</code> if the current state of the working copy
* doesn't allow the AST to be created (e.g. if the working copy's content
* cannot be parsed).
* <p>
* If the AST level requested during reconciling is not {@link AST#JLS8}
* or if binding resolutions was not requested, then a different AST is created.
* Note that this AST does not become the current AST and it is only valid for
* the requestor.
* </p>
*
* @return the AST created from the current state of the working copy,
* or <code>null</code> if none could be created
* @exception JavaModelException if the contents of the working copy
* cannot be accessed. Reasons include:
* <ul>
* <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @since 3.10
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST8() throws JavaModelException {
if (this.operation.astLevel != AST.JLS8 || !this.operation.resolveBindings) {
// create AST (optionally resolving bindings)
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
parser.setResolveBindings(true);
parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
parser.setSource(this.workingCopy);
parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
}
return this.operation.makeConsistent(this.workingCopy);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:ReconcileContext.java
示例19: getAST4
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Returns a resolved AST with {@link AST#JLS4 JLS4} level.
* It is created from the current state of the working copy.
* Creates one if none exists yet.
* Returns <code>null</code> if the current state of the working copy
* doesn't allow the AST to be created (e.g. if the working copy's content
* cannot be parsed).
* <p>
* If the AST level requested during reconciling is not {@link AST#JLS4}
* or if binding resolutions was not requested, then a different AST is created.
* Note that this AST does not become the current AST and it is only valid for
* the requestor.
* </p>
*
* @return the AST created from the current state of the working copy,
* or <code>null</code> if none could be created
* @exception JavaModelException if the contents of the working copy
* cannot be accessed. Reasons include:
* <ul>
* <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li>
* </ul>
* @since 3.7.1
*/
public org.eclipse.jdt.core.dom.CompilationUnit getAST4() throws JavaModelException {
if (this.operation.astLevel != AST.JLS4 || !this.operation.resolveBindings) {
// create AST (optionally resolving bindings)
ASTParser parser = ASTParser.newParser(AST.JLS4);
parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
parser.setResolveBindings(true);
parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
parser.setSource(this.workingCopy);
parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
}
return this.operation.makeConsistent(this.workingCopy);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:39,代码来源:ReconcileContext.java
示例20: newWorkingCopy
import org.eclipse.jdt.internal.core.CompilationUnit; //导入依赖的package包/类
/**
* Returns a new working copy with the given name using this working copy owner to
* create its buffer.
* <p>
* This working copy always belongs to the default package in a package
* fragment root that corresponds to its Java project, and this Java project never exists.
* However this Java project has the given classpath that is used when resolving names
* in this working copy.
* </p><p>
* A DOM AST created using this working copy will have bindings resolved using the given
* classpath, and problem are reported to the given problem requestor.
* <p></p>
* <code>JavaCore#getOptions()</code> is used to create the DOM AST as it is not
* possible to set the options on the non-existing Java project.
* </p><p>
* When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is
* reported on this working copy.
* </p><p>
* Once done with the working copy, users of this method must discard it using
* {@link ICompilationUnit#discardWorkingCopy()}.
* </p><p>
* Note that when such working copy is committed, only its buffer is saved (see
* {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created.
* </p><p>
* This method is not intended to be overriden by clients.
* </p>
*
* @param name the name of the working copy (e.g. "X.java")
* @param classpath the classpath used to resolve names in this working copy
* @param problemRequestor a requestor which will get notified of problems detected during
* reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
* that the client is not interested in problems.
* @param monitor a progress monitor used to report progress while opening the working copy
* or <code>null</code> if no progress should be reported
* @throws JavaModelException if the contents of this working copy can
* not be determined.
* @return a new working copy
* @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
* @since 3.2
*
* @deprecated Use {@link #newWorkingCopy(String, IClasspathEntry[], IProgressMonitor)} instead.
* Note that if this deprecated method is used, problems may be reported twice
* if the given requestor is not the same as the current working copy owner one.
*/
public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
ExternalJavaProject project = new ExternalJavaProject(classpath);
IPackageFragment parent = ((PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject())).getPackageFragment(CharOperation.NO_STRINGS);
CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
result.becomeWorkingCopy(problemRequestor, monitor);
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:52,代码来源:WorkingCopyOwner.java
注:本文中的org.eclipse.jdt.internal.core.CompilationUnit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论