use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class MemberVisibilityAdjustor method adjustVisibility.
/**
* Adjusts the visibilities of the referenced and referencing elements.
*
* @param monitor the progress monitor to use
* @throws JavaModelException if an error occurs during search
*/
public final void adjustVisibility(final IProgressMonitor monitor) throws JavaModelException {
try {
//$NON-NLS-1$
monitor.beginTask("", 7);
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(SearchPattern.createPattern(fReferenced, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE));
engine.setScope(fScope);
engine.setStatus(fStatus);
engine.setOwner(fOwner);
if (fIncoming) {
// check calls to the referenced (moved) element, adjust element
// visibility if necessary.
engine.searchPattern(new SubProgressMonitor(monitor, 1));
adjustIncomingVisibility((SearchResultGroup[]) engine.getResults(), new SubProgressMonitor(monitor, 1));
engine.clearResults();
// of the type if they are accessed outside of the moved type
if (fReferenced instanceof IType) {
final IType type = (IType) fReferenced;
adjustMemberVisibility(type, new SubProgressMonitor(monitor, 1));
}
}
if (fOutgoing) {
/*
* Search for the types, fields, and methods which
* are called/acted upon inside the referenced element (the one
* to be moved) and assure that they are also visible from
* within the referencing element (the destination type (or
* package if move to new type)).
*/
engine.searchReferencedTypes(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
engine.searchReferencedFields(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
engine.searchReferencedMethods(fReferenced, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
adjustOutgoingVisibility((SearchResultGroup[]) engine.getResults(), new SubProgressMonitor(monitor, 1));
}
} finally {
monitor.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class MemberVisibilityAdjustor method thresholdTypeToType.
/**
* Returns the visibility threshold from a type to another type.
*
* @param referencing the referencing type
* @param referenced the referenced type
* @param monitor the progress monitor to use
* @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
* @throws JavaModelException if the java elements could not be accessed
*/
private ModifierKeyword thresholdTypeToType(final IType referencing, final IType referenced, final IProgressMonitor monitor) throws JavaModelException {
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
final ICompilationUnit referencedUnit = referenced.getCompilationUnit();
if (referencing.equals(referenced.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else {
final ITypeHierarchy hierarchy = getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
final IType[] types = hierarchy.getSupertypes(referencing);
IType superType = null;
for (int index = 0; index < types.length; index++) {
superType = types[index];
if (superType.equals(referenced)) {
keyword = null;
return keyword;
}
}
}
final ICompilationUnit typeUnit = referencing.getCompilationUnit();
if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
if (referenced.getDeclaringType() != null)
keyword = null;
else
keyword = ModifierKeyword.PRIVATE_KEYWORD;
} else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
keyword = null;
return keyword;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class IntroduceFactoryRefactoring method findNonPrimaryType.
private IType findNonPrimaryType(String fullyQualifiedName, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
SearchPattern p = SearchPattern.createPattern(fullyQualifiedName, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(p);
engine.setFiltering(true, true);
engine.setScope(RefactoringScopeFactory.create(fCtorBinding.getJavaElement().getJavaProject()));
engine.setStatus(status);
engine.searchPattern(new SubProgressMonitor(pm, 1));
SearchResultGroup[] groups = (SearchResultGroup[]) engine.getResults();
if (groups.length != 0) {
for (int i = 0; i < groups.length; i++) {
SearchMatch[] matches = groups[i].getSearchResults();
for (int j = 0; j < matches.length; j++) {
if (matches[j].getAccuracy() == SearchMatch.A_ACCURATE)
return (IType) matches[j].getElement();
}
}
}
return null;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class IntroduceFactoryRefactoring method searchForCallsTo.
/**
* Search for all calls to the given <code>IMethodBinding</code> in the project
* that contains the compilation unit <code>fCUHandle</code>.
* @param methodBinding
* @param pm
* @param status
* @return an array of <code>SearchResultGroup</code>'s that identify the search matches
* @throws JavaModelException
*/
private SearchResultGroup[] searchForCallsTo(IMethodBinding methodBinding, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
IMethod method = (IMethod) methodBinding.getJavaElement();
final RefactoringSearchEngine2 engine = new RefactoringSearchEngine2(createSearchPattern(method, methodBinding));
engine.setFiltering(true, true);
engine.setScope(createSearchScope(method, methodBinding));
engine.setStatus(status);
engine.searchPattern(new SubProgressMonitor(pm, 1));
return (SearchResultGroup[]) engine.getResults();
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class IntroduceIndirectionRefactoring method adjustVisibility.
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;
}
Aggregations