本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup.getCompilationUnit方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResultGroup.getCompilationUnit方法的具体用法?Java SearchResultGroup.getCompilationUnit怎么用?Java SearchResultGroup.getCompilationUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup
的用法示例。
在下文中一共展示了SearchResultGroup.getCompilationUnit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addReferenceUpdates
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
SearchResultGroup[] grouped = getOccurrences();
for (int i = 0; i < grouped.length; i++) {
SearchResultGroup group = grouped[i];
SearchMatch[] results = group.getSearchResults();
ICompilationUnit cu = group.getCompilationUnit();
TextChange change = manager.get(cu);
for (int j = 0; j < results.length; j++) {
SearchMatch match = results[j];
if (!(match instanceof MethodDeclarationMatch)) {
ReplaceEdit replaceEdit = createReplaceEdit(match, cu);
String editName = RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
addTextEdit(change, editName, replaceEdit);
}
}
}
pm.done();
}
示例2: analyzeRenameChanges
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
static RefactoringStatus analyzeRenameChanges(
TextChangeManager manager,
SearchResultGroup[] oldOccurrences,
SearchResultGroup[] newOccurrences) {
RefactoringStatus result = new RefactoringStatus();
for (int i = 0; i < oldOccurrences.length; i++) {
SearchResultGroup oldGroup = oldOccurrences[i];
SearchMatch[] oldSearchResults = oldGroup.getSearchResults();
ICompilationUnit cunit = oldGroup.getCompilationUnit();
if (cunit == null) continue;
for (int j = 0; j < oldSearchResults.length; j++) {
SearchMatch oldSearchResult = oldSearchResults[j];
if (!RenameAnalyzeUtil.existsInNewOccurrences(oldSearchResult, newOccurrences, manager)) {
addShadowsError(cunit, oldSearchResult, result);
}
}
}
return result;
}
示例3: createTypeReferencesMapping
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private Map<ICompilationUnit, SearchMatch[]> createTypeReferencesMapping(IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
final RefactoringSearchEngine2 engine= new RefactoringSearchEngine2(SearchPattern.createPattern(fType, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
engine.setFiltering(true, true);
engine.setScope(RefactoringScopeFactory.create(fType));
engine.setStatus(status);
engine.searchPattern(new SubProgressMonitor(pm, 1));
final SearchResultGroup[] groups= (SearchResultGroup[]) engine.getResults();
Map<ICompilationUnit, SearchMatch[]> result= new HashMap<ICompilationUnit, SearchMatch[]>();
for (int i= 0; i < groups.length; i++) {
SearchResultGroup group= groups[i];
ICompilationUnit cu= group.getCompilationUnit();
if (cu == null)
continue;
result.put(cu, group.getSearchResults());
}
return result;
}
示例4: removeUnrealReferences
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private SearchResultGroup[] removeUnrealReferences(SearchResultGroup[] groups) {
List<SearchResultGroup> result= new ArrayList<SearchResultGroup>(groups.length);
for (int i= 0; i < groups.length; i++) {
SearchResultGroup group= groups[i];
ICompilationUnit cu= group.getCompilationUnit();
if (cu == null)
continue;
CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
SearchMatch[] allSearchResults= group.getSearchResults();
List<SearchMatch> realConstructorReferences= new ArrayList<SearchMatch>(Arrays.asList(allSearchResults));
for (int j= 0; j < allSearchResults.length; j++) {
SearchMatch searchResult= allSearchResults[j];
if (! isRealConstructorReferenceNode(ASTNodeSearchUtil.getAstNode(searchResult, cuNode)))
realConstructorReferences.remove(searchResult);
}
if (! realConstructorReferences.isEmpty())
result.add(new SearchResultGroup(group.getResource(), realConstructorReferences.toArray(new SearchMatch[realConstructorReferences.size()])));
}
return result.toArray(new SearchResultGroup[result.size()]);
}
示例5: getImplicitConstructorReferencesInClassCreations
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
//XXX workaround for jdt core bug 23112
SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status);
List<SearchMatch> result= new ArrayList<SearchMatch>();
for (int i= 0; i < refs.length; i++) {
SearchResultGroup group= refs[i];
ICompilationUnit cu= group.getCompilationUnit();
if (cu == null)
continue;
CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
SearchMatch[] results= group.getSearchResults();
for (int j= 0; j < results.length; j++) {
SearchMatch searchResult= results[j];
ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode);
if (isImplicitConstructorReferenceNodeInClassCreations(node))
result.add(searchResult);
}
}
return result;
}
示例6: collectAffectedUnits
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* @param searchHits
* @return the set of compilation units that will be affected by this
* particular invocation of this refactoring. This in general includes
* the class containing the constructor in question, as well as all
* call sites to the constructor.
*/
private ICompilationUnit[] collectAffectedUnits(SearchResultGroup[] searchHits) {
Collection<ICompilationUnit> result= new ArrayList<ICompilationUnit>();
boolean hitInFactoryClass= false;
for(int i=0; i < searchHits.length; i++) {
SearchResultGroup rg= searchHits[i];
ICompilationUnit icu= rg.getCompilationUnit();
result.add(icu);
if (icu.equals(fFactoryUnitHandle))
hitInFactoryClass= true;
}
if (!hitInFactoryClass)
result.add(fFactoryUnitHandle);
return result.toArray(new ICompilationUnit[result.size()]);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:24,代码来源:IntroduceFactoryRefactoring.java
示例7: analyzeRenameChanges
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
static RefactoringStatus analyzeRenameChanges(TextChangeManager manager, SearchResultGroup[] oldOccurrences, SearchResultGroup[] newOccurrences) {
RefactoringStatus result= new RefactoringStatus();
for (int i= 0; i < oldOccurrences.length; i++) {
SearchResultGroup oldGroup= oldOccurrences[i];
SearchMatch[] oldSearchResults= oldGroup.getSearchResults();
ICompilationUnit cunit= oldGroup.getCompilationUnit();
if (cunit == null)
continue;
for (int j= 0; j < oldSearchResults.length; j++) {
SearchMatch oldSearchResult= oldSearchResults[j];
if (! RenameAnalyzeUtil.existsInNewOccurrences(oldSearchResult, newOccurrences, manager)){
addShadowsError(cunit, oldSearchResult, result);
}
}
}
return result;
}
示例8: addReferenceUpdates
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager manager, IProgressMonitor pm) {
SearchResultGroup[] grouped= getOccurrences();
for (int i= 0; i < grouped.length; i++) {
SearchResultGroup group= grouped[i];
SearchMatch[] results= group.getSearchResults();
ICompilationUnit cu= group.getCompilationUnit();
TextChange change= manager.get(cu);
for (int j= 0; j < results.length; j++){
SearchMatch match= results[j];
if (!(match instanceof MethodDeclarationMatch)) {
ReplaceEdit replaceEdit= createReplaceEdit(match, cu);
String editName= RefactoringCoreMessages.RenamePrivateMethodRefactoring_update;
addTextEdit(change, editName, replaceEdit);
}
}
}
pm.done();
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:19,代码来源:RenameNonVirtualMethodProcessor.java
示例9: collectAffectedUnits
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* @param searchHits
* @return the set of compilation units that will be affected by this particular invocation of
* this refactoring. This in general includes the class containing the constructor in
* question, as well as all call sites to the constructor.
*/
private ICompilationUnit[] collectAffectedUnits(SearchResultGroup[] searchHits) {
Collection<ICompilationUnit> result = new ArrayList<ICompilationUnit>();
boolean hitInFactoryClass = false;
for (int i = 0; i < searchHits.length; i++) {
SearchResultGroup rg = searchHits[i];
ICompilationUnit icu = rg.getCompilationUnit();
result.add(icu);
if (icu.equals(fFactoryUnitHandle)) hitInFactoryClass = true;
}
if (!hitInFactoryClass) result.add(fFactoryUnitHandle);
return result.toArray(new ICompilationUnit[result.size()]);
}
示例10: excludeBinaryUnits
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* @param groups
* @return an array of <code>SearchResultGroup</code>'s like the argument, but omitting those
* groups that have no corresponding compilation unit (i.e. are binary and therefore can't be
* modified).
*/
private SearchResultGroup[] excludeBinaryUnits(SearchResultGroup[] groups) {
Collection<SearchResultGroup> result = new ArrayList<SearchResultGroup>();
for (int i = 0; i < groups.length; i++) {
SearchResultGroup rg = groups[i];
ICompilationUnit unit = rg.getCompilationUnit();
if (unit != null) // ignore hits within a binary unit
result.add(rg);
else fCallSitesInBinaryUnits = true;
}
return result.toArray(new SearchResultGroup[result.size()]);
}
示例11: addReferenceUpdates
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
private void addReferenceUpdates(TextChangeManager changeManager, ICompilationUnit movedUnit, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException, CoreException {
List<ICompilationUnit> cuList= Arrays.asList(fCus);
SearchResultGroup[] references= getReferences(movedUnit, pm, status);
for (int i= 0; i < references.length; i++) {
SearchResultGroup searchResultGroup= references[i];
ICompilationUnit referencingCu= searchResultGroup.getCompilationUnit();
if (referencingCu == null)
continue;
boolean simpleReferencesNeedNewImport= simpleReferencesNeedNewImport(movedUnit, referencingCu, cuList);
SearchMatch[] results= searchResultGroup.getSearchResults();
for (int j= 0; j < results.length; j++) {
// TODO: should update type references with results from addImport
TypeReference reference= (TypeReference) results[j];
if (reference.isImportDeclaration()) {
ImportRewrite rewrite= getImportRewrite(referencingCu);
IImportDeclaration importDecl= (IImportDeclaration) SearchUtils.getEnclosingJavaElement(results[j]);
if (Flags.isStatic(importDecl.getFlags())) {
rewrite.removeStaticImport(importDecl.getElementName());
addStaticImport(movedUnit, importDecl, rewrite);
} else {
rewrite.removeImport(importDecl.getElementName());
rewrite.addImport(createStringForNewImport(movedUnit, importDecl));
}
} else if (reference.isQualified()) {
TextChange textChange= changeManager.get(referencingCu);
String changeName= RefactoringCoreMessages.MoveCuUpdateCreator_update_references;
TextEdit replaceEdit= new ReplaceEdit(reference.getOffset(), reference.getSimpleNameStart() - reference.getOffset(), fNewPackage);
TextChangeCompatibility.addTextEdit(textChange, changeName, replaceEdit);
} else if (simpleReferencesNeedNewImport) {
ImportRewrite importEdit= getImportRewrite(referencingCu);
String typeName= reference.getSimpleName();
importEdit.addImport(getQualifiedType(fDestination.getElementName(), typeName));
}
}
}
}
示例12: createMethodJavadocReferences
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* Creates the necessary changes to update tag references to the original
* method.
*
* @param rewrites
* the map of compilation units to compilation unit rewrites
* @param declaration
* the source method declaration
* @param groups
* the search result groups representing all references to the
* moved method, including references in comments
* @param status
* the refactoring status
* @param monitor
* the progress monitor to use
*/
protected void createMethodJavadocReferences(Map<ICompilationUnit, CompilationUnitRewrite> rewrites, MethodDeclaration declaration, SearchResultGroup[] groups, RefactoringStatus status, IProgressMonitor monitor) {
Assert.isNotNull(rewrites);
Assert.isNotNull(declaration);
Assert.isNotNull(status);
Assert.isNotNull(monitor);
try {
monitor.beginTask("", groups.length); //$NON-NLS-1$
monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_creating);
SearchMatch[] matches= null;
IJavaElement element= null;
ICompilationUnit unit= null;
CompilationUnitRewrite rewrite= null;
SearchResultGroup group= null;
for (int index= 0; index < groups.length; index++) {
group= groups[index];
element= JavaCore.create(group.getResource());
unit= group.getCompilationUnit();
if (element instanceof ICompilationUnit) {
matches= group.getSearchResults();
unit= (ICompilationUnit) element;
rewrite= getCompilationUnitRewrite(rewrites, unit);
SearchMatch match= null;
for (int offset= 0; offset < matches.length; offset++) {
match= matches[offset];
if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
status.merge(RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_inline_inaccurate, BasicElementLabels.getFileName(unit)), JavaStatusContext.create(unit, new SourceRange(match.getOffset(), match.getLength()))));
} else
createMethodJavadocReference(rewrite, declaration, match, status);
}
}
monitor.worked(1);
}
} finally {
monitor.done();
}
}
示例13: getCus
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* Returns the compilation units that contain the search results.
* @param groups
* @return the CUs
*/
private ICompilationUnit[] getCus(SearchResultGroup[] groups) {
List<ICompilationUnit> result= new ArrayList<ICompilationUnit>(groups.length);
for (int i= 0; i < groups.length; i++) {
SearchResultGroup group= groups[i];
ICompilationUnit cu= group.getCompilationUnit();
if (cu != null) {
result.add(cu);
fCuToSearchResultGroup.put(cu, group);
}
}
return result.toArray(new ICompilationUnit[result.size()]);
}
示例14: excludeBinaryUnits
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* @param groups
* @return an array of <code>SearchResultGroup</code>'s like the argument,
* but omitting those groups that have no corresponding compilation unit
* (i.e. are binary and therefore can't be modified).
*/
private SearchResultGroup[] excludeBinaryUnits(SearchResultGroup[] groups) {
Collection<SearchResultGroup> result= new ArrayList<SearchResultGroup>();
for (int i = 0; i < groups.length; i++) {
SearchResultGroup rg= groups[i];
ICompilationUnit unit= rg.getCompilationUnit();
if (unit != null) // ignore hits within a binary unit
result.add(rg);
else
fCallSitesInBinaryUnits= true;
}
return result.toArray(new SearchResultGroup[result.size()]);
}
示例15: createMethodJavadocReferences
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup; //导入方法依赖的package包/类
/**
* Creates the necessary changes to update tag references to the original
* method.
*
* @param rewrites
* the map of compilation units to compilation unit rewrites
* @param declaration
* the source method declaration
* @param groups
* the search result groups representing all references to the
* moved method, including references in comments
* @param target
* <code>true</code> if a target node must be inserted as first
* argument, <code>false</code> otherwise
* @param status
* the refactoring status
* @param monitor
* the progress monitor to use
*/
protected void createMethodJavadocReferences(final Map<ICompilationUnit, CompilationUnitRewrite> rewrites, final MethodDeclaration declaration, final SearchResultGroup[] groups, final boolean target, final RefactoringStatus status, final IProgressMonitor monitor) {
Assert.isNotNull(rewrites);
Assert.isNotNull(declaration);
Assert.isNotNull(status);
Assert.isNotNull(monitor);
try {
monitor.beginTask("", groups.length); //$NON-NLS-1$
monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_creating);
SearchMatch[] matches= null;
IJavaElement element= null;
ICompilationUnit unit= null;
CompilationUnitRewrite rewrite= null;
SearchResultGroup group= null;
for (int index= 0; index < groups.length; index++) {
group= groups[index];
element= JavaCore.create(group.getResource());
unit= group.getCompilationUnit();
if (element instanceof ICompilationUnit) {
matches= group.getSearchResults();
unit= (ICompilationUnit) element;
rewrite= getCompilationUnitRewrite(rewrites, unit);
SearchMatch match= null;
for (int offset= 0; offset < matches.length; offset++) {
match= matches[offset];
if (match.getAccuracy() == SearchMatch.A_INACCURATE) {
status.merge(RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MoveInstanceMethodProcessor_inline_inaccurate, BasicElementLabels.getFileName(unit)), JavaStatusContext.create(unit, new SourceRange(match.getOffset(), match.getLength()))));
} else
createMethodJavadocReference(rewrite, declaration, match, target, status);
}
}
monitor.worked(1);
}
} finally {
monitor.done();
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:56,代码来源:MoveInstanceMethodProcessor.java