Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 242929 Details for
Bug 432147
[refactoring] Extract Constant displays error message on name of local variable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch to implement the functionality
clipboard.txt (text/plain), 5.78 KB, created by
Timo Kinnunen
on 2014-05-10 12:58:53 EDT
(
hide
)
Description:
Patch to implement the functionality
Filename:
MIME Type:
Creator:
Timo Kinnunen
Created:
2014-05-10 12:58:53 EDT
Size:
5.78 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java >index 774f96e..932808d 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Timo Kinnunen - Contribution for bug 432147 - [refactoring] Extract Constant displays error message on name of local variable > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > >@@ -983,4 +984,8 @@ > public void setLinkedProposalModel(LinkedProposalModel model) { > fLinkedProposalModel= model; > } >+ >+ public void setSelfInitializing(boolean value) { >+ fSelfInitializing = value; >+ } > } >diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractConstantAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractConstantAction.java >index ff6a4c8..88bb254 100644 >--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractConstantAction.java >+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ExtractConstantAction.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2014 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Timo Kinnunen - Contribution for bug 432147 - [refactoring] Extract Constant displays error message on name of local variable > *******************************************************************************/ > package org.eclipse.jdt.ui.actions; > >@@ -14,17 +15,32 @@ > > import org.eclipse.ui.PlatformUI; > >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.SourceRange; >+import org.eclipse.jdt.core.dom.ASTNode; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.SimpleName; >+import org.eclipse.jdt.core.dom.VariableDeclaration; >+ >+import org.eclipse.jdt.internal.corext.dom.fragments.ASTFragmentFactory; >+import org.eclipse.jdt.internal.corext.dom.fragments.IASTFragment; > import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; > import org.eclipse.jdt.internal.corext.refactoring.code.ExtractConstantRefactoring; >+import org.eclipse.jdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring; >+import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; >+import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser; > > import org.eclipse.jdt.ui.refactoring.RefactoringSaveHelper; > > import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; >+import org.eclipse.jdt.internal.ui.JavaPlugin; > import org.eclipse.jdt.internal.ui.actions.ActionUtil; > import org.eclipse.jdt.internal.ui.actions.SelectionConverter; > import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; > import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection; > import org.eclipse.jdt.internal.ui.refactoring.ExtractConstantWizard; >+import org.eclipse.jdt.internal.ui.refactoring.PromoteTempWizard; > import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; > import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; > >@@ -84,7 +100,30 @@ > public void run(ITextSelection selection) { > if (!ActionUtil.isEditable(fEditor)) > return; >- ExtractConstantRefactoring refactoring= new ExtractConstantRefactoring(SelectionConverter.getInputAsCompilationUnit(fEditor), selection.getOffset(), selection.getLength()); >+ ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(fEditor); >+ CompilationUnit cuNode= RefactoringASTParser.parseWithASTProvider(unit, true, null); >+ int selectionStart= selection.getOffset(); >+ int selectionLength= selection.getLength(); >+ ExtractConstantRefactoring refactoring= new ExtractConstantRefactoring(cuNode, selectionStart, selectionLength); >+ try { >+ CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite(unit, cuNode); >+ SourceRange range= new SourceRange(selectionStart, selectionLength); >+ IASTFragment ast= ASTFragmentFactory.createFragmentForSourceRange(range, cuRewrite.getRoot(), unit); >+ ASTNode node= ast.getAssociatedNode(); >+ if (node instanceof SimpleName && node.getParent() instanceof VariableDeclaration) { >+ ICompilationUnit cunit= SelectionConverter.getInputAsCompilationUnit(fEditor); >+ PromoteTempToFieldRefactoring refactoring2= new PromoteTempToFieldRefactoring(cunit, selection.getOffset(), selection.getLength()); >+ refactoring2.setInitializeIn(PromoteTempToFieldRefactoring.INITIALIZE_IN_FIELD); >+ refactoring2.setDeclareFinal(true); >+ refactoring2.setDeclareStatic(true); >+ refactoring2.setFieldName(refactoring.guessConstantName()); >+ refactoring2.setSelfInitializing(true); >+ new RefactoringStarter().activate(new PromoteTempWizard(refactoring2), getShell(), RefactoringMessages.ConvertLocalToField_title, RefactoringSaveHelper.SAVE_NOTHING); >+ return; >+ } >+ } catch (JavaModelException e) { >+ JavaPlugin.log(e); >+ } > new RefactoringStarter().activate(new ExtractConstantWizard(refactoring), getShell(), RefactoringMessages.ExtractConstantAction_extract_constant, RefactoringSaveHelper.SAVE_NOTHING); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 432147
:
242929
|
244026
|
249301