private IJavaElement declarationMatched(IJavaElement javaElement, IBindingProvider mirror) {
   if (mirror != null) {
     parser.setProject(typeRoot.getJavaProject());
     IBinding[] bindings = parser.createBindings(new IJavaElement[] {javaElement}, null);
     if (bindings.length > 0 && bindings[0] != null) {
       if (mirror instanceof JDTMethod && bindings[0] instanceof ITypeBinding) {
         // Case of a constructor : let's go to the constructor and not to the type.
         ITypeBinding typeBinding = (ITypeBinding) bindings[0];
         for (IMethodBinding methodBinding : typeBinding.getDeclaredMethods()) {
           //                        if (methodBinding.isConstructor()) {
           if (CharOperation.equals(
               methodBinding.getKey().toCharArray(), mirror.getBindingKey())) {
             return methodBinding.getJavaElement();
           }
           //                        }
         }
       }
       if (CharOperation.equals(bindings[0].getKey().toCharArray(), mirror.getBindingKey())) {
         return javaElement;
       }
     }
   }
   return null;
 }
  private ClipboardData getClipboardData(ITypeRoot inputElement, int offset, int length) {
    CompilationUnit astRoot =
        SharedASTProvider.getAST(inputElement, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
    if (astRoot == null) {
      return null;
    }

    // do process import if selection spans over import declaration or package
    List<ImportDeclaration> list = astRoot.imports();
    if (!list.isEmpty()) {
      if (offset < ((ASTNode) list.get(list.size() - 1)).getStartPosition()) {
        return null;
      }
    } else if (astRoot.getPackage() != null) {
      if (offset < ((ASTNode) astRoot.getPackage()).getStartPosition()) {
        return null;
      }
    }

    ArrayList<SimpleName> typeImportsRefs = new ArrayList<SimpleName>();
    ArrayList<SimpleName> staticImportsRefs = new ArrayList<SimpleName>();

    ImportReferencesCollector.collect(
        astRoot,
        inputElement.getJavaProject(),
        new Region(offset, length),
        typeImportsRefs,
        staticImportsRefs);

    if (typeImportsRefs.isEmpty() && staticImportsRefs.isEmpty()) {
      return null;
    }

    HashSet<String> namesToImport = new HashSet<String>(typeImportsRefs.size());
    for (int i = 0; i < typeImportsRefs.size(); i++) {
      Name curr = typeImportsRefs.get(i);
      IBinding binding = curr.resolveBinding();
      if (binding != null && binding.getKind() == IBinding.TYPE) {
        ITypeBinding typeBinding = (ITypeBinding) binding;
        if (typeBinding.isArray()) {
          typeBinding = typeBinding.getElementType();
        }
        if (typeBinding.isTypeVariable()
            || typeBinding.isCapture()
            || typeBinding.isWildcardType()) { // can be removed when bug 98473 is fixed
          continue;
        }

        if (typeBinding.isMember() || typeBinding.isTopLevel()) {
          String name = Bindings.getRawQualifiedName(typeBinding);
          if (name.length() > 0) {
            namesToImport.add(name);
          }
        }
      }
    }

    HashSet<String> staticsToImport = new HashSet<String>(staticImportsRefs.size());
    for (int i = 0; i < staticImportsRefs.size(); i++) {
      Name curr = staticImportsRefs.get(i);
      IBinding binding = curr.resolveBinding();
      if (binding != null) {
        StringBuffer buf = new StringBuffer(Bindings.getImportName(binding));
        if (binding.getKind() == IBinding.METHOD) {
          buf.append("()"); // $NON-NLS-1$
        }
        staticsToImport.add(buf.toString());
      }
    }

    if (namesToImport.isEmpty() && staticsToImport.isEmpty()) {
      return null;
    }

    String[] typeImports = namesToImport.toArray(new String[namesToImport.size()]);
    String[] staticImports = staticsToImport.toArray(new String[staticsToImport.size()]);
    return new ClipboardData(inputElement, typeImports, staticImports);
  }
    private void insertAllMissingMethodTags(ASTRewrite rewriter, MethodDeclaration methodDecl) {
      AST ast = methodDecl.getAST();
      Javadoc javadoc = methodDecl.getJavadoc();
      ListRewrite tagsRewriter = rewriter.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY);

      List<TypeParameter> typeParams = methodDecl.typeParameters();
      ASTNode root = methodDecl.getRoot();
      if (root instanceof CompilationUnit) {
        ITypeRoot typeRoot = ((CompilationUnit) root).getTypeRoot();
        if (typeRoot != null
            && !StubUtility.shouldGenerateMethodTypeParameterTags(typeRoot.getJavaProject()))
          typeParams = Collections.emptyList();
      }
      List<String> typeParamNames = new ArrayList<>();
      for (int i = typeParams.size() - 1; i >= 0; i--) {
        TypeParameter decl = typeParams.get(i);
        String name = '<' + decl.getName().getIdentifier() + '>';
        if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
          TagElement newTag = ast.newTagElement();
          newTag.setTagName(TagElement.TAG_PARAM);
          TextElement text = ast.newTextElement();
          text.setText(name);
          newTag.fragments().add(text);
          insertTabStop(rewriter, newTag.fragments(), "typeParam" + i); // $NON-NLS-1$
          insertTag(tagsRewriter, newTag, getPreviousTypeParamNames(typeParams, decl));
        }
        typeParamNames.add(name);
      }
      List<SingleVariableDeclaration> params = methodDecl.parameters();
      for (int i = params.size() - 1; i >= 0; i--) {
        SingleVariableDeclaration decl = params.get(i);
        String name = decl.getName().getIdentifier();
        if (findTag(javadoc, TagElement.TAG_PARAM, name) == null) {
          TagElement newTag = ast.newTagElement();
          newTag.setTagName(TagElement.TAG_PARAM);
          newTag.fragments().add(ast.newSimpleName(name));
          insertTabStop(rewriter, newTag.fragments(), "methParam" + i); // $NON-NLS-1$
          Set<String> sameKindLeadingNames = getPreviousParamNames(params, decl);
          sameKindLeadingNames.addAll(typeParamNames);
          insertTag(tagsRewriter, newTag, sameKindLeadingNames);
        }
      }
      if (!methodDecl.isConstructor()) {
        Type type = methodDecl.getReturnType2();
        if (!type.isPrimitiveType()
            || (((PrimitiveType) type).getPrimitiveTypeCode() != PrimitiveType.VOID)) {
          if (findTag(javadoc, TagElement.TAG_RETURN, null) == null) {
            TagElement newTag = ast.newTagElement();
            newTag.setTagName(TagElement.TAG_RETURN);
            insertTabStop(rewriter, newTag.fragments(), "return"); // $NON-NLS-1$
            insertTag(tagsRewriter, newTag, null);
          }
        }
      }
      List<Type> thrownExceptions = methodDecl.thrownExceptionTypes();
      for (int i = thrownExceptions.size() - 1; i >= 0; i--) {
        Type exception = thrownExceptions.get(i);
        ITypeBinding binding = exception.resolveBinding();
        if (binding != null) {
          String name = binding.getName();
          if (findThrowsTag(javadoc, name) == null) {
            TagElement newTag = ast.newTagElement();
            newTag.setTagName(TagElement.TAG_THROWS);
            TextElement excNode = ast.newTextElement();
            excNode.setText(ASTNodes.getQualifiedTypeName(exception));
            newTag.fragments().add(excNode);
            insertTabStop(rewriter, newTag.fragments(), "exception" + i); // $NON-NLS-1$
            insertTag(tagsRewriter, newTag, getPreviousExceptionNames(thrownExceptions, exception));
          }
        }
      }
    }
 public Change createChange(IProgressMonitor pm) throws CoreException {
   if (fDeleteSource && fCurrentMode == Mode.INLINE_ALL) {
     TextChange change = fChangeManager.get((ICompilationUnit) fSourceProvider.getTypeRoot());
     TextEdit delete = fSourceProvider.getDeleteEdit();
     TextEditGroup description =
         new TextEditGroup(
             RefactoringCoreMessages.InlineMethodRefactoring_edit_delete, new TextEdit[] {delete});
     TextEdit root = change.getEdit();
     if (root != null) {
       // TODO instead of finding the right insert position the call inliner should
       // reuse the AST & rewriter of the source provide and we should rewrite the
       // whole AST at the end. However, since recursive calls aren't allowed there
       // shouldn't be a text edit overlap.
       // root.addChild(delete);
       TextChangeCompatibility.insert(root, delete);
     } else {
       change.setEdit(delete);
     }
     change.addTextEditGroup(description);
   }
   final Map arguments = new HashMap();
   String project = null;
   IJavaProject javaProject = fInitialTypeRoot.getJavaProject();
   if (javaProject != null) project = javaProject.getElementName();
   int flags =
       RefactoringDescriptor.STRUCTURAL_CHANGE
           | JavaRefactoringDescriptor.JAR_REFACTORING
           | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
   final IMethodBinding binding = fSourceProvider.getDeclaration().resolveBinding();
   final ITypeBinding declaring = binding.getDeclaringClass();
   if (!Modifier.isPrivate(binding.getModifiers())) flags |= RefactoringDescriptor.MULTI_CHANGE;
   final String description =
       Messages.format(
           RefactoringCoreMessages.InlineMethodRefactoring_descriptor_description_short,
           BasicElementLabels.getJavaElementName(binding.getName()));
   final String header =
       Messages.format(
           RefactoringCoreMessages.InlineMethodRefactoring_descriptor_description,
           new String[] {
             BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED),
             BindingLabelProvider.getBindingLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED)
           });
   final JDTRefactoringDescriptorComment comment =
       new JDTRefactoringDescriptorComment(project, this, header);
   comment.addSetting(
       Messages.format(
           RefactoringCoreMessages.InlineMethodRefactoring_original_pattern,
           BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
   if (fDeleteSource)
     comment.addSetting(RefactoringCoreMessages.InlineMethodRefactoring_remove_method);
   if (fCurrentMode == Mode.INLINE_ALL)
     comment.addSetting(RefactoringCoreMessages.InlineMethodRefactoring_replace_references);
   final InlineMethodDescriptor descriptor =
       RefactoringSignatureDescriptorFactory.createInlineMethodDescriptor(
           project, description, comment.asString(), arguments, flags);
   arguments.put(
       JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT,
       JavaRefactoringDescriptorUtil.elementToHandle(project, fInitialTypeRoot));
   arguments.put(
       JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION,
       new Integer(fSelectionStart).toString()
           + " "
           + new Integer(fSelectionLength).toString()); // $NON-NLS-1$
   arguments.put(ATTRIBUTE_DELETE, Boolean.valueOf(fDeleteSource).toString());
   arguments.put(ATTRIBUTE_MODE, new Integer(fCurrentMode == Mode.INLINE_ALL ? 1 : 0).toString());
   return new DynamicValidationRefactoringChange(
       descriptor,
       RefactoringCoreMessages.InlineMethodRefactoring_edit_inlineCall,
       fChangeManager.getAllChanges());
 }