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); } } }
public ImplementInterfaceProposal( ICompilationUnit targetCU, ITypeBinding binding, CompilationUnit astRoot, ITypeBinding newInterface, int relevance) { super( "", targetCU, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)); // $NON-NLS-1$ Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding)); fBinding = binding; fAstRoot = astRoot; fNewInterface = newInterface; String[] args = { BasicElementLabels.getJavaElementName(binding.getName()), BasicElementLabels.getJavaElementName(Bindings.getRawName(newInterface)) }; setDisplayName(Messages.format(CorrectionMessages.ImplementInterfaceProposal_name, args)); }
private void runOnMultiple(final ICompilationUnit[] cus) { ICleanUp[] cleanUps = getCleanUps(cus); if (cleanUps == null) return; MultiStatus status = new MultiStatus( JavaUI.ID_PLUGIN, IStatus.OK, ActionMessages.CleanUpAction_MultiStateErrorTitle, null); for (int i = 0; i < cus.length; i++) { ICompilationUnit cu = cus[i]; if (!ActionUtil.isOnBuildPath(cu)) { String cuLocation = BasicElementLabels.getPathLabel(cu.getPath(), false); String message = Messages.format(ActionMessages.CleanUpAction_CUNotOnBuildpathMessage, cuLocation); status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null)); } } if (!status.isOK()) { ErrorDialog.openError(getShell(), getActionName(), null, status); return; } try { performRefactoring(cus, cleanUps); } catch (InvocationTargetException e) { JavaPlugin.log(e); if (e.getCause() instanceof CoreException) showUnexpectedError((CoreException) e.getCause()); } }
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 String getQualifiedLabel(IType enclosedType) { return BasicElementLabels.getJavaElementName(enclosedType.getFullyQualifiedName('.')); }