use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class IntroduceIndirectionRefactoring method updateTargetVisibility.
private RefactoringStatus updateTargetVisibility(IProgressMonitor monitor) throws JavaModelException, CoreException {
RefactoringStatus result = new RefactoringStatus();
// Adjust the visibility of the method and of the referenced type. Note that
// the target method may not be in the target type; and in this case, the type
// of the target method does not need a visibility adjustment.
// This method is called after all other changes have been
// created. Changes induced by this method will be attached to those changes.
result.merge(adjustVisibility((IType) fIntermediaryFirstParameterType.getJavaElement(), fIntermediaryType, monitor));
if (result.hasError())
// binary
return result;
ModifierKeyword neededVisibility = getNeededVisibility(fTargetMethod, fIntermediaryType);
if (neededVisibility != null) {
result.merge(adjustVisibility(fTargetMethod, neededVisibility, monitor));
if (result.hasError())
// binary
return result;
// Need to adjust the overridden methods of the target method.
ITypeHierarchy hierarchy = fTargetMethod.getDeclaringType().newTypeHierarchy(null);
MethodOverrideTester tester = new MethodOverrideTester(fTargetMethod.getDeclaringType(), hierarchy);
IType[] subtypes = hierarchy.getAllSubtypes(fTargetMethod.getDeclaringType());
for (int i = 0; i < subtypes.length; i++) {
IMethod method = tester.findOverridingMethodInType(subtypes[i], fTargetMethod);
if (method != null && method.exists()) {
result.merge(adjustVisibility(method, neededVisibility, monitor));
if (monitor.isCanceled())
throw new OperationCanceledException();
if (result.hasError())
// binary
return result;
}
}
}
return result;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class ModifierCorrectionSubProcessor method findVisibilityModifier.
private static Modifier findVisibilityModifier(List<IExtendedModifier> modifiers) {
for (int i = 0; i < modifiers.size(); i++) {
IExtendedModifier curr = modifiers.get(i);
if (curr instanceof Modifier) {
Modifier modifier = (Modifier) curr;
ModifierKeyword keyword = modifier.getKeyword();
if (keyword == ModifierKeyword.PUBLIC_KEYWORD || keyword == ModifierKeyword.PROTECTED_KEYWORD || keyword == ModifierKeyword.PRIVATE_KEYWORD) {
return modifier;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method adjustIncomingVisibility.
/**
* Adjusts the visibility of the specified member.
*
* @param element the "source" point from which to calculate the visibility
* @param referencedMovedElement the moved element which may be adjusted in visibility
* @param monitor the progress monitor to use
* @throws JavaModelException if the visibility adjustment could not be computed
*/
private void adjustIncomingVisibility(final IJavaElement element, IMember referencedMovedElement, final IProgressMonitor monitor) throws JavaModelException {
final ModifierKeyword threshold = getVisibilityThreshold(element, referencedMovedElement, monitor);
int flags = referencedMovedElement.getFlags();
IType declaring = referencedMovedElement.getDeclaringType();
if (declaring != null && declaring.isInterface() || referencedMovedElement instanceof IField && Flags.isEnum(referencedMovedElement.getFlags()))
return;
if (hasLowerVisibility(flags, threshold == null ? Modifier.NONE : threshold.toFlagValue()) && needsVisibilityAdjustment(referencedMovedElement, threshold))
fAdjustments.put(referencedMovedElement, new IncomingMemberVisibilityAdjustment(referencedMovedElement, threshold, RefactoringStatus.createStatus(fVisibilitySeverity, Messages.format(getMessage(referencedMovedElement), new String[] { getLabel(referencedMovedElement), getLabel(threshold) }), JavaStatusContext.create(referencedMovedElement), null, RefactoringStatusEntry.NO_CODE, null)));
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method computeOutgoingVisibilityThreshold.
/**
* Computes the visibility threshold for the referenced element.
*
* @param referencing the referencing element
* @param referenced the referenced element
* @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 computeOutgoingVisibilityThreshold(final IJavaElement referencing, final IMember referenced, final IProgressMonitor monitor) throws JavaModelException {
Assert.isTrue(referencing instanceof ICompilationUnit || referencing instanceof IType || referencing instanceof IPackageFragment);
Assert.isTrue(referenced instanceof IType || referenced instanceof IField || referenced instanceof IMethod);
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
final int referencingType = referencing.getElementType();
final int referencedType = referenced.getElementType();
switch(referencedType) {
case IJavaElement.TYPE:
{
final IType typeReferenced = (IType) referenced;
switch(referencingType) {
case IJavaElement.COMPILATION_UNIT:
{
final ICompilationUnit unit = (ICompilationUnit) referencing;
final ICompilationUnit referencedUnit = typeReferenced.getCompilationUnit();
if (referencedUnit != null && referencedUnit.equals(unit))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.getParent().equals(unit.getParent()))
keyword = null;
break;
}
case IJavaElement.TYPE:
{
keyword = thresholdTypeToType((IType) referencing, typeReferenced, monitor);
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (typeReferenced.getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.FIELD:
{
final IField fieldReferenced = (IField) referenced;
final ICompilationUnit referencedUnit = fieldReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.COMPILATION_UNIT:
{
final ICompilationUnit unit = (ICompilationUnit) referencing;
if (referencedUnit != null && referencedUnit.equals(unit))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.getParent().equals(unit.getParent()))
keyword = null;
break;
}
case IJavaElement.TYPE:
{
keyword = thresholdTypeToField((IType) referencing, fieldReferenced, monitor);
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (fieldReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.METHOD:
{
final IMethod methodReferenced = (IMethod) referenced;
final ICompilationUnit referencedUnit = methodReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.COMPILATION_UNIT:
{
final ICompilationUnit unit = (ICompilationUnit) referencing;
if (referencedUnit != null && referencedUnit.equals(unit))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.getParent().equals(unit.getParent()))
keyword = null;
break;
}
case IJavaElement.TYPE:
{
keyword = thresholdTypeToMethod((IType) referencing, methodReferenced, monitor);
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (methodReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
default:
Assert.isTrue(false);
}
} finally {
monitor.done();
}
return keyword;
}
use of org.eclipse.jdt.core.dom.Modifier.ModifierKeyword in project che by eclipse.
the class MemberVisibilityAdjustor method getVisibilityThreshold.
/**
* Computes the visibility threshold for the referenced element.
*
* @param referencing the referencing element
* @param referenced the referenced element
* @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
*/
public ModifierKeyword getVisibilityThreshold(final IJavaElement referencing, final IMember referenced, final IProgressMonitor monitor) throws JavaModelException {
Assert.isTrue(!(referencing instanceof IInitializer));
Assert.isTrue(!(referenced instanceof IInitializer));
ModifierKeyword keyword = ModifierKeyword.PUBLIC_KEYWORD;
try {
//$NON-NLS-1$
monitor.beginTask("", 1);
monitor.setTaskName(RefactoringCoreMessages.MemberVisibilityAdjustor_checking);
final int referencingType = referencing.getElementType();
final int referencedType = referenced.getElementType();
switch(referencedType) {
case IJavaElement.TYPE:
{
final IType typeReferenced = (IType) referenced;
final ICompilationUnit referencedUnit = typeReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToType((IType) referencing, typeReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (typeReferenced.equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (typeReferenced.getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (typeReferenced.getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.FIELD:
{
final IField fieldReferenced = (IField) referenced;
final ICompilationUnit referencedUnit = fieldReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToField((IType) referencing, fieldReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (fieldReferenced.getDeclaringType().equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (fieldReferenced.getDeclaringType().getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (fieldReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
case IJavaElement.METHOD:
{
final IMethod methodReferenced = (IMethod) referenced;
final ICompilationUnit referencedUnit = methodReferenced.getCompilationUnit();
switch(referencingType) {
case IJavaElement.TYPE:
{
keyword = thresholdTypeToMethod((IType) referencing, methodReferenced, monitor);
break;
}
case IJavaElement.FIELD:
case IJavaElement.METHOD:
{
final IMember member = (IMember) referencing;
if (methodReferenced.getDeclaringType().equals(member.getDeclaringType()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (referencedUnit != null && referencedUnit.equals(member.getCompilationUnit()))
keyword = ModifierKeyword.PRIVATE_KEYWORD;
else if (methodReferenced.getDeclaringType().getPackageFragment().equals(member.getDeclaringType().getPackageFragment()))
keyword = null;
break;
}
case IJavaElement.PACKAGE_FRAGMENT:
{
final IPackageFragment fragment = (IPackageFragment) referencing;
if (methodReferenced.getDeclaringType().getPackageFragment().equals(fragment))
keyword = null;
break;
}
default:
Assert.isTrue(false);
}
break;
}
default:
Assert.isTrue(false);
}
} finally {
monitor.done();
}
return keyword;
}
Aggregations