View | Details | Raw Unified | Return to bug 21768
Collapse All | Expand All

(-)NewVariableCompletionProposal.java (-4 / +21 lines)
Lines 20-25 Link Here
20
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IMember;
21
import org.eclipse.jdt.core.IMember;
22
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.compiler.IScanner;
24
import org.eclipse.jdt.core.compiler.ITerminalSymbols;
25
import org.eclipse.jdt.core.compiler.InvalidInputException;
23
import org.eclipse.jdt.core.dom.ASTNode;
26
import org.eclipse.jdt.core.dom.ASTNode;
24
import org.eclipse.jdt.core.dom.Block;
27
import org.eclipse.jdt.core.dom.Block;
25
import org.eclipse.jdt.core.dom.ConstructorInvocation;
28
import org.eclipse.jdt.core.dom.ConstructorInvocation;
Lines 106-122 Link Here
106
	private static class AddParameterEdit extends SimpleTextEdit {
109
	private static class AddParameterEdit extends SimpleTextEdit {
107
		private String fContent;
110
		private String fContent;
108
		private ASTNode fAstRoot;
111
		private ASTNode fAstRoot;
112
		private ICompilationUnit fCompilationUnit;
109
113
110
		public AddParameterEdit(ASTNode astRoot, String content) {
114
		public AddParameterEdit(ICompilationUnit cu, ASTNode astRoot, String content) {
111
			fAstRoot= astRoot;
115
			fAstRoot= astRoot;
112
			fContent= content;
116
			fContent= content;
117
			fCompilationUnit= cu;
113
		}
118
		}
114
		
119
		
115
		/* non Java-doc
120
		/* non Java-doc
116
		 * @see TextEdit#getCopy
121
		 * @see TextEdit#getCopy
117
		 */
122
		 */
118
		public TextEdit copy() {
123
		public TextEdit copy() {
119
			return new AddParameterEdit(fAstRoot, fContent);
124
			return new AddParameterEdit(fCompilationUnit, fAstRoot, fContent);
120
		}
125
		}
121
		
126
		
122
		/* non Java-doc
127
		/* non Java-doc
Lines 143-149 Link Here
143
					insertString= ", " + fContent; //$NON-NLS-1$
148
					insertString= ", " + fContent; //$NON-NLS-1$
144
				} else {
149
				} else {
145
					SimpleName name= declaration.getName();
150
					SimpleName name= declaration.getName();
146
					offset= name.getStartPosition() + name.getLength() - 1;
151
					try {
152
						IScanner scanner= ASTResolving.createScanner(fCompilationUnit, name.getStartPosition());
153
						int nextNoken= scanner.getNextToken();
154
						while (nextNoken != ITerminalSymbols.TokenNameLPAREN) {
155
							nextNoken= scanner.getNextToken();
156
							if (nextNoken == ITerminalSymbols.TokenNameEOF) {
157
								return;
158
							}
159
						}
160
						offset= scanner.getCurrentTokenEndPosition() + 1;
161
					} catch (InvalidInputException e) {
162
						return;
163
					}					
147
					insertString= fContent;
164
					insertString= fContent;
148
				}
165
				}
149
			}
166
			}
Lines 196-202 Link Here
196
			changeElement.addTextEdit("field", createFieldEdit(content, settings.tabWidth)); //$NON-NLS-1$
213
			changeElement.addTextEdit("field", createFieldEdit(content, settings.tabWidth)); //$NON-NLS-1$
197
		} else if (fVariableKind == PARAM) {
214
		} else if (fVariableKind == PARAM) {
198
			// new parameter
215
			// new parameter
199
			changeElement.addTextEdit("parameter", new AddParameterEdit(fNode, content)); //$NON-NLS-1$
216
			changeElement.addTextEdit("parameter", new AddParameterEdit(cu, fNode, content)); //$NON-NLS-1$
200
		}
217
		}
201
	}
218
	}
202
	
219
	

Return to bug 21768