Lines 122-128
Link Here
|
122 |
} |
122 |
} |
123 |
} |
123 |
} |
124 |
|
124 |
|
125 |
protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration, AbstractTypeDeclaration typeDecl) { |
125 |
protected void buildBodyDeclarations( |
|
|
126 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration, |
127 |
AbstractTypeDeclaration typeDecl, |
128 |
boolean isInterface) { |
126 |
// add body declaration in the lexical order |
129 |
// add body declaration in the lexical order |
127 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes; |
130 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes; |
128 |
org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields; |
131 |
org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields; |
Lines 177-183
Link Here
|
177 |
case 1 : |
180 |
case 1 : |
178 |
methodsIndex++; |
181 |
methodsIndex++; |
179 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
182 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
180 |
typeDecl.bodyDeclarations().add(convert(nextMethodDeclaration)); |
183 |
typeDecl.bodyDeclarations().add(convert(isInterface, nextMethodDeclaration)); |
181 |
} |
184 |
} |
182 |
break; |
185 |
break; |
183 |
case 2 : |
186 |
case 2 : |
Lines 249-255
Link Here
|
249 |
case 1 : |
252 |
case 1 : |
250 |
methodsIndex++; |
253 |
methodsIndex++; |
251 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
254 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
252 |
enumDeclaration.bodyDeclarations().add(convert(nextMethodDeclaration)); |
255 |
enumDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration)); |
253 |
} |
256 |
} |
254 |
break; |
257 |
break; |
255 |
case 2 : |
258 |
case 2 : |
Lines 316-322
Link Here
|
316 |
case 1 : |
319 |
case 1 : |
317 |
methodsIndex++; |
320 |
methodsIndex++; |
318 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
321 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
319 |
anonymousClassDeclaration.bodyDeclarations().add(convert(nextMethodDeclaration)); |
322 |
anonymousClassDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration)); |
320 |
} |
323 |
} |
321 |
break; |
324 |
break; |
322 |
case 2 : |
325 |
case 2 : |
Lines 415-421
Link Here
|
415 |
} |
418 |
} |
416 |
} |
419 |
} |
417 |
|
420 |
|
418 |
public ASTNode convert(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) { |
421 |
public ASTNode convert(boolean isInterface, org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) { |
419 |
checkCanceled(); |
422 |
checkCanceled(); |
420 |
if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) { |
423 |
if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) { |
421 |
return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration); |
424 |
return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration); |
Lines 457-462
Link Here
|
457 |
} |
460 |
} |
458 |
org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null; |
461 |
org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null; |
459 |
if (isConstructor) { |
462 |
if (isConstructor) { |
|
|
463 |
if (isInterface) { |
464 |
// interface cannot have a constructor |
465 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
466 |
} |
460 |
org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration; |
467 |
org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration; |
461 |
explicitConstructorCall = constructorDeclaration.constructorCall; |
468 |
explicitConstructorCall = constructorDeclaration.constructorCall; |
462 |
switch(this.ast.apiLevel) { |
469 |
switch(this.ast.apiLevel) { |
Lines 481-499
Link Here
|
481 |
methodDecl.setExtraDimensions(extraDimensions); |
488 |
methodDecl.setExtraDimensions(extraDimensions); |
482 |
setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions); |
489 |
setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions); |
483 |
} else { |
490 |
} else { |
|
|
491 |
// no return type for a method that is not a constructor |
492 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
484 |
switch(this.ast.apiLevel) { |
493 |
switch(this.ast.apiLevel) { |
485 |
case AST.JLS2_INTERNAL : |
|
|
486 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
487 |
break; |
488 |
case AST.JLS3 : |
494 |
case AST.JLS3 : |
489 |
methodDecl.setReturnType2(null); |
495 |
methodDecl.setReturnType2(null); |
490 |
} |
496 |
} |
491 |
} |
497 |
} |
492 |
} |
498 |
} |
493 |
int declarationSourceStart = methodDeclaration.declarationSourceStart; |
499 |
int declarationSourceStart = methodDeclaration.declarationSourceStart; |
494 |
int declarationSourceEnd = methodDeclaration.bodyEnd; |
500 |
int bodyEnd = methodDeclaration.bodyEnd; |
495 |
methodDecl.setSourceRange(declarationSourceStart, declarationSourceEnd - declarationSourceStart + 1); |
501 |
methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1); |
496 |
int closingPosition = retrieveRightBraceOrSemiColonPosition(methodDeclaration.bodyEnd + 1, methodDeclaration.declarationSourceEnd); |
502 |
int declarationSourceEnd = methodDeclaration.declarationSourceEnd; |
|
|
503 |
int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1; |
504 |
int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart, declarationSourceEnd); |
497 |
if (closingPosition != -1) { |
505 |
if (closingPosition != -1) { |
498 |
int startPosition = methodDecl.getStartPosition(); |
506 |
int startPosition = methodDecl.getStartPosition(); |
499 |
methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1); |
507 |
methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1); |
Lines 502-508
Link Here
|
502 |
|
510 |
|
503 |
start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart); |
511 |
start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart); |
504 |
if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start |
512 |
if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start |
505 |
end = retrieveRightBrace(methodDeclaration.bodyEnd, methodDeclaration.declarationSourceEnd); |
513 |
end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd); |
506 |
Block block = null; |
514 |
Block block = null; |
507 |
if (start != -1 && end != -1) { |
515 |
if (start != -1 && end != -1) { |
508 |
/* |
516 |
/* |
Lines 528-541
Link Here
|
528 |
} |
536 |
} |
529 |
} |
537 |
} |
530 |
} |
538 |
} |
531 |
if (block != null && (Modifier.isAbstract(methodDecl.getModifiers()) || Modifier.isNative(methodDecl.getModifiers()))) { |
539 |
if (block != null |
|
|
540 |
&& (Modifier.isAbstract(methodDecl.getModifiers()) |
541 |
|| Modifier.isNative(methodDecl.getModifiers()) |
542 |
|| isInterface)) { |
532 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
543 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
533 |
} |
544 |
} |
534 |
} else { |
545 |
} else { |
535 |
// syntax error in this method declaration |
546 |
// syntax error in this method declaration |
536 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
547 |
methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); |
537 |
if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) { |
548 |
if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) { |
538 |
start = retrieveStartBlockPosition(methodHeaderEnd, declarationSourceEnd); |
549 |
start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd); |
539 |
if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start |
550 |
if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start |
540 |
end = methodDeclaration.bodyEnd; |
551 |
end = methodDeclaration.bodyEnd; |
541 |
// try to get the best end position |
552 |
// try to get the best end position |
Lines 708-714
Link Here
|
708 |
typeDecl.setName(typeName); |
719 |
typeDecl.setName(typeName); |
709 |
typeDecl.setSourceRange(typeDeclaration.declarationSourceStart, typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1); |
720 |
typeDecl.setSourceRange(typeDeclaration.declarationSourceStart, typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1); |
710 |
|
721 |
|
711 |
buildBodyDeclarations(typeDeclaration, typeDecl); |
722 |
buildBodyDeclarations(typeDeclaration, typeDecl, false); |
712 |
// The javadoc comment is now got from list store in compilation unit declaration |
723 |
// The javadoc comment is now got from list store in compilation unit declaration |
713 |
if (this.resolveBindings) { |
724 |
if (this.resolveBindings) { |
714 |
recordNodes(typeDecl, typeDeclaration); |
725 |
recordNodes(typeDecl, typeDeclaration); |
Lines 970-976
Link Here
|
970 |
} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) { |
981 |
} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) { |
971 |
AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node; |
982 |
AbstractMethodDeclaration nextMethodDeclaration = (AbstractMethodDeclaration) node; |
972 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
983 |
if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { |
973 |
typeDecl.bodyDeclarations().add(convert(nextMethodDeclaration)); |
984 |
typeDecl.bodyDeclarations().add(convert(false, nextMethodDeclaration)); |
974 |
} |
985 |
} |
975 |
} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
986 |
} else if(node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
976 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
987 |
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
Lines 2662-2668
Link Here
|
2662 |
if (typeDeclaration.modifiersSourceStart != -1) { |
2673 |
if (typeDeclaration.modifiersSourceStart != -1) { |
2663 |
setModifiers(typeDecl, typeDeclaration); |
2674 |
setModifiers(typeDecl, typeDeclaration); |
2664 |
} |
2675 |
} |
2665 |
typeDecl.setInterface(kind == org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.INTERFACE_DECL); |
2676 |
boolean isInterface = kind == org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.INTERFACE_DECL; |
|
|
2677 |
typeDecl.setInterface(isInterface); |
2666 |
final SimpleName typeName = new SimpleName(this.ast); |
2678 |
final SimpleName typeName = new SimpleName(this.ast); |
2667 |
typeName.internalSetIdentifier(new String(typeDeclaration.name)); |
2679 |
typeName.internalSetIdentifier(new String(typeDeclaration.name)); |
2668 |
typeName.setSourceRange(typeDeclaration.sourceStart, typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1); |
2680 |
typeName.setSourceRange(typeDeclaration.sourceStart, typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1); |
Lines 2708-2714
Link Here
|
2708 |
} |
2720 |
} |
2709 |
} |
2721 |
} |
2710 |
} |
2722 |
} |
2711 |
buildBodyDeclarations(typeDeclaration, typeDecl); |
2723 |
buildBodyDeclarations(typeDeclaration, typeDecl, isInterface); |
2712 |
if (this.resolveBindings) { |
2724 |
if (this.resolveBindings) { |
2713 |
recordNodes(typeDecl, typeDeclaration); |
2725 |
recordNodes(typeDecl, typeDeclaration); |
2714 |
recordNodes(typeName, typeDeclaration); |
2726 |
recordNodes(typeName, typeDeclaration); |