Java 类org.eclipse.jdt.core.refactoring.descriptors.InlineMethodDescriptor 实例源码

项目:che    文件:RefactoringSignatureDescriptorFactory.java   
public static InlineMethodDescriptor createInlineMethodDescriptor() {
  return new InlineMethodDescriptor();
}
项目:che    文件:RefactoringSignatureDescriptorFactory.java   
public static InlineMethodDescriptor createInlineMethodDescriptor(
    String project, String description, String comment, Map arguments, int flags) {
  return new InlineMethodDescriptor(project, description, comment, arguments, flags);
}
项目:Eclipse-Postfix-Code-Completion    文件:InlineMethodRefactoringContribution.java   
/**
 * {@inheritDoc}
 */
@Override
public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException {
    int selectionStart= -1;
    int selectionLength= -1;
    ICompilationUnit unit= null;
    CompilationUnit node= null;
    if (descriptor instanceof InlineMethodDescriptor) {
        InlineMethodDescriptor extended= (InlineMethodDescriptor) descriptor;
        Map<String, String> arguments= retrieveArgumentMap(extended);
        final String selection= arguments.get(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
        if (selection != null) {
            int offset= -1;
            int length= -1;
            final StringTokenizer tokenizer= new StringTokenizer(selection);
            if (tokenizer.hasMoreTokens())
                offset= Integer.valueOf(tokenizer.nextToken()).intValue();
            if (tokenizer.hasMoreTokens())
                length= Integer.valueOf(tokenizer.nextToken()).intValue();
            if (offset >= 0 && length >= 0) {
                selectionStart= offset;
                selectionLength= length;
            } else
                throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION}), null));
        }
        final String handle= arguments.get(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
        if (handle != null) {
            final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(descriptor.getProject(), handle, false);
            if (element == null || !element.exists())
                throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String[] { RefactoringCoreMessages.InlineMethodRefactoring_name, IJavaRefactorings.INLINE_METHOD}), null));
            else {
                if (element instanceof ICompilationUnit) {
                    unit= (ICompilationUnit) element;
                    if (selection == null)
                        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION), null));
                } else if (element instanceof IMethod) {
                    final IMethod method= (IMethod) element;
                    try {
                        final ISourceRange range= method.getNameRange();
                        if (range != null) {
                            selectionStart= range.getOffset();
                            selectionLength= range.getLength();
                        } else
                            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { handle, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT}), null));
                    } catch (JavaModelException exception) {
                        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String[] { RefactoringCoreMessages.InlineMethodRefactoring_name, IJavaRefactorings.INLINE_METHOD}), exception));
                    }
                    unit= method.getCompilationUnit();
                } else
                    throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { handle, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT}), null));
                final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
                parser.setResolveBindings(true);
                parser.setSource(unit);
                node= (CompilationUnit) parser.createAST(null);
            }
        } else
            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT), null));
    } else
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments, null));
    return InlineMethodRefactoring.create(unit, node, selectionStart, selectionLength);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InlineMethodRefactoringContribution.java   
/**
 * {@inheritDoc}
 */
@Override
public final Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException {
    int selectionStart= -1;
    int selectionLength= -1;
    ICompilationUnit unit= null;
    CompilationUnit node= null;
    if (descriptor instanceof InlineMethodDescriptor) {
        InlineMethodDescriptor extended= (InlineMethodDescriptor) descriptor;
        Map<String, String> arguments= retrieveArgumentMap(extended);
        final String selection= arguments.get(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION);
        if (selection != null) {
            int offset= -1;
            int length= -1;
            final StringTokenizer tokenizer= new StringTokenizer(selection);
            if (tokenizer.hasMoreTokens())
                offset= Integer.valueOf(tokenizer.nextToken()).intValue();
            if (tokenizer.hasMoreTokens())
                length= Integer.valueOf(tokenizer.nextToken()).intValue();
            if (offset >= 0 && length >= 0) {
                selectionStart= offset;
                selectionLength= length;
            } else
                throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { selection, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION}), null));
        }
        final String handle= arguments.get(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
        if (handle != null) {
            final IJavaElement element= JavaRefactoringDescriptorUtil.handleToElement(descriptor.getProject(), handle, false);
            if (element == null || !element.exists())
                throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String[] { RefactoringCoreMessages.InlineMethodRefactoring_name, IJavaRefactorings.INLINE_METHOD}), null));
            else {
                if (element instanceof ICompilationUnit) {
                    unit= (ICompilationUnit) element;
                    if (selection == null)
                        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION), null));
                } else if (element instanceof IMethod) {
                    final IMethod method= (IMethod) element;
                    try {
                        final ISourceRange range= method.getNameRange();
                        if (range != null) {
                            selectionStart= range.getOffset();
                            selectionLength= range.getLength();
                        } else
                            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { handle, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT}), null));
                    } catch (JavaModelException exception) {
                        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_inputs_do_not_exist, new String[] { RefactoringCoreMessages.InlineMethodRefactoring_name, IJavaRefactorings.INLINE_METHOD}), exception));
                    }
                    unit= method.getCompilationUnit();
                } else
                    throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { handle, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT}), null));
                final ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
                parser.setResolveBindings(true);
                parser.setSource(unit);
                node= (CompilationUnit) parser.createAST(null);
            }
        } else
            throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT), null));
    } else
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments, null));
    return InlineMethodRefactoring.create(unit, node, selectionStart, selectionLength);
}