public static RefactoringStatus checkMembersInDestinationType(IMember[] members, IType destinationType) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < members.length; i++) { if (members[i].getElementType() == IJavaElement.METHOD) checkMethodInType(destinationType, result, (IMethod)members[i]); else if (members[i].getElementType() == IJavaElement.FIELD) checkFieldInType(destinationType, result, (IField)members[i]); else if (members[i].getElementType() == IJavaElement.TYPE) checkTypeInType(destinationType, result, (IType)members[i]); } return result; }
private void checkMembersInDestinationType(final RefactoringStatus status, final Set<IMember> set) throws JavaModelException { final IMember[] destinationMembers= getCreatedDestinationMembers(); final List<IMember> list= new ArrayList<>(destinationMembers.length); list.addAll(Arrays.asList(destinationMembers)); list.addAll(set); list.removeAll(Arrays.asList(fDeletedMethods)); final IMember[] members= list.toArray(new IMember[list.size()]); status.merge(MemberCheckUtil.checkMembersInDestinationType(members, getDestinationType())); }
private static void checkHierarchyOfEnclosedTypes(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { IType[] enclosedTypes= getAllEnclosedTypes(type); for (int i= 0; i < enclosedTypes.length; i++) { IType enclosedType= enclosedTypes[i]; if (destinationType.getElementName().equals(enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict3, new String[] { getQualifiedLabel(enclosedType), getQualifiedLabel(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict4, new String[] { getQualifiedLabel(enclosedType), getQualifiedLabel(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } } }
private static void checkTypeInType(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { String typeName= type.getElementName(); IType destinationTypeType= destinationType.getType(typeName); if (destinationTypeType.exists()){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict0, new String[]{ BasicElementLabels.getJavaElementName(typeName), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeType.getNameRange()); result.addError(message, context); } else { //need to check the hierarchy of enclosing and enclosed types if (destinationType.getElementName().equals(typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict1, getQualifiedLabel(type)); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict2, getQualifiedLabel(type)); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } checkHierarchyOfEnclosedTypes(destinationType, result, type); } }
private static void checkHierarchyOfEnclosedTypes(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { IType[] enclosedTypes= getAllEnclosedTypes(type); for (int i= 0; i < enclosedTypes.length; i++) { IType enclosedType= enclosedTypes[i]; if (destinationType.getElementName().equals(enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict3, new String[]{JavaModelUtil.getFullyQualifiedName(enclosedType), JavaModelUtil.getFullyQualifiedName(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict4, new String[]{JavaModelUtil.getFullyQualifiedName(enclosedType), JavaModelUtil.getFullyQualifiedName(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } } }
private static void checkTypeInType(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { String typeName= type.getElementName(); IType destinationTypeType= destinationType.getType(typeName); if (destinationTypeType.exists()){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict0, new String[]{typeName, JavaModelUtil.getFullyQualifiedName(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeType.getNameRange()); result.addError(message, context); } else { //need to check the hierarchy of enclosing and enclosed types if (destinationType.getElementName().equals(typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict1, new String[]{JavaModelUtil.getFullyQualifiedName(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict2, new String[]{JavaModelUtil.getFullyQualifiedName(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } checkHierarchyOfEnclosedTypes(destinationType, result, type); } }
private static void checkMethodInType(IType destinationType, RefactoringStatus result, IMethod method) throws JavaModelException { IMethod[] destinationTypeMethods= destinationType.getMethods(); IMethod found= findMethod(method, destinationTypeMethods); if (found != null){ RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), found.getSourceRange()); String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_signature_exists, new String[]{ BasicElementLabels.getJavaElementName(method.getElementName()), getQualifiedLabel(destinationType)}); result.addError(message, context); } else { IMethod similar= Checks.findMethod(method, destinationType); if (similar != null){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_same_param_count, new String[]{ BasicElementLabels.getJavaElementName(method.getElementName()), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), similar.getSourceRange()); result.addWarning(message, context); } } }
private Map getMatchingMembersMapping(final IType initial) throws JavaModelException { final Map result= new HashMap(); final IMember[] members= getCreatedDestinationMembers(); for (int i= 0; i < members.length; i++) { final IMember member= members[i]; if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod found= MemberCheckUtil.findMethod(method, initial.getMethods()); if (found != null) addMatchingMember(result, method, found); } else if (member instanceof IField) { final IField field= (IField) member; final IField found= initial.getField(field.getElementName()); if (found.exists()) addMatchingMember(result, field, found); } else if (member instanceof IType) { final IType type= (IType) member; final IType found= initial.getType(type.getElementName()); if (found.exists()) addMatchingMember(result, type, found); } else Assert.isTrue(false); } return result; }
private static IType[] getAllEnclosedTypes(IType type) throws JavaModelException { List<IType> result= new ArrayList<>(2); IType[] directlyEnclosed= type.getTypes(); result.addAll(Arrays.asList(directlyEnclosed)); for (int i= 0; i < directlyEnclosed.length; i++) { IType enclosedType= directlyEnclosed[i]; result.addAll(Arrays.asList(getAllEnclosedTypes(enclosedType))); } return result.toArray(new IType[result.size()]); }
private static void checkFieldInType(IType destinationType, RefactoringStatus result, IField field) throws JavaModelException { IField destinationTypeField= destinationType.getField(field.getElementName()); if (! destinationTypeField.exists()) return; String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_field_exists, new String[]{ BasicElementLabels.getJavaElementName(field.getElementName()), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeField.getSourceRange()); result.addError(message, context); }
private static void checkTypeInType(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { String typeName= type.getElementName(); IType destinationTypeType= destinationType.getType(typeName); if (destinationTypeType.exists()){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict0, new String[]{ BasicElementLabels.getJavaElementName(typeName), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeType.getNameRange()); result.addError(message, context); } else { //need to check the hierarchy of enclosing and enclosed types if (destinationType.getElementName().equals(typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict1, getQualifiedLabel(type)); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, typeName)){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict2, getQualifiedLabel(type)); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } checkHierarchyOfEnclosedTypes(destinationType, result, type); } }
private static void checkMethodInType(IType destinationType, RefactoringStatus result, IMethod method) throws JavaModelException { IMethod[] destinationTypeMethods= destinationType.getMethods(); IMethod found= findMethod(method, destinationTypeMethods); if (found != null){ RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), found.getSourceRange()); String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_signature_exists, new String[]{ BasicElementLabels.getJavaElementName(method.getElementName()), getQualifiedLabel(destinationType)}); result.addError(message, context); } else { IMethod similar= Checks.findMethod(method, destinationType); if (similar != null){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_same_param_count, new String[]{ BasicElementLabels.getJavaElementName(method.getElementName()), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), similar.getSourceRange()); result.addWarning(message, context); } } }
private Map<IMember, Set<IMember>> getMatchingMembersMapping(final IType initial) throws JavaModelException { final Map<IMember, Set<IMember>> result= new HashMap<>(); final IMember[] members= getCreatedDestinationMembers(); for (int i= 0; i < members.length; i++) { final IMember member= members[i]; if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod found= MemberCheckUtil.findMethod(method, initial.getMethods()); if (found != null) addMatchingMember(result, method, found); } else if (member instanceof IField) { final IField field= (IField) member; final IField found= initial.getField(field.getElementName()); if (found.exists()) addMatchingMember(result, field, found); } else if (member instanceof IType) { final IType type= (IType) member; final IType found= initial.getType(type.getElementName()); if (found.exists()) addMatchingMember(result, type, found); } else Assert.isTrue(false); } return result; }
private static IType[] getAllEnclosedTypes(IType type) throws JavaModelException { List<IType> result= new ArrayList<>(2); IType[] directlyEnclosed= type.getTypes(); result.addAll(Arrays.asList(directlyEnclosed)); for (int i= 0; i < directlyEnclosed.length; i++) { IType enclosedType= directlyEnclosed[i]; result.addAll(Arrays.asList(getAllEnclosedTypes(enclosedType))); } return result.toArray(new IType[result.size()]); }
private static void checkFieldInType(IType destinationType, RefactoringStatus result, IField field) throws JavaModelException { IField destinationTypeField= destinationType.getField(field.getElementName()); if (! destinationTypeField.exists()) return; String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_field_exists, new String[]{ BasicElementLabels.getJavaElementName(field.getElementName()), getQualifiedLabel(destinationType)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationTypeField.getSourceRange()); result.addError(message, context); }
public static RefactoringStatus checkMembersInDestinationType(IMember[] members, IType destinationType) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < members.length; i++) { if (members[i].getElementType() == IJavaElement.METHOD) checkMethodInType(destinationType, result, (IMethod)members[i]); else if (members[i].getElementType() == IJavaElement.FIELD) checkFieldInType(destinationType, result, (IField)members[i]); else if (members[i].getElementType() == IJavaElement.TYPE) checkTypeInType(destinationType, result, (IType)members[i]); } return result; }
private static void checkHierarchyOfEnclosedTypes(IType destinationType, RefactoringStatus result, IType type) throws JavaModelException { IType[] enclosedTypes= getAllEnclosedTypes(type); for (int i= 0; i < enclosedTypes.length; i++) { IType enclosedType= enclosedTypes[i]; if (destinationType.getElementName().equals(enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict3, new String[] { getQualifiedLabel(enclosedType), getQualifiedLabel(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } if (typeNameExistsInEnclosingTypeChain(destinationType, enclosedType.getElementName())){ String message= Messages.format(RefactoringCoreMessages.MemberCheckUtil_type_name_conflict4, new String[] { getQualifiedLabel(enclosedType), getQualifiedLabel(type)}); RefactoringStatusContext context= JavaStatusContext.create(destinationType.getCompilationUnit(), destinationType.getNameRange()); result.addError(message, context); } } }
private void checkMembersInDestinationType(final RefactoringStatus status, final Set<IMember> set) throws JavaModelException { final IMember[] destinationMembers= getCreatedDestinationMembers(); final List<IMember> list= new ArrayList<>(destinationMembers.length); list.addAll(Arrays.asList(destinationMembers)); list.addAll(set); list.removeAll(Arrays.asList(fDeletedMethods)); final IMember[] members= list.toArray(new IMember[list.size()]); status.merge(MemberCheckUtil.checkMembersInDestinationType(members, getDestinationType())); }
private Map<IMember, Set<IMember>> getMatchingMembersMapping(final IType initial) throws JavaModelException { final Map<IMember, Set<IMember>> result= new HashMap<>(); final IMember[] members= getCreatedDestinationMembers(); for (int i= 0; i < members.length; i++) { final IMember member= members[i]; if (member instanceof IMethod) { final IMethod method= (IMethod) member; final IMethod found= MemberCheckUtil.findMethod(method, initial.getMethods()); if (found != null) addMatchingMember(result, method, found); } else if (member instanceof IField) { final IField field= (IField) member; final IField found= initial.getField(field.getElementName()); if (found.exists()) addMatchingMember(result, field, found); } else if (member instanceof IType) { final IType type= (IType) member; final IType found= initial.getType(type.getElementName()); if (found.exists()) addMatchingMember(result, type, found); } else Assert.isTrue(false); } return result; }
private static IType[] getAllEnclosedTypes(IType type) throws JavaModelException { List result= new ArrayList(2); IType[] directlyEnclosed= type.getTypes(); result.addAll(Arrays.asList(directlyEnclosed)); for (int i= 0; i < directlyEnclosed.length; i++) { IType enclosedType= directlyEnclosed[i]; result.addAll(Arrays.asList(getAllEnclosedTypes(enclosedType))); } return (IType[]) result.toArray(new IType[result.size()]); }