|
Lines 12-17
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.util.ArrayList; |
13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
14 |
import java.util.List; |
|
|
15 |
import java.util.Map; |
| 16 |
import java.util.TreeMap; |
| 15 |
|
17 |
|
| 16 |
import org.eclipse.core.runtime.Assert; |
18 |
import org.eclipse.core.runtime.Assert; |
| 17 |
import org.eclipse.core.runtime.IProgressMonitor; |
19 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
Lines 63-68
Link Here
|
| 63 |
} |
65 |
} |
| 64 |
|
66 |
|
| 65 |
protected void appendExpression(final String signature) { |
67 |
protected void appendExpression(final String signature) { |
|
|
68 |
appendExpression(signature, false); |
| 69 |
} |
| 70 |
|
| 71 |
protected void appendExpression(String signature, boolean castNull) { |
| 66 |
switch (signature.charAt(0)) { |
72 |
switch (signature.charAt(0)) { |
| 67 |
case Signature.C_BOOLEAN: |
73 |
case Signature.C_BOOLEAN: |
| 68 |
fBuffer.append("false"); //$NON-NLS-1$ |
74 |
fBuffer.append("false"); //$NON-NLS-1$ |
|
Lines 77-85
Link Here
|
| 77 |
fBuffer.append("0"); //$NON-NLS-1$ |
83 |
fBuffer.append("0"); //$NON-NLS-1$ |
| 78 |
break; |
84 |
break; |
| 79 |
default: |
85 |
default: |
| 80 |
fBuffer.append("("); //$NON-NLS-1$ |
86 |
if (castNull) { |
| 81 |
fBuffer.append(Signature.toString(signature)); |
87 |
fBuffer.append("("); //$NON-NLS-1$ |
| 82 |
fBuffer.append(")"); //$NON-NLS-1$ |
88 |
fBuffer.append(Signature.toString(signature)); |
|
|
89 |
fBuffer.append(")"); //$NON-NLS-1$ |
| 90 |
} |
| 83 |
fBuffer.append("null"); //$NON-NLS-1$ |
91 |
fBuffer.append("null"); //$NON-NLS-1$ |
| 84 |
break; |
92 |
break; |
| 85 |
} |
93 |
} |
|
Lines 112-117
Link Here
|
| 112 |
final IType type= (IType) member; |
120 |
final IType type= (IType) member; |
| 113 |
if (!type.isMember()) |
121 |
if (!type.isMember()) |
| 114 |
flags&= ~Flags.AccPrivate; |
122 |
flags&= ~Flags.AccPrivate; |
|
|
123 |
if (Flags.isEnum(flags)) |
| 124 |
flags&= ~Flags.AccAbstract; |
| 115 |
} |
125 |
} |
| 116 |
if (Flags.isEnum(flags)) |
126 |
if (Flags.isEnum(flags)) |
| 117 |
flags&= ~Flags.AccFinal; |
127 |
flags&= ~Flags.AccFinal; |
|
Lines 211-216
Link Here
|
| 211 |
} |
221 |
} |
| 212 |
} |
222 |
} |
| 213 |
|
223 |
|
|
|
224 |
@SuppressWarnings("boxing") |
| 214 |
protected void appendMethodBody(final IMethod method) throws JavaModelException { |
225 |
protected void appendMethodBody(final IMethod method) throws JavaModelException { |
| 215 |
if (method.isConstructor()) { |
226 |
if (method.isConstructor()) { |
| 216 |
final IType declaringType= method.getDeclaringType(); |
227 |
final IType declaringType= method.getDeclaringType(); |
|
Lines 220-247
Link Here
|
| 220 |
final IType superclass= declaringType.getJavaProject().findType(Signature.getSignatureQualifier(superSignature), Signature.getSignatureSimpleName(superSignature)); |
231 |
final IType superclass= declaringType.getJavaProject().findType(Signature.getSignatureQualifier(superSignature), Signature.getSignatureSimpleName(superSignature)); |
| 221 |
if (superclass != null) { |
232 |
if (superclass != null) { |
| 222 |
final IMethod[] superMethods= superclass.getMethods(); |
233 |
final IMethod[] superMethods= superclass.getMethods(); |
|
|
234 |
|
| 235 |
// collect super constructors by parameter count |
| 236 |
Map<Integer, List<IMethod>> superConstructorsByParamCount= new TreeMap<Integer, List<IMethod>>(); |
| 237 |
boolean multi= false; |
| 223 |
IMethod superConstructor= null; |
238 |
IMethod superConstructor= null; |
| 224 |
final int length= superMethods.length; |
239 |
for (int i= 0; i < superMethods.length; i++) { |
| 225 |
for (int index= 0; index < length; index++) { |
240 |
IMethod superMethod= superMethods[i]; |
| 226 |
final IMethod superMethod= superMethods[index]; |
241 |
if (superMethod.isConstructor() |
| 227 |
if (superMethod.isConstructor() && !Flags.isPrivate(superMethod.getFlags())) { |
242 |
&& !Flags.isPrivate(superMethod.getFlags()) |
| 228 |
superConstructor= superMethod; |
243 |
&& !(Flags.isPackageDefault(superMethod.getFlags()) && !declaringType.getPackageFragment().equals(superclass.getPackageFragment())) |
| 229 |
if (superConstructor.getExceptionTypes().length == 0) |
244 |
) { |
|
|
245 |
int paramCount= superMethod.getNumberOfParameters(); |
| 246 |
if (paramCount == 0) { |
| 247 |
superConstructor= superMethod; |
| 230 |
break; |
248 |
break; |
|
|
249 |
} |
| 250 |
List<IMethod> constructors= superConstructorsByParamCount.get(paramCount); |
| 251 |
if (constructors == null) { |
| 252 |
constructors= new ArrayList<IMethod>(); |
| 253 |
superConstructorsByParamCount.put(paramCount, constructors); |
| 254 |
} |
| 255 |
constructors.add(superMethod); |
| 256 |
} |
| 257 |
} |
| 258 |
if (superConstructor == null && superConstructorsByParamCount.size() > 0) { |
| 259 |
// look for constructors without exceptions and without parameters |
| 260 |
done: for (List<IMethod> constructors : superConstructorsByParamCount.values()) { |
| 261 |
for (IMethod constructor : constructors) { |
| 262 |
if (constructor.getExceptionTypes().length == 0) { |
| 263 |
superConstructor= constructor; |
| 264 |
multi= constructors.size() != 1; |
| 265 |
if (multi) |
| 266 |
break; |
| 267 |
else |
| 268 |
break done; |
| 269 |
} |
| 270 |
if (superConstructor == null) { |
| 271 |
superConstructor= constructor; |
| 272 |
multi= constructors.size() != 1; |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
if (superConstructor == null) { |
| 277 |
// give up, get first |
| 278 |
superConstructor= superConstructorsByParamCount.values().iterator().next().get(0); |
| 279 |
multi= true; |
| 231 |
} |
280 |
} |
| 232 |
} |
281 |
} |
| 233 |
if (superConstructor != null) { |
282 |
if (superConstructor != null) { |
| 234 |
final String[] superParameters= superConstructor.getParameterTypes(); |
283 |
final String[] superParameters= superConstructor.getParameterTypes(); |
| 235 |
final int paramLength= superParameters.length; |
284 |
final int paramLength= superParameters.length; |
|
|
285 |
fBuffer.append("super("); //$NON-NLS-1$ |
| 236 |
if (paramLength != 0) { |
286 |
if (paramLength != 0) { |
| 237 |
fBuffer.append("super("); //$NON-NLS-1$ |
|
|
| 238 |
for (int index= 0; index < paramLength; index++) { |
287 |
for (int index= 0; index < paramLength; index++) { |
| 239 |
if (index > 0) |
288 |
if (index > 0) |
| 240 |
fBuffer.append(","); //$NON-NLS-1$ |
289 |
fBuffer.append(","); //$NON-NLS-1$ |
| 241 |
appendExpression(superParameters[index]); |
290 |
appendExpression(superParameters[index], multi); |
| 242 |
} |
291 |
} |
| 243 |
fBuffer.append(");"); //$NON-NLS-1$ |
|
|
| 244 |
} |
292 |
} |
|
|
293 |
fBuffer.append(");"); //$NON-NLS-1$ |
| 245 |
} |
294 |
} |
| 246 |
} |
295 |
} |
| 247 |
} |
296 |
} |