本文整理汇总了Java中org.eclipse.jdt.core.IMember.getCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:Java IMember.getCompilationUnit方法的具体用法?Java IMember.getCompilationUnit怎么用?Java IMember.getCompilationUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IMember
的用法示例。
在下文中一共展示了IMember.getCompilationUnit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
/**
* Creates a new search scope with all compilation units possibly referencing <code>javaElement
* </code>.
*
* @param javaElement the java element
* @param considerVisibility consider visibility of javaElement iff <code>true</code>
* @param sourceReferencesOnly consider references in source only (no references in binary)
* @return the search scope
* @throws JavaModelException if an error occurs
*/
public static IJavaSearchScope create(
IJavaElement javaElement, boolean considerVisibility, boolean sourceReferencesOnly)
throws JavaModelException {
if (considerVisibility & javaElement instanceof IMember) {
IMember member = (IMember) javaElement;
if (JdtFlags.isPrivate(member)) {
if (member.getCompilationUnit() != null)
return SearchEngine.createJavaSearchScope(
new IJavaElement[] {member.getCompilationUnit()});
else return SearchEngine.createJavaSearchScope(new IJavaElement[] {member});
}
// Removed code that does some optimizations regarding package visible members. The problem is
// that
// there can be a package fragment with the same name in a different source folder or project.
// So we
// have to treat package visible members like public or protected members.
}
IJavaProject javaProject = javaElement.getJavaProject();
return SearchEngine.createJavaSearchScope(
getAllScopeElements(javaProject, sourceReferencesOnly), false);
}
示例2: getASTNode
import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
public static ASTNode getASTNode(IJavaElement elem, IProgressMonitor monitor) {
final IMember mem = getIMember(elem);
final ICompilationUnit icu = mem.getCompilationUnit();
if (icu == null)
throw new BinaryElementEncounteredException(Messages.ASTNodeProcessor_SourceNotPresent,
mem);
final ASTNode root = Util.getCompilationUnit(icu, monitor);
return root;
}
示例3: adjustVisibility
import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private RefactoringStatus adjustVisibility(
IMember whoToAdjust,
ModifierKeyword neededVisibility,
boolean alsoIncreaseEnclosing,
IProgressMonitor monitor)
throws CoreException {
Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
if (isRewriteKept(whoToAdjust.getCompilationUnit())) adjustments = fIntermediaryAdjustments;
else adjustments = new HashMap<IMember, IncomingMemberVisibilityAdjustment>();
int existingAdjustments = adjustments.size();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
if (alsoIncreaseEnclosing)
while (whoToAdjust.getDeclaringType() != null) {
whoToAdjust = whoToAdjust.getDeclaringType();
addAdjustment(whoToAdjust, neededVisibility, adjustments);
}
boolean hasNewAdjustments = (adjustments.size() - existingAdjustments) > 0;
if (hasNewAdjustments && ((whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
return RefactoringStatus.createErrorStatus(
Messages.format(
RefactoringCoreMessages
.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility,
new String[] {
JavaElementLabels.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT)
}),
JavaStatusContext.create(whoToAdjust));
RefactoringStatus status = new RefactoringStatus();
// Don't create a rewrite if it is not necessary
if (!hasNewAdjustments) return status;
try {
monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
CompilationUnitRewrite rewrite =
new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
rewrite.setResolveBindings(false);
rewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
status.merge(
rewriteVisibility(
adjustments,
rewrites,
new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
rewrite.attachChange(
(CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()),
true,
new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
}
} finally {
monitor.done();
}
return status;
}