Refine search
public static org.eclipse.jdt.core.dom.MethodDeclaration getRealMethodDeclarationNode(org.eclipse.jdt.core.IMethod sourceMethod, org.eclipse.jdt.core.dom.CompilationUnit cuUnit) throws JavaModelException { MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, cuUnit); if (isGenerated(methodDeclarationNode)) { IType declaringType = sourceMethod.getDeclaringType(); Stack<IType> typeStack = new Stack<IType>(); while (declaringType != null) { typeStack.push(declaringType); declaringType = declaringType.getDeclaringType(); String methodName = sourceMethod.getElementName(); for (Object declaration : typeDeclaration.bodyDeclarations()) { if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) {
public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception { List<IMethod> result = new ArrayList<IMethod>(); for (IMethod m : methods) { if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m); } return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); }
/** * Finds a method in a type. * Searches for a method with the same name and the same parameter count. * Parameter types are <b>not</b> compared. * @param method * @param type * @return The first found method or null, if nothing found * @throws JavaModelException */ public static IMethod findMethod(IMethod method, IType type) throws JavaModelException { return findMethod(method.getElementName(), method.getParameterTypes().length, method.isConstructor(), type.getMethods()); }
public static boolean isRenameProhibited(final IMethod method) throws CoreException { if (method.getElementName().equals("toString") //$NON-NLS-1$ && (method.getNumberOfParameters() == 0) && (method.getReturnType().equals("Ljava.lang.String;") //$NON-NLS-1$ || method.getReturnType().equals("QString;") //$NON-NLS-1$ || method.getReturnType().equals("Qjava.lang.String;"))) { return true; } else { return false; } }
private RefactoringStatus checkIfMethodDeclaredIn(final IMethod iMethod, final IType type) throws JavaModelException { final IMethod methodInType= JavaModelUtil.findMethod(iMethod.getElementName(), iMethod.getParameterTypes(), iMethod.isConstructor(), type); if (methodInType == null || !methodInType.exists()) return null; final String[] keys= { JavaElementLabels.getTextLabel(methodInType, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getTextLabel(type, JavaElementLabels.ALL_FULLY_QUALIFIED)}; final String msg= Messages.format(RefactoringCoreMessages.PullUpRefactoring_Method_declared_in_class, keys); final RefactoringStatusContext context= JavaStatusContext.create(methodInType); return RefactoringStatus.createWarningStatus(msg, context); }
public static String createMethodSignature(IMethod method){ try { return Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, ! method.isConstructor()); } catch(JavaModelException e) { return method.getElementName(); //fallback } }
@Override public String getQualifiedName() { IType declaringType = this.method.getDeclaringType(); return declaringType.getFullyQualifiedName() + "#" + this.method.getElementName(); }
private IMethod findSimilarMethod(IMethod meth, Object[] elements) throws JavaModelException { String name= meth.getElementName(); String[] paramTypes= meth.getParameterTypes(); boolean isConstructor= meth.isConstructor(); for (int i= 0; i < elements.length; i++) { Object curr= elements[i]; if (curr instanceof IMethod && JavaModelUtil.isSameMethodSignature(name, paramTypes, isConstructor, (IMethod) curr)) { return (IMethod) curr; } } return null; }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
@Override public String getSimpleName() { IType declaringType = this.method.getDeclaringType(); return declaringType.getElementName() + "#" + this.method.getElementName(); }
private RefactoringStatus checkNewAccessor(IMethod existingAccessor, String newAccessorName) throws CoreException{ RefactoringStatus result= new RefactoringStatus(); IMethod accessor= JavaModelUtil.findMethod(newAccessorName, existingAccessor.getParameterTypes(), false, fField.getDeclaringType()); if (accessor == null || !accessor.exists()) { return null; } String message= Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_already_exists, new String[]{JavaElementUtil.createMethodSignature(accessor), BasicElementLabels.getJavaElementName(fField.getDeclaringType().getFullyQualifiedName('.'))}); result.addError(message, JavaStatusContext.create(accessor)); return result; }
public static boolean hasSuiteMethod(IType type) throws JavaModelException { IMethod method= type.getMethod("suite", new String[0]); //$NON-NLS-1$ if (!method.exists()) return false; if (!Flags.isStatic(method.getFlags()) || !Flags.isPublic(method.getFlags())) { return false; } if (!Signature.getSimpleName(Signature.toString(method.getReturnType())).equals(JUnitCorePlugin.SIMPLE_TEST_INTERFACE_NAME)) { return false; } return true; }
protected int getDescriptorFlags() { int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE; try { if (!Flags.isPrivate(fMethod.getFlags())) flags|= RefactoringDescriptor.MULTI_CHANGE; final IType declaring= fMethod.getDeclaringType(); if (declaring.isAnonymous() || declaring.isLocal()) flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; } catch (JavaModelException exception) { JavaPlugin.log(exception); } return flags; }
public static boolean isMoveMethodAvailable(final IMethod method) throws JavaModelException { return method.exists() && !method.isConstructor() && !method.isBinary() && !method.isReadOnly() && !JdtFlags.isStatic(method) && (JdtFlags.isDefaultMethod(method) || !method.getDeclaringType().isInterface()); }
private void initializeFields(IMethod method) throws JavaModelException { fCompilationUnit= method.getCompilationUnit(); Assert.isNotNull(fCompilationUnit); fOffset= method.getNameRange().getOffset(); fLength= method.getNameRange().getLength(); fParameterObjectFactory= new ParameterObjectFactory(fCompilationUnit); String methodName= method.getElementName(); String className= String.valueOf(Character.toUpperCase(methodName.charAt(0))); if (methodName.length() > 1) className+= methodName.substring(1); className+= PARAMETER_CLASS_APPENDIX; fParameterObjectReference= ParameterInfo.createInfoForAddedParameter(className, DEFAULT_PARAMETER_OBJECT_NAME); fParameterObjectFactory.setClassName(className); fParameterObjectFactory.setPackage(method.getDeclaringType().getPackageFragment().getElementName()); updateReferenceType(); }
private static boolean isValueAccessor(IMethod method) throws JavaModelException { if (!"getString".equals(method.getElementName())) //$NON-NLS-1$ return false; int flags= method.getFlags(); if (!Modifier.isStatic(flags) || !Modifier.isPublic(flags)) return false; String returnType= method.getReturnType(); if (!JAVA_LANG_STRING.equals(returnType)) return false; String[] parameters= method.getParameterTypes(); if (parameters.length != 1 || !JAVA_LANG_STRING.equals(parameters[0])) return false; return true; }
@Override public boolean isMethodOK(IMethod method) throws JavaModelException { return Flags.isPublic(method.getFlags()) && method.getParameterTypes().length == 0 && "java.lang.String".equals(JavaModelUtil.getResolvedTypeName(method.getReturnType(), type)); //$NON-NLS-1$ } });
private static boolean hasMethod(IMethod[] methods, String name) { for (int i = 0; i < methods.length; i++) { IMethod curr = methods[i]; if (curr.getElementName().equals(name) && curr.getParameterTypes().length == 0) { return true; } } return false; }
private RefactoringStatus checkForMethodsWithConstructorNames() throws CoreException { IMethod[] methods = fType.getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].isConstructor()) { continue; } RefactoringStatus check = Checks.checkIfConstructorName(methods[i], methods[i].getElementName(), getNewElementName()); if (check != null) { return check; } } return null; }
private ITypeHierarchy getCachedTypeHierarchy(IProgressMonitor monitor) throws JavaModelException { if (fCachedTypeHierarchy == null) fCachedTypeHierarchy= fMethod.getDeclaringType().newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedTypeHierarchy; }