use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class RenameMethodProcessor method searchForOuterTypesOfReferences.
private IType[] searchForOuterTypesOfReferences(IMethod[] newNameMethods, IProgressMonitor pm) throws CoreException {
final Set<IType> outerTypesOfReferences = new HashSet<IType>();
SearchPattern pattern = RefactoringSearchEngine.createOrPattern(newNameMethods, IJavaSearchConstants.REFERENCES);
IJavaSearchScope scope = createRefactoringScope(getMethod());
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
Object element = match.getElement();
if (!(element instanceof IMember))
// e.g. an IImportDeclaration for a static method import
return;
IMember member = (IMember) element;
IType declaring = member.getDeclaringType();
if (declaring == null)
return;
IType outer = declaring.getDeclaringType();
if (outer != null)
outerTypesOfReferences.add(declaring);
}
};
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
return outerTypesOfReferences.toArray(new IType[outerTypesOfReferences.size()]);
}
use of org.eclipse.jdt.core.IMember in project che by eclipse.
the class RenameTypeParameterProcessor method createRenameChanges.
/**
* Creates the necessary changes for the renaming of the type parameter.
*
* @param monitor
* the progress monitor to display progress
* @return the status of the operation
* @throws CoreException
* if the change could not be generated
*/
private RefactoringStatus createRenameChanges(IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(monitor);
RefactoringStatus status = new RefactoringStatus();
try {
monitor.beginTask(RefactoringCoreMessages.RenameTypeParameterRefactoring_searching, 2);
ICompilationUnit cu = fTypeParameter.getDeclaringMember().getCompilationUnit();
CompilationUnit root = RefactoringASTParser.parseWithASTProvider(cu, true, null);
CompilationUnitRewrite rewrite = new CompilationUnitRewrite(cu, root);
IMember member = fTypeParameter.getDeclaringMember();
ASTNode declaration = null;
if (member instanceof IMethod) {
declaration = ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, root);
} else if (member instanceof IType) {
declaration = ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, root);
} else {
//$NON-NLS-1$
JavaPlugin.logErrorMessage("Unexpected sub-type of IMember: " + member.getClass().getName());
Assert.isTrue(false);
}
monitor.worked(1);
RenameTypeParameterVisitor visitor = new RenameTypeParameterVisitor(rewrite, fTypeParameter.getNameRange(), status);
if (declaration != null)
declaration.accept(visitor);
fChange = visitor.getResult();
} finally {
monitor.done();
}
return status;
}
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);
}
Aggregations