@Override public IJavaElement getJavaElement() { return originalBinding.getJavaElement(); }
/** * Creates an status entry context for the given method binding * * @param method the method binding for which the context is supposed to be created * @return the status entry context or <code>Context.NULL_CONTEXT</code> if the * context cannot be created */ public static RefactoringStatusContext create(IMethodBinding method) { return create((IMethod) method.getJavaElement()); }
/** * Creates an status entry context for the given method binding * * @param method the method binding for which the context is supposed to be created * @return the status entry context or <code>Context.NULL_CONTEXT</code> if the * context cannot be created */ public static RefactoringStatusContext create(IMethodBinding method) { return create((IMethod) method.getJavaElement()); }
/** * Creates an status entry context for the given method binding * * @param method the method binding for which the context is supposed to be created * @return the status entry context or <code>Context.NULL_CONTEXT</code> if the * context cannot be created */ public static RefactoringStatusContext create(IMethodBinding method) { return create((IMethod) method.getJavaElement()); }
private boolean checkOverriddenBinaryMethods() { if (fMethodBinding != null){ Set<ITypeBinding> declaringSupertypes= getDeclaringSuperTypes(fMethodBinding); for (Iterator<ITypeBinding> iter= declaringSupertypes.iterator(); iter.hasNext();) { ITypeBinding superType= iter.next(); IMethodBinding overriddenMethod= findMethod(fMethodBinding, superType); Assert.isNotNull(overriddenMethod);//because we asked for declaring types IMethod iMethod= (IMethod) overriddenMethod.getJavaElement(); if (iMethod.isBinary()){ return true; } } } return false; }
private IMethod getIMethod(IMethodBinding method) { IJavaElement element= method.getJavaElement(); if (element == null || element.getElementType() != IJavaElement.METHOD) return null; // extra safety, not seen in tests (triggered from ctor of local class inside initializer) IMethod iMethod= (IMethod) element; if (isEnclosingElement(iMethod)) { return (IMethod) fEnclosingElement; // benefit from better details on LambdaMethod } return iMethod; }
private boolean checkOverriddenBinaryMethods() { if (fMethodBinding != null){ Set<ITypeBinding> declaringSupertypes= getDeclaringSuperTypes(fMethodBinding); for (Iterator<ITypeBinding> iter= declaringSupertypes.iterator(); iter.hasNext();) { ITypeBinding superType= iter.next(); IMethodBinding overriddenMethod= findMethod(fMethodBinding, superType); Assert.isNotNull(overriddenMethod);//because we asked for declaring types IMethod iMethod= (IMethod) overriddenMethod.getJavaElement(); if (iMethod.isBinary()){ return true; } } } return false; }
private boolean checkOverriddenBinaryMethods() throws JavaModelException { if (fMethodBinding != null){ Set declaringSupertypes= getDeclaringSuperTypes(fMethodBinding); for (Iterator iter= declaringSupertypes.iterator(); iter.hasNext();) { ITypeBinding superType= (ITypeBinding) iter.next(); IMethodBinding overriddenMethod= findMethod(fMethodBinding, superType); Assert.isNotNull(overriddenMethod);//because we asked for declaring types IMethod iMethod= (IMethod) overriddenMethod.getJavaElement(); if (iMethod.isBinary()){ return true; } } } return false; }
private IMethod getIMethod(IMethodBinding method) { IJavaElement element= method.getJavaElement(); if (element == null || element.getElementType() != IJavaElement.METHOD) return null; // extra safety, not seen in tests (triggered from ctor of local class inside initializer) IMethod iMethod= (IMethod) element; if (isEnclosingElement(iMethod)) { return (IMethod) fEnclosingElement; // benefit from better details on LambdaMethod } return iMethod; }
IMethodBinding binding = (IMethodBinding) node.getName().resolveBinding(); ICompilationUnit unit = (ICompilationUnit) binding.getJavaElement().getAncestor( IJavaElement.COMPILATION_UNIT ); if ( unit == null ) { // not available, external declaration }b ASTParser parser = ASTParser.newParser( AST.JLS8 ); parser.setKind( ASTParser.K_COMPILATION_UNIT ); parser.setSource( unit ); parser.setResolveBindings( true ); CompilationUnit cu = (CompilationUnit) parser.createAST( null ); MethodDeclaration decl = (MethodDeclaration)cu.findDeclaringNode( binding.getKey() );
/** * Returns the method to inline, or null if the method could not be found or * {@link #checkInitialConditions(IProgressMonitor)} has not been called yet. * * @return the method, or <code>null</code> */ public IMethod getMethod() { if (fSourceProvider == null) return null; IMethodBinding binding= fSourceProvider.getDeclaration().resolveBinding(); if (binding == null) return null; return (IMethod) binding.getJavaElement(); }
/** * Returns the method to inline, or null if the method could not be found or * {@link #checkInitialConditions(IProgressMonitor)} has not been called yet. * * @return the method, or <code>null</code> */ public IMethod getMethod() { if (fSourceProvider == null) return null; IMethodBinding binding= fSourceProvider.getDeclaration().resolveBinding(); if (binding == null) return null; return (IMethod) binding.getJavaElement(); }
private static boolean hasNullAnnotation(MethodDeclaration decl) { List<IExtendedModifier> modifiers= decl.modifiers(); String nonnull= NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false); String nullable= NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false); for (Object mod : modifiers) { if (mod instanceof Annotation) { Name annotationName= ((Annotation) mod).getTypeName(); String fullyQualifiedName= annotationName.getFullyQualifiedName(); if (annotationName.isSimpleName() ? nonnull.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nonnull)) return true; if (annotationName.isSimpleName() ? nullable.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nullable)) return true; } } return false; }
@Override public void open() { try { IMethod method= (IMethod) realMethod.getJavaElement(); if (method != null) { action.run(new StructuredSelection(method)); } } catch(Exception e) { Activator.log(e); } }
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) { try { IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement(); IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement(); if (firstMethod == null || secondMethod == null) { return 0; } ISourceRange firstSourceRange= firstMethod.getSourceRange(); ISourceRange secondSourceRange= secondMethod.getSourceRange(); if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) { return firstMethod.getElementName().compareTo(secondMethod.getElementName()); } else { return firstSourceRange.getOffset() - secondSourceRange.getOffset(); } } catch (JavaModelException e) { return 0; } } }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm) throws JavaModelException { pm.beginTask("", 9); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden); MethodDeclaration decl= fSourceProvider.getDeclaration(); IMethod method= (IMethod) decl.resolveBinding().getJavaElement(); if (method == null || Flags.isPrivate(method.getFlags())) { pm.worked(8); return; } IType type= method.getDeclaringType(); ITypeHierarchy hierarchy= type.newTypeHierarchy(new SubProgressMonitor(pm, 6)); checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1)); checkSuperClasses(status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1)); checkSuperInterfaces(status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1)); pm.setTaskName(""); //$NON-NLS-1$ }
public static void addOverrideAnnotation(ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) { String version= binding.getJavaElement().getJavaProject().getOption(JavaCore.COMPILER_COMPLIANCE, true); if (!binding.getDeclaringClass().isInterface() || !JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6)) { final Annotation marker= rewrite.getAST().newMarkerAnnotation(); marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$ rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null); } }