use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class IntroduceIndirectionRefactoring method updateReferences.
private RefactoringStatus updateReferences(IProgressMonitor monitor) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
//$NON-NLS-1$
monitor.beginTask("", 90);
if (monitor.isCanceled())
throw new OperationCanceledException();
IMethod[] ripple = RippleMethodFinder2.getRelatedMethods(fTargetMethod, false, new NoOverrideProgressMonitor(monitor, 10), null);
if (monitor.isCanceled())
throw new OperationCanceledException();
SearchResultGroup[] references = Checks.excludeCompilationUnits(getReferences(ripple, new NoOverrideProgressMonitor(monitor, 10), result), result);
if (result.hasFatalError())
return result;
result.merge(Checks.checkCompileErrorsInAffectedFiles(references));
if (monitor.isCanceled())
throw new OperationCanceledException();
int ticksPerCU = references.length == 0 ? 0 : 70 / references.length;
for (int i = 0; i < references.length; i++) {
SearchResultGroup group = references[i];
SearchMatch[] searchResults = group.getSearchResults();
CompilationUnitRewrite currentCURewrite = getCachedCURewrite(group.getCompilationUnit());
for (int j = 0; j < searchResults.length; j++) {
SearchMatch match = searchResults[j];
if (match.isInsideDocComment())
continue;
IMember enclosingMember = (IMember) match.getElement();
ASTNode target = getSelectedNode(group.getCompilationUnit(), currentCURewrite.getRoot(), match.getOffset(), match.getLength());
if (target instanceof SuperMethodInvocation) {
// Cannot retarget calls to super - add a warning
result.merge(createWarningAboutCall(enclosingMember, target, RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_super_keyword));
continue;
}
//$NON-NLS-1$
Assert.isTrue(target instanceof MethodInvocation, "Element of call should be a MethodInvocation.");
MethodInvocation invocation = (MethodInvocation) target;
ITypeBinding typeBinding = getExpressionType(invocation);
if (fIntermediaryFirstParameterType == null) {
// no highest type yet
fIntermediaryFirstParameterType = typeBinding.getTypeDeclaration();
} else {
// check if current type is higher
result.merge(findCommonParent(typeBinding.getTypeDeclaration()));
}
if (result.hasFatalError())
return result;
// create an edit for this particular call
result.merge(updateMethodInvocation(invocation, enclosingMember, currentCURewrite));
// does call see the intermediary method?
// => increase visibility of the type of the intermediary method.
result.merge(adjustVisibility(fIntermediaryType, enclosingMember.getDeclaringType(), new NoOverrideProgressMonitor(monitor, 0)));
if (monitor.isCanceled())
throw new OperationCanceledException();
}
if (!isRewriteKept(group.getCompilationUnit()))
createChangeAndDiscardRewrite(group.getCompilationUnit());
monitor.worked(ticksPerCU);
}
monitor.done();
return result;
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class RefactoringAvailabilityTester method isPullUpAvailable.
public static boolean isPullUpAvailable(final IStructuredSelection selection) throws JavaModelException {
if (!selection.isEmpty()) {
if (selection.size() == 1) {
if (selection.getFirstElement() instanceof ICompilationUnit)
// Do not force opening
return true;
final IType type = getSingleSelectedType(selection);
if (type != null)
return Checks.isAvailable(type) && isPullUpAvailable(new IType[] { type });
}
for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
if (!(iterator.next() instanceof IMember))
return false;
}
final Set<IMember> members = new HashSet<IMember>();
@SuppressWarnings("unchecked") List<IMember> selectionList = (List<IMember>) (List<?>) Arrays.asList(selection.toArray());
members.addAll(selectionList);
return isPullUpAvailable(members.toArray(new IMember[members.size()]));
}
return false;
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class RefactoringAvailabilityTester method isExtractSupertypeAvailable.
public static boolean isExtractSupertypeAvailable(final IStructuredSelection selection) throws JavaModelException {
if (!selection.isEmpty()) {
if (selection.size() == 1) {
if (selection.getFirstElement() instanceof ICompilationUnit)
// Do not force opening
return true;
final IType type = getSingleSelectedType(selection);
if (type != null)
return Checks.isAvailable(type) && isExtractSupertypeAvailable(new IType[] { type });
}
for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
if (!(iterator.next() instanceof IMember))
return false;
}
final Set<IMember> members = new HashSet<IMember>();
@SuppressWarnings("unchecked") List<IMember> selectionList = (List<IMember>) (List<?>) Arrays.asList(selection.toArray());
members.addAll(selectionList);
return isExtractSupertypeAvailable(members.toArray(new IMember[members.size()]));
}
return false;
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class RefactoringAvailabilityTester method isInlineMethodAvailable.
public static boolean isInlineMethodAvailable(final JavaTextSelection selection) throws JavaModelException {
final IJavaElement[] elements = selection.resolveElementAtOffset();
if (elements.length != 1) {
IJavaElement enclosingElement = selection.resolveEnclosingElement();
if (!(enclosingElement instanceof IMember))
return false;
ITypeRoot typeRoot = ((IMember) enclosingElement).getTypeRoot();
CompilationUnit compilationUnit = selection.resolvePartialAstAtOffset();
if (compilationUnit == null)
return false;
return getInlineableMethodNode(typeRoot, compilationUnit, selection.getOffset(), selection.getLength()) != null;
}
IJavaElement element = elements[0];
if (!(element instanceof IMethod))
return false;
IMethod method = (IMethod) element;
if (!isInlineMethodAvailable((method)))
return false;
// in binary class, only activate for method declarations
IJavaElement enclosingElement = selection.resolveEnclosingElement();
if (enclosingElement == null || enclosingElement.getAncestor(IJavaElement.CLASS_FILE) == null)
return true;
if (!(enclosingElement instanceof IMethod))
return false;
IMethod enclosingMethod = (IMethod) enclosingElement;
if (enclosingMethod.isConstructor())
return false;
int nameOffset = enclosingMethod.getNameRange().getOffset();
int nameLength = enclosingMethod.getNameRange().getLength();
return (nameOffset <= selection.getOffset()) && (selection.getOffset() + selection.getLength() <= nameOffset + nameLength);
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class JavaElementLabelComposer method appendTypeParameterLabel.
/**
* Appends the styled label for a type parameter.
*
* @param typeParameter the element to render
* @param flags the rendering flags. Flags with names starting with 'T_' are considered.
*/
public void appendTypeParameterLabel(ITypeParameter typeParameter, long flags) {
try {
appendTypeParameterWithBounds(typeParameter, flags);
// post qualification
if (getFlag(flags, JavaElementLabels.TP_POST_QUALIFIED)) {
fBuffer.append(JavaElementLabels.CONCAT_STRING);
IMember declaringMember = typeParameter.getDeclaringMember();
appendElementLabel(declaringMember, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
}
} catch (JavaModelException e) {
// NotExistsException will not reach this point
JavaPlugin.log(e);
}
}
Aggregations