Lines 14-25
Link Here
|
14 |
import java.util.List; |
14 |
import java.util.List; |
15 |
|
15 |
|
16 |
import org.eclipse.core.runtime.CoreException; |
16 |
import org.eclipse.core.runtime.CoreException; |
|
|
17 |
import org.eclipse.core.runtime.Status; |
17 |
|
18 |
|
18 |
import org.eclipse.jdt.core.ICompilationUnit; |
19 |
import org.eclipse.jdt.core.ICompilationUnit; |
19 |
import org.eclipse.jdt.core.IField; |
20 |
import org.eclipse.jdt.core.IField; |
20 |
import org.eclipse.jdt.core.IJavaElement; |
21 |
import org.eclipse.jdt.core.IJavaElement; |
21 |
import org.eclipse.jdt.core.IMember; |
22 |
import org.eclipse.jdt.core.IMember; |
22 |
import org.eclipse.jdt.core.IType; |
23 |
import org.eclipse.jdt.core.IType; |
|
|
24 |
import org.eclipse.jdt.core.compiler.IScanner; |
25 |
import org.eclipse.jdt.core.compiler.ITerminalSymbols; |
26 |
import org.eclipse.jdt.core.compiler.InvalidInputException; |
23 |
import org.eclipse.jdt.core.dom.ASTNode; |
27 |
import org.eclipse.jdt.core.dom.ASTNode; |
24 |
import org.eclipse.jdt.core.dom.Block; |
28 |
import org.eclipse.jdt.core.dom.Block; |
25 |
import org.eclipse.jdt.core.dom.ConstructorInvocation; |
29 |
import org.eclipse.jdt.core.dom.ConstructorInvocation; |
Lines 28-33
Link Here
|
28 |
import org.eclipse.jdt.core.dom.SimpleName; |
32 |
import org.eclipse.jdt.core.dom.SimpleName; |
29 |
import org.eclipse.jdt.core.dom.SuperConstructorInvocation; |
33 |
import org.eclipse.jdt.core.dom.SuperConstructorInvocation; |
30 |
|
34 |
|
|
|
35 |
import org.eclipse.jdt.ui.JavaUI; |
36 |
|
31 |
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; |
37 |
import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; |
32 |
import org.eclipse.jdt.internal.corext.codemanipulation.ImportEdit; |
38 |
import org.eclipse.jdt.internal.corext.codemanipulation.ImportEdit; |
33 |
import org.eclipse.jdt.internal.corext.codemanipulation.MemberEdit; |
39 |
import org.eclipse.jdt.internal.corext.codemanipulation.MemberEdit; |
Lines 41-47
Link Here
|
41 |
import org.eclipse.jdt.internal.corext.textmanipulation.TextRange; |
47 |
import org.eclipse.jdt.internal.corext.textmanipulation.TextRange; |
42 |
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; |
48 |
import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; |
43 |
import org.eclipse.jdt.internal.ui.JavaPluginImages; |
49 |
import org.eclipse.jdt.internal.ui.JavaPluginImages; |
44 |
|
|
|
45 |
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; |
50 |
import org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings; |
46 |
|
51 |
|
47 |
public class NewVariableCompletionProposal extends CUCorrectionProposal { |
52 |
public class NewVariableCompletionProposal extends CUCorrectionProposal { |
Lines 106-122
Link Here
|
106 |
private static class AddParameterEdit extends SimpleTextEdit { |
111 |
private static class AddParameterEdit extends SimpleTextEdit { |
107 |
private String fContent; |
112 |
private String fContent; |
108 |
private ASTNode fAstRoot; |
113 |
private ASTNode fAstRoot; |
|
|
114 |
private ICompilationUnit fCompilationUnit; |
109 |
|
115 |
|
110 |
public AddParameterEdit(ASTNode astRoot, String content) { |
116 |
public AddParameterEdit(ICompilationUnit cu, ASTNode astRoot, String content) { |
111 |
fAstRoot= astRoot; |
117 |
fAstRoot= astRoot; |
112 |
fContent= content; |
118 |
fContent= content; |
|
|
119 |
fCompilationUnit= cu; |
113 |
} |
120 |
} |
114 |
|
121 |
|
115 |
/* non Java-doc |
122 |
/* non Java-doc |
116 |
* @see TextEdit#getCopy |
123 |
* @see TextEdit#getCopy |
117 |
*/ |
124 |
*/ |
118 |
public TextEdit copy() { |
125 |
public TextEdit copy() { |
119 |
return new AddParameterEdit(fAstRoot, fContent); |
126 |
return new AddParameterEdit(fCompilationUnit, fAstRoot, fContent); |
120 |
} |
127 |
} |
121 |
|
128 |
|
122 |
/* non Java-doc |
129 |
/* non Java-doc |
Lines 143-149
Link Here
|
143 |
insertString= ", " + fContent; //$NON-NLS-1$ |
150 |
insertString= ", " + fContent; //$NON-NLS-1$ |
144 |
} else { |
151 |
} else { |
145 |
SimpleName name= declaration.getName(); |
152 |
SimpleName name= declaration.getName(); |
146 |
offset= name.getStartPosition() + name.getLength() - 1; |
153 |
try { |
|
|
154 |
IScanner scanner= ASTResolving.createScanner(fCompilationUnit, name.getStartPosition()); |
155 |
int nextNoken= scanner.getNextToken(); |
156 |
while (nextNoken != ITerminalSymbols.TokenNameLPAREN) { |
157 |
nextNoken= scanner.getNextToken(); |
158 |
if (nextNoken == ITerminalSymbols.TokenNameEOF) { |
159 |
throw new CoreException(new Status(Status.ERROR, JavaUI.ID_PLUGIN, Status.ERROR, "Unexpected EOF while scanning", null)); //$NON-NLS-1$ |
160 |
} |
161 |
} |
162 |
offset= scanner.getCurrentTokenEndPosition() + 1; |
163 |
} catch (InvalidInputException e) { |
164 |
throw new CoreException(new Status(Status.ERROR, JavaUI.ID_PLUGIN, Status.ERROR, "Exception while scanning", e)); //$NON-NLS-1$ |
165 |
} |
147 |
insertString= fContent; |
166 |
insertString= fContent; |
148 |
} |
167 |
} |
149 |
} |
168 |
} |
Lines 196-202
Link Here
|
196 |
changeElement.addTextEdit("field", createFieldEdit(content, settings.tabWidth)); //$NON-NLS-1$ |
215 |
changeElement.addTextEdit("field", createFieldEdit(content, settings.tabWidth)); //$NON-NLS-1$ |
197 |
} else if (fVariableKind == PARAM) { |
216 |
} else if (fVariableKind == PARAM) { |
198 |
// new parameter |
217 |
// new parameter |
199 |
changeElement.addTextEdit("parameter", new AddParameterEdit(fNode, content)); //$NON-NLS-1$ |
218 |
changeElement.addTextEdit("parameter", new AddParameterEdit(cu, fNode, content)); //$NON-NLS-1$ |
200 |
} |
219 |
} |
201 |
} |
220 |
} |
202 |
|
221 |
|