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) {
private void appendResolved(String typeName) { String resolvedType; try { resolvedType= resolveType(typeName, result, fMethod.getDeclaringType(), null); } catch (CoreException e) { throw new NestedException(e); } this.fBuffer.append(resolvedType); } };
private void createTypeToMethod() { fTypeToMethod= new HashMap<>(); for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { IMethod declaration= iter.next(); fTypeToMethod.put(declaration.getDeclaringType(), declaration); } }
private void createTypeToMethod() { fTypeToMethod= new HashMap<>(); for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { IMethod declaration= iter.next(); fTypeToMethod.put(declaration.getDeclaringType(), declaration); } }
private Set<IType> getRelatedTypes() { Set<IMethod> methods= getMethodsToRename(); Set<IType> result= new HashSet<>(methods.size()); for (Iterator<IMethod> iter= methods.iterator(); iter.hasNext(); ){ result.add(iter.next().getDeclaringType()); } return result; }
public static String getMethodSignature(IMethod method) { StringBuffer buffer= new StringBuffer(); buffer.append(JavaElementLabels.getElementLabel( method.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED)); boolean isConstructor= method.getElementName().equals(method.getDeclaringType().getElementName()); if (!isConstructor) { buffer.append('.'); } buffer.append(getUnqualifiedMethodSignature(method, !isConstructor)); return buffer.toString(); }
private static String createMethodInTypeLinks(IMethod overridden) { CharSequence methodLink= createSimpleMemberLink(overridden); CharSequence typeLink= createSimpleMemberLink(overridden.getDeclaringType()); String methodInType= MessageFormat.format(JavaDocMessages.JavaDoc2HTMLTextReader_method_in_type, new Object[] { methodLink, typeLink }); return methodInType; }
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException { IRegion region= JavaCore.newRegion(); for (Iterator<IMethod> iter= fDeclarations.iterator(); iter.hasNext();) { IType declaringType= iter.next().getDeclaringType(); region.add(declaringType); } fHierarchy= JavaCore.newTypeHierarchy(region, owner, pm); }
@Override public String getSimpleName() { IType declaringType = this.method.getDeclaringType(); return declaringType.getElementName() + "#" + this.method.getElementName(); }
/** * Returns the method inherited from, <code>null</code> if method is newly defined. * @param method the method being written * @return the ancestor method, or <code>null</code> if none * @throws JavaModelException if accessing the Java model fails */ private static IMethod getInheritedMethod(IMethod method) throws JavaModelException { IType declaringType= method.getDeclaringType(); MethodOverrideTester tester= SuperTypeHierarchyCache.getMethodOverrideTester(declaringType); return tester.findOverriddenMethod(method, true); }
private ITypeHierarchy getCachedTypeHierarchy(IProgressMonitor monitor) throws JavaModelException { if (fCachedTypeHierarchy == null) fCachedTypeHierarchy= fMethod.getDeclaringType().newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedTypeHierarchy; }
/** * Finds the super implementation of the method. * * @param method the method * @return the super implementation of the method if any or <code>null</code> * @throws JavaModelException if an exception occurs while creating the type hierarchy to find * the super implementation */ static IMethod findSuperImplementation(IMethod method) throws JavaModelException { MethodOverrideTester tester= SuperTypeHierarchyCache.getMethodOverrideTester(method.getDeclaringType()); return tester.findOverriddenMethod(method, false); }
private ITypeHierarchy getCachedTypeHierarchy(IProgressMonitor monitor) throws JavaModelException { if (fCachedTypeHierarchy == null) fCachedTypeHierarchy= fMethod.getDeclaringType().newTypeHierarchy(new SubProgressMonitor(monitor, 1)); return fCachedTypeHierarchy; }
@Override public Color getForeground(Object element) { if (fMethodsViewer.isShowInheritedMethods() && element instanceof IMethod) { IMethod curr= (IMethod) element; IMember declaringType= curr.getDeclaringType(); if (!declaringType.equals(fMethodsViewer.getInput())) { return JFaceResources.getColorRegistry().get(ColoredViewersManager.INHERITED_COLOR_NAME); } } return null; }
public static BodyDeclaration getMethodOrAnnotationTypeMemberDeclarationNode(IMethod iMethod, CompilationUnit cuNode) throws JavaModelException { if (JdtFlags.isAnnotation(iMethod.getDeclaringType())) return getAnnotationTypeMemberDeclarationNode(iMethod, cuNode); else return getMethodDeclarationNode(iMethod, cuNode); }
@Override public Color getForeground(Object element) { if (fMethodsViewer.isShowInheritedMethods() && element instanceof IMethod) { IMethod curr= (IMethod) element; IMember declaringType= curr.getDeclaringType(); if (!declaringType.equals(fMethodsViewer.getInput())) { return JFaceResources.getColorRegistry().get(ColoredViewersManager.INHERITED_COLOR_NAME); } } return null; }
public Color getForeground(Object element) { if (fMethodsViewer.isShowInheritedMethods() && element instanceof IMethod) { IMethod curr= (IMethod) element; IMember declaringType= curr.getDeclaringType(); if (!declaringType.equals(fMethodsViewer.getInput())) { return JFaceResources.getColorRegistry().get(ColoredViewersManager.INHERITED_COLOR_NAME); } } return null; }
private String createMethodComment(IMethod meth, String lineDelimiter) throws CoreException { IType declaringType= meth.getDeclaringType(); IMethod overridden= null; if (!meth.isConstructor()) { ITypeHierarchy hierarchy= SuperTypeHierarchyCache.getTypeHierarchy(declaringType); MethodOverrideTester tester= new MethodOverrideTester(declaringType, hierarchy); overridden= tester.findOverriddenMethod(meth, true); } return CodeGeneration.getMethodComment(meth, overridden, lineDelimiter); }
private boolean mustAnalyzeAstOfDeclaringCu() throws JavaModelException{ if (JdtFlags.isAbstract(getMethod())) return false; else if (JdtFlags.isNative(getMethod())) return false; else if (getMethod().getDeclaringType().isInterface()) return false; else return true; }
public static RefactoringStatus checkIfOverridesAnother(IMethod method, ITypeHierarchy hierarchy) throws JavaModelException { IMethod overrides= MethodChecks.overridesAnotherMethod(method, hierarchy); if (overrides == null) return null; RefactoringStatusContext context= JavaStatusContext.create(overrides); String message= Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[]{JavaElementUtil.createMethodSignature(overrides), JavaElementLabels.getElementLabel(overrides.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED)}); return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, overrides); }