package org.eclipse.jdt.internal.compiler;
import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.*;
import org.eclipse.jdt.internal.compiler.impl.*;
import org.eclipse.jdt.core.compiler.*;
import org.eclipse.jdt.internal.compiler.ast.*;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.internal.compiler.problem.*;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
import org.eclipse.jdt.internal.core.util.CommentRecorderParser;
import org.eclipse.jdt.internal.core.util.Messages;
@SuppressWarnings({"rawtypes", "unchecked"})
public class SourceElementParser extends CommentRecorderParser {
ISourceElementRequestor requestor;
boolean reportReferenceInfo;
boolean reportLocalDeclarations;
HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
HashMap nodesToCategories = new HashMap();
boolean useSourceJavadocParser = true;
SourceElementNotifier notifier;
public SourceElementParser(
final ISourceElementRequestor requestor,
IProblemFactory problemFactory,
CompilerOptions options,
boolean reportLocalDeclarations,
boolean optimizeStringLiterals) {
this(requestor, problemFactory, options, reportLocalDeclarations, optimizeStringLiterals, true);
}
public SourceElementParser(
ISourceElementRequestor requestor,
IProblemFactory problemFactory,
CompilerOptions options,
boolean reportLocalDeclarations,
boolean optimizeStringLiterals,
boolean useSourceJavadocParser) {
super(
new ProblemReporter(
DefaultErrorHandlingPolicies.exitAfterAllProblems(),
options,
problemFactory),
optimizeStringLiterals);
this.reportLocalDeclarations = reportLocalDeclarations;
this.problemReporter = new ProblemReporter(
DefaultErrorHandlingPolicies.exitAfterAllProblems(),
options,
problemFactory) {
@Override
public void record(CategorizedProblem problem, CompilationResult unitResult, ReferenceContext context, boolean mandatoryError) {
unitResult.record(problem, context, mandatoryError);
SourceElementParser.this.requestor.acceptProblem(problem);
}
};
this.requestor = requestor;
this.options = options;
this.notifier = new SourceElementNotifier(this.requestor, reportLocalDeclarations);
this.useSourceJavadocParser = useSourceJavadocParser;
if (useSourceJavadocParser) {
this.javadocParser = new SourceJavadocParser(this);
}
}
private void acceptJavadocTypeReference(Expression expression) {
if (expression instanceof JavadocSingleTypeReference) {
JavadocSingleTypeReference singleRef = (JavadocSingleTypeReference) expression;
this.requestor.acceptTypeReference(singleRef.token, singleRef.sourceStart);
} else if (expression instanceof JavadocQualifiedTypeReference) {
JavadocQualifiedTypeReference qualifiedRef = (JavadocQualifiedTypeReference) expression;
this.requestor.acceptTypeReference(qualifiedRef.tokens, qualifiedRef.sourceStart, qualifiedRef.sourceEnd);
}
}
public void addUnknownRef(NameReference nameRef) {
if (nameRef instanceof SingleNameReference) {
this.requestor.acceptUnknownReference(((SingleNameReference) nameRef).token, nameRef.sourceStart);
} else {
this.requestor.acceptUnknownReference(((QualifiedNameReference) nameRef).tokens, nameRef.sourceStart, nameRef.sourceEnd);
}
}
@Override
public void () {
int lastComment = getCommentPtr();
if (!(this.diet && this.dietInt==0) && lastComment >= 0) {
flushCommentsDefinedPriorTo(this.endStatementPosition);
lastComment = getCommentPtr();
}
if (this.modifiersSourceStart >= 0) {
while (lastComment >= 0) {
int commentSourceStart = this.scanner.commentStarts[lastComment];
if (commentSourceStart < 0) commentSourceStart = -commentSourceStart;
if (commentSourceStart <= this.modifiersSourceStart) break;
lastComment--;
}
}
if (lastComment >= 0) {
int lastCommentStart = this.scanner.commentStarts[0];
if (lastCommentStart < 0) lastCommentStart = -lastCommentStart;
if (this.forStartPosition == 0 || this.forStartPosition < lastCommentStart) {
this.modifiersSourceStart = lastCommentStart;
}
while (lastComment >= 0 && this.scanner.commentStops[lastComment] < 0) lastComment--;
if (lastComment >= 0 && this.javadocParser != null) {
int commentEnd = this.scanner.commentStops[lastComment] - 1;
if (this.javadocParser.shouldReportProblems) {
this.javadocParser.reportProblems = this.currentElement == null || commentEnd > this.lastJavadocEnd;
} else {
this.javadocParser.reportProblems = false;
}
if (this.javadocParser.checkDeprecation(lastComment)) {
checkAndSetModifiers(ClassFileConstants.AccDeprecated);
}
this.javadoc = this.javadocParser.docComment;
if (this.currentElement == null) this.lastJavadocEnd = commentEnd;
}
}
if (this.reportReferenceInfo && this.javadocParser.checkDocComment && this.javadoc != null) {
TypeReference[] thrownExceptions = this.javadoc.exceptionReferences;
if (thrownExceptions != null) {
for (int i = 0, max=thrownExceptions.length; i < max; i++) {
TypeReference typeRef = thrownExceptions[i];
if (typeRef instanceof JavadocSingleTypeReference) {
JavadocSingleTypeReference singleRef = (JavadocSingleTypeReference) typeRef;
this.requestor.acceptTypeReference(singleRef.token, singleRef.sourceStart);
} else if (typeRef instanceof JavadocQualifiedTypeReference) {
JavadocQualifiedTypeReference qualifiedRef = (JavadocQualifiedTypeReference) typeRef;
this.requestor.acceptTypeReference(qualifiedRef.tokens, qualifiedRef.sourceStart, qualifiedRef.sourceEnd);
}
}
}
Expression[] references = this.javadoc.seeReferences;
if (references != null) {
for (int i = 0, max=references.length; i < max; i++) {
Expression reference = references[i];
acceptJavadocTypeReference(reference);
if (reference instanceof JavadocFieldReference) {
JavadocFieldReference fieldRef = (JavadocFieldReference) reference;
this.requestor.acceptFieldReference(fieldRef.token, fieldRef.sourceStart);
if (fieldRef.receiver != null && !fieldRef.receiver.isThis()) {
acceptJavadocTypeReference(fieldRef.receiver);
}
} else if (reference instanceof JavadocMessageSend) {
JavadocMessageSend messageSend = (JavadocMessageSend) reference;
int argCount = messageSend.arguments == null ? 0 : messageSend.arguments.length;
this.requestor.acceptMethodReference(messageSend.selector, argCount, messageSend.sourceStart);
this.requestor.acceptConstructorReference(messageSend.selector, argCount, messageSend.sourceStart);
if (messageSend.receiver != null && !messageSend.receiver.isThis()) {
acceptJavadocTypeReference(messageSend.receiver);
}
} else if (reference instanceof JavadocAllocationExpression) {
JavadocAllocationExpression constructor = (JavadocAllocationExpression) reference;
int argCount = constructor.arguments == null ? 0 : constructor.arguments.length;
if (constructor.type != null) {
char[][] compoundName = constructor.type.getParameterizedTypeName();
this.requestor.acceptConstructorReference(compoundName[compoundName.length-1], argCount, constructor.sourceStart);
if (!constructor.type.isThis()) {
acceptJavadocTypeReference(constructor.type);
}
}
}
}
}
}
}
@Override
protected void classInstanceCreation(boolean alwaysQualified) {
boolean previousFlag = this.reportReferenceInfo;
this.reportReferenceInfo = false;
super.classInstanceCreation(alwaysQualified);
this.reportReferenceInfo = previousFlag;
if (this.reportReferenceInfo){
AllocationExpression alloc = (AllocationExpression)this.expressionStack[this.expressionPtr];
TypeReference typeRef = alloc.type;
this.requestor.acceptConstructorReference(
typeRef instanceof SingleTypeReference
? ((SingleTypeReference) typeRef).token
: CharOperation.concatWith(alloc.type.getParameterizedTypeName(), '.'),
alloc.arguments == null ? 0 : alloc.arguments.length,
alloc.sourceStart);
}
}
@Override
protected void consumeAnnotationAsModifier() {
super.consumeAnnotationAsModifier();
Annotation annotation = (Annotation)this.expressionStack[this.expressionPtr];
if (this.reportReferenceInfo) {
this.requestor.acceptAnnotationTypeReference(annotation.type.getTypeName(), annotation.sourceStart, annotation.sourceEnd);
}
}
@Override
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
boolean previousFlag = this.reportReferenceInfo;
this.reportReferenceInfo = false;
super.consumeClassInstanceCreationExpressionQualifiedWithTypeArguments();
this.reportReferenceInfo = previousFlag;
if (this.reportReferenceInfo){
AllocationExpression alloc = (AllocationExpression)this.expressionStack[this.expressionPtr];
TypeReference typeRef = alloc.type;
this.requestor.acceptConstructorReference(
typeRef instanceof SingleTypeReference
? ((SingleTypeReference) typeRef).token
: CharOperation.concatWith(alloc.type.getParameterizedTypeName(), '.'),
alloc.arguments == null ? 0 : alloc.arguments.length,
alloc.sourceStart);
}
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeAnnotationTypeDeclarationHeaderName();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeAnnotationTypeDeclarationHeaderNameWithTypeParameters();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void consumeCatchFormalParameter() {
super.consumeCatchFormalParameter();
flushCommentsDefinedPriorTo(this.scanner.currentPosition);
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeClassHeaderName1();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeModuleHeader();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void consumeClassInstanceCreationExpressionWithTypeArguments() {
boolean previousFlag = this.reportReferenceInfo;
this.reportReferenceInfo = false;
super.consumeClassInstanceCreationExpressionWithTypeArguments();
this.reportReferenceInfo = previousFlag;
if (this.reportReferenceInfo){
AllocationExpression alloc = (AllocationExpression)this.expressionStack[this.expressionPtr];
TypeReference typeRef = alloc.type;
this.requestor.acceptConstructorReference(
typeRef instanceof SingleTypeReference
? ((SingleTypeReference) typeRef).token
: CharOperation.concatWith(alloc.type.getParameterizedTypeName(), '.'),
alloc.arguments == null ? 0 : alloc.arguments.length,
alloc.sourceStart);
}
}
@Override
protected void () {
long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
int selectorSourceEnd = (int) selectorSourcePositions;
int currentAstPtr = this.astPtr;
super.consumeConstructorHeaderName();
if (this.astPtr > currentAstPtr) {
this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
rememberCategories();
}
}
@Override
protected void () {
long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
int selectorSourceEnd = (int) selectorSourcePositions;
int currentAstPtr = this.astPtr;
super.consumeConstructorHeaderNameWithTypeParameters();
if (this.astPtr > currentAstPtr) {
this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
rememberCategories();
}
}
@Override
protected void consumeEnumConstantWithClassBody() {
super.consumeEnumConstantWithClassBody();
if ((this.currentToken == TokenNameCOMMA || this.currentToken == TokenNameSEMICOLON)
&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
rememberCategories();
}
}
@Override
protected void consumeEnumConstantNoClassBody() {
super.consumeEnumConstantNoClassBody();
if ((this.currentToken == TokenNameCOMMA || this.currentToken == TokenNameSEMICOLON)
&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
rememberCategories();
}
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeEnumHeaderName();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeEnumHeaderNameWithTypeParameters();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void consumeExitVariableWithInitialization() {
super.consumeExitVariableWithInitialization();
if ((this.currentToken == TokenNameCOMMA || this.currentToken == TokenNameSEMICOLON)
&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
rememberCategories();
}
}
@Override
protected void consumeExitVariableWithoutInitialization() {
super.consumeExitVariableWithoutInitialization();
if ((this.currentToken == TokenNameCOMMA || this.currentToken == TokenNameSEMICOLON)
&& this.astStack[this.astPtr] instanceof FieldDeclaration) {
this.sourceEnds.put(this.astStack[this.astPtr], this.scanner.currentPosition - 1);
rememberCategories();
}
}
@Override
protected void consumeFieldAccess(boolean isSuperAccess) {
super.consumeFieldAccess(isSuperAccess);
FieldReference fr = (FieldReference) this.expressionStack[this.expressionPtr];
if (this.reportReferenceInfo) {
this.requestor.acceptFieldReference(fr.token, fr.sourceStart);
}
}
@Override
protected void consumeFormalParameter(boolean isVarArgs) {
super.consumeFormalParameter(isVarArgs);
flushCommentsDefinedPriorTo(this.scanner.currentPosition);
}
@Override
protected void consumeTypeElidedLambdaParameter(boolean parenthesized) {
super.consumeTypeElidedLambdaParameter(parenthesized);
flushCommentsDefinedPriorTo(this.scanner.currentPosition);
}
@Override
protected void () {
int currentAstPtr = this.astPtr;
super.consumeInterfaceHeaderName1();
if (this.astPtr > currentAstPtr)
rememberCategories();
}
@Override
protected void consumeMemberValuePair() {
super.consumeMemberValuePair();
MemberValuePair memberValuepair = (MemberValuePair) this.astStack[this.astPtr];
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(memberValuepair.name, 0, memberValuepair.sourceStart);
}
}
@Override
protected void consumeMarkerAnnotation(boolean isTypeAnnotation) {
super.consumeMarkerAnnotation(isTypeAnnotation);
Annotation annotation = (Annotation) (isTypeAnnotation ? this.typeAnnotationStack[this.typeAnnotationPtr] : this.expressionStack[this.expressionPtr]);
if (this.reportReferenceInfo) {
this.requestor.acceptAnnotationTypeReference(annotation.type.getTypeName(), annotation.sourceStart, annotation.sourceEnd);
}
}
@Override
protected void (boolean isAnnotationMethod) {
long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
int selectorSourceEnd = (int) selectorSourcePositions;
int currentAstPtr = this.astPtr;
super.consumeMethodHeaderName(isAnnotationMethod);
if (this.astPtr > currentAstPtr) {
this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
rememberCategories();
}
flushCommentsDefinedPriorTo(this.scanner.currentPosition);
}
@Override
protected void (boolean isAnnotationMethod) {
long selectorSourcePositions = this.identifierPositionStack[this.identifierPtr];
int selectorSourceEnd = (int) selectorSourcePositions;
int currentAstPtr = this.astPtr;
super.consumeMethodHeaderNameWithTypeParameters(isAnnotationMethod);
if (this.astPtr > currentAstPtr)
this.sourceEnds.put(this.astStack[this.astPtr], selectorSourceEnd);
rememberCategories();
}
@Override
protected void consumeMethodInvocationName() {
super.consumeMethodInvocationName();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeMethodInvocationNameWithTypeArguments() {
super.consumeMethodInvocationNameWithTypeArguments();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeMethodInvocationPrimary() {
super.consumeMethodInvocationPrimary();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeMethodInvocationPrimaryWithTypeArguments() {
super.consumeMethodInvocationPrimaryWithTypeArguments();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeMethodInvocationSuper() {
super.consumeMethodInvocationSuper();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeMethodInvocationSuperWithTypeArguments() {
super.consumeMethodInvocationSuperWithTypeArguments();
MessageSend messageSend = (MessageSend) this.expressionStack[this.expressionPtr];
Expression[] args = messageSend.arguments;
if (this.reportReferenceInfo) {
this.requestor.acceptMethodReference(
messageSend.selector,
args == null ? 0 : args.length,
(int)(messageSend.nameSourcePosition >>> 32));
}
}
@Override
protected void consumeNormalAnnotation(boolean isTypeAnnotation) {
super.consumeNormalAnnotation(isTypeAnnotation);
Annotation annotation = (Annotation) (isTypeAnnotation ? this.typeAnnotationStack[this.typeAnnotationPtr] : this.expressionStack[this.expressionPtr]);
if (this.reportReferenceInfo) {
this.requestor.acceptAnnotationTypeReference(annotation.type.getTypeName(), annotation.sourceStart, annotation.sourceEnd);
}
}
@Override
protected void consumeProvidesStatement() {
super.consumeProvidesStatement();
ProvidesStatement service = (ProvidesStatement) this.astStack[this.astPtr];
TypeReference ref = service.serviceInterface;
this.requestor.acceptTypeReference(ref.getTypeName(), ref.sourceStart, ref.sourceEnd);
}
@Override
protected void consumeSingleMemberAnnotation(boolean isTypeAnnotation) {
super.consumeSingleMemberAnnotation(isTypeAnnotation);
SingleMemberAnnotation member = (SingleMemberAnnotation) (isTypeAnnotation ? this.typeAnnotationStack[this.typeAnnotationPtr] : this.expressionStack[this.expressionPtr]);
if (this.reportReferenceInfo) {
this.requestor.acceptAnnotationTypeReference(member.type.getTypeName(), member.sourceStart, member.sourceEnd);
this.requestor.acceptMethodReference(TypeConstants.VALUE, 0, member.sourceStart);
}
}
@Override
protected void consumeSingleStaticImportDeclarationName() {
ImportReference impt;
int length;
char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
this.identifierPtr -= length;
long[] positions = new long[length];
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccStatic));
this.modifiers = ClassFileConstants.AccDefault;
this.modifiersSourceStart = -1;
if (this.currentToken == TokenNameSEMICOLON){
impt.declarationSourceEnd = this.scanner.currentPosition - 1;
} else {
impt.declarationSourceEnd = impt.sourceEnd;
}
impt.declarationEnd = impt.declarationSourceEnd;
impt.declarationSourceStart = this.intStack[this.intPtr--];
if(!this.statementRecoveryActivated &&
this.options.sourceLevel < ClassFileConstants.JDK1_5 &&
this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
impt.modifiers = ClassFileConstants.AccDefault;
problemReporter().invalidUsageOfStaticImports(impt);
}
if (this.currentElement != null){
this.lastCheckPoint = impt.declarationSourceEnd+1;
this.currentElement = this.currentElement.add(impt, 0);
this.lastIgnoredToken = -1;
this.restartRecovery = true;
}
if (this.reportReferenceInfo) {
int tokensLength = impt.tokens.length-1;
int start = (int) (impt.sourcePositions[tokensLength] >>> 32);
char[] last = impt.tokens[tokensLength];
this.requestor.acceptFieldReference(last, start);
this.requestor.acceptMethodReference(last, 0,start);
this.requestor.acceptTypeReference(last, start);
if (tokensLength > 0) {
char[][] compoundName = new char[tokensLength][];
System.arraycopy(impt.tokens, 0, compoundName, 0, tokensLength);
int end = (int) impt.sourcePositions[tokensLength-1];
this.requestor.acceptTypeReference(compoundName, impt.sourceStart, end);
}
}
}
@Override
protected void consumeSingleTypeImportDeclarationName() {
ImportReference impt;
int length;
char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
this.identifierPtr -= length;
long[] positions = new long[length];
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
pushOnAstStack(impt = newImportReference(tokens, positions, false, ClassFileConstants.AccDefault));
if (this.currentToken == TokenNameSEMICOLON){
impt.declarationSourceEnd = this.scanner.currentPosition - 1;
} else {
impt.declarationSourceEnd = impt.sourceEnd;
}
impt.declarationEnd = impt.declarationSourceEnd;
impt.declarationSourceStart = this.intStack[this.intPtr--];
if (this.currentElement != null){
this.lastCheckPoint = impt.declarationSourceEnd+1;
this.currentElement = this.currentElement.add(impt, 0);
this.lastIgnoredToken = -1;
this.restartRecovery = true;
}
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
}
}
@Override
protected void consumeStaticImportOnDemandDeclarationName() {
ImportReference impt;
int length;
char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
this.identifierPtr -= length;
long[] positions = new long[length];
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccStatic));
impt.trailingStarPosition = this.intStack[this.intPtr--];
this.modifiers = ClassFileConstants.AccDefault;
this.modifiersSourceStart = -1;
if (this.currentToken == TokenNameSEMICOLON){
impt.declarationSourceEnd = this.scanner.currentPosition - 1;
} else {
impt.declarationSourceEnd = impt.sourceEnd;
}
impt.declarationEnd = impt.declarationSourceEnd;
impt.declarationSourceStart = this.intStack[this.intPtr--];
if(!this.statementRecoveryActivated &&
this.options.sourceLevel < ClassFileConstants.JDK1_5 &&
this.lastErrorEndPositionBeforeRecovery < this.scanner.currentPosition) {
impt.modifiers = ClassFileConstants.AccDefault;
problemReporter().invalidUsageOfStaticImports(impt);
}
if (this.currentElement != null){
this.lastCheckPoint = impt.declarationSourceEnd+1;
this.currentElement = this.currentElement.add(impt, 0);
this.lastIgnoredToken = -1;
this.restartRecovery = true;
}
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
}
}
@Override
protected void consumeTypeImportOnDemandDeclarationName() {
ImportReference impt;
int length;
char[][] tokens = new char[length = this.identifierLengthStack[this.identifierLengthPtr--]][];
this.identifierPtr -= length;
long[] positions = new long[length];
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
pushOnAstStack(impt = new ImportReference(tokens, positions, true, ClassFileConstants.AccDefault));
impt.trailingStarPosition = this.intStack[this.intPtr--];
if (this.currentToken == TokenNameSEMICOLON){
impt.declarationSourceEnd = this.scanner.currentPosition - 1;
} else {
impt.declarationSourceEnd = impt.sourceEnd;
}
impt.declarationEnd = impt.declarationSourceEnd;
impt.declarationSourceStart = this.intStack[this.intPtr--];
if (this.currentElement != null){
this.lastCheckPoint = impt.declarationSourceEnd+1;
this.currentElement = this.currentElement.add(impt, 0);
this.lastIgnoredToken = -1;
this.restartRecovery = true;
}
if (this.reportReferenceInfo) {
this.requestor.acceptUnknownReference(impt.tokens, impt.sourceStart, impt.sourceEnd);
}
}
@Override
protected void consumeUsesStatement() {
super.consumeUsesStatement();
UsesStatement ref = (UsesStatement) this.astStack[this.astPtr];
this.requestor.acceptTypeReference(ref.serviceInterface.getTypeName(), ref.sourceStart, ref.sourceEnd);
}
@Override
protected void consumeWithClause() {
super.consumeWithClause();
ProvidesStatement service = (ProvidesStatement) this.astStack[this.astPtr];
for (int i = 0; i < service.implementations.length; i++) {
TypeReference ref = service.implementations[i];
this.requestor.acceptTypeReference(ref.getTypeName(), ref.sourceStart, ref.sourceEnd);
}
}
@Override
public MethodDeclaration convertToMethodDeclaration(ConstructorDeclaration c, CompilationResult compilationResult) {
MethodDeclaration methodDeclaration = super.convertToMethodDeclaration(c, compilationResult);
int selectorSourceEnd = this.sourceEnds.removeKey(c);
if (selectorSourceEnd != -1)
this.sourceEnds.put(methodDeclaration, selectorSourceEnd);
char[][] categories = (char[][]) this.nodesToCategories.remove(c);
if (categories != null)
this.nodesToCategories.put(methodDeclaration, categories);
return methodDeclaration;
}
@Override
protected CompilationUnitDeclaration endParse(int act) {
if (this.scanner.recordLineSeparator) {
this.requestor.acceptLineSeparatorPositions(this.scanner.getLineEnds());
}
if (this.compilationUnit != null) {
CompilationUnitDeclaration result = super.endParse(act);
return result;
} else {
return null;
}
}
@Override
public TypeReference getTypeReference(int dim) {
Annotation [][] annotationsOnDimensions = null;
TypeReference ref;
int length = this.identifierLengthStack[this.identifierLengthPtr--];
if (length < 0) {
annotationsOnDimensions = getAnnotationsOnDimensions(dim);
ref = TypeReference.baseTypeReference(-length, dim, annotationsOnDimensions);
ref.sourceStart = this.intStack[this.intPtr--];
if (dim == 0) {
ref.sourceEnd = this.intStack[this.intPtr--];
} else {
this.intPtr--;
ref.sourceEnd = this.rBracketPosition;
}
if (this.reportReferenceInfo){
this.requestor.acceptTypeReference(ref.getParameterizedTypeName(), ref.sourceStart, ref.sourceEnd);
}
} else {
int numberOfIdentifiers = this.genericsIdentifiersLengthStack[this.genericsIdentifiersLengthPtr--];
if (length != numberOfIdentifiers || this.genericsLengthStack[this.genericsLengthPtr] != 0) {
ref = getTypeReferenceForGenericType(dim, length, numberOfIdentifiers);
if (this.reportReferenceInfo) {
if (length == 1 && numberOfIdentifiers == 1) {
ParameterizedSingleTypeReference parameterizedSingleTypeReference = (ParameterizedSingleTypeReference) ref;
this.requestor.acceptTypeReference(parameterizedSingleTypeReference.token, parameterizedSingleTypeReference.sourceStart);
} else {
ParameterizedQualifiedTypeReference parameterizedQualifiedTypeReference = (ParameterizedQualifiedTypeReference) ref;
this.requestor.acceptTypeReference(parameterizedQualifiedTypeReference.tokens, parameterizedQualifiedTypeReference.sourceStart, parameterizedQualifiedTypeReference.sourceEnd);
}
}
} else if (length == 1) {
this.genericsLengthPtr--;
if (dim == 0) {
ref =
new SingleTypeReference(
this.identifierStack[this.identifierPtr],
this.identifierPositionStack[this.identifierPtr--]);
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(((SingleTypeReference)ref).token, ref.sourceStart);
}
} else {
annotationsOnDimensions = getAnnotationsOnDimensions(dim);
ref =
new ArrayTypeReference(
this.identifierStack[this.identifierPtr],
dim,
annotationsOnDimensions,
this.identifierPositionStack[this.identifierPtr--]);
ref.sourceEnd = this.endPosition;
if (annotationsOnDimensions != null) {
ref.bits |= ASTNode.HasTypeAnnotations;
}
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(((ArrayTypeReference)ref).token, ref.sourceStart);
}
}
} else {
this.genericsLengthPtr--;
char[][] tokens = new char[length][];
this.identifierPtr -= length;
long[] positions = new long[length];
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
System.arraycopy(
this.identifierPositionStack,
this.identifierPtr + 1,
positions,
0,
length);
if (dim == 0) {
ref = new QualifiedTypeReference(tokens, positions);
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(((QualifiedTypeReference)ref).tokens, ref.sourceStart, ref.sourceEnd);
}
} else {
annotationsOnDimensions = getAnnotationsOnDimensions(dim);
ref =
new ArrayQualifiedTypeReference(tokens, dim, annotationsOnDimensions, positions);
ref.sourceEnd = this.endPosition;
if (annotationsOnDimensions != null) {
ref.bits |= ASTNode.HasTypeAnnotations;
}
if (this.reportReferenceInfo) {
this.requestor.acceptTypeReference(((ArrayQualifiedTypeReference)ref).tokens, ref.sourceStart, ref.sourceEnd);
}
}
}
}
int levels = ref.getAnnotatableLevels();
for (int i = levels - 1; i >= 0; i--) {
if ((length = this.typeAnnotationLengthStack[this.typeAnnotationLengthPtr--]) != 0) {
if (ref.annotations == null)
ref.annotations = new Annotation[levels][];
System.arraycopy(
this.typeAnnotationStack,
(this.typeAnnotationPtr -= length) + 1,
ref.annotations[i] = new Annotation[length],
0,
length);
if (i == 0) {
ref.sourceStart = ref.annotations[0][0].sourceStart;
}
ref.bits |= ASTNode.HasTypeAnnotations;
}
}
return ref;
}
@Override
public NameReference getUnspecifiedReference(boolean rejectTypeAnnotations) {
if (rejectTypeAnnotations) {
consumeNonTypeUseName();
}
int length;
if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1) {
SingleNameReference ref =
newSingleNameReference(
this.identifierStack[this.identifierPtr],
this.identifierPositionStack[this.identifierPtr--]);
if (this.reportReferenceInfo) {
addUnknownRef(ref);
}
return ref;
} else {
char[][] tokens = new char[length][];
this.identifierPtr -= length;
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
long[] positions = new long[length];
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
QualifiedNameReference ref =
newQualifiedNameReference(
tokens,
positions,
(int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32),
(int) this.identifierPositionStack[this.identifierPtr + length]);
if (this.reportReferenceInfo) {
addUnknownRef(ref);
}
return ref;
}
}
@Override
public NameReference getUnspecifiedReferenceOptimized() {
consumeNonTypeUseName();
int length;
if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1) {
SingleNameReference ref =
newSingleNameReference(
this.identifierStack[this.identifierPtr],
this.identifierPositionStack[this.identifierPtr--]);
ref.bits &= ~ASTNode.RestrictiveFlagMASK;
ref.bits |= Binding.LOCAL | Binding.FIELD;
if (this.reportReferenceInfo) {
addUnknownRef(ref);
}
return ref;
}
char[][] tokens = new char[length][];
this.identifierPtr -= length;
System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length);
long[] positions = new long[length];
System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length);
QualifiedNameReference ref =
newQualifiedNameReference(
tokens,
positions,
(int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32),
(int) this.identifierPositionStack[this.identifierPtr + length]);
ref.bits &= ~ASTNode.RestrictiveFlagMASK;
ref.bits |= Binding.LOCAL | Binding.FIELD;
if (this.reportReferenceInfo) {
addUnknownRef(ref);
}
return ref;
}
protected ImportReference newImportReference(char[][] tokens, long[] positions, boolean onDemand, int mod) {
return new ImportReference(tokens, positions, onDemand, mod);
}
protected QualifiedNameReference newQualifiedNameReference(char[][] tokens, long[] positions, int sourceStart, int sourceEnd) {
return new QualifiedNameReference(tokens, positions, sourceStart, sourceEnd);
}
protected SingleNameReference newSingleNameReference(char[] source, long positions) {
return new SingleNameReference(source, positions);
}
public CompilationUnitDeclaration parseCompilationUnit(
ICompilationUnit unit,
boolean fullParse,
IProgressMonitor pm) {
boolean old = this.diet;
int oldInt = this.dietInt;
CompilationUnitDeclaration parsedUnit = null;
try {
this.diet = true;
this.dietInt = 0;
this.reportReferenceInfo = fullParse;
CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.options.maxProblemsPerUnit);
parsedUnit = parse(unit, compilationUnitResult);
if (pm != null && pm.isCanceled())
throw new OperationCanceledException(Messages.operation_cancelled);
if (this.scanner.recordLineSeparator) {
this.requestor.acceptLineSeparatorPositions(compilationUnitResult.getLineSeparatorPositions());
}
int initialStart = this.scanner.initialPosition;
int initialEnd = this.scanner.eofPosition;
if (this.reportLocalDeclarations || fullParse){
this.diet = false;
getMethodBodies(parsedUnit);
}
this.scanner.resetTo(initialStart, initialEnd);
this.notifier.notifySourceElementRequestor(
parsedUnit,
this.scanner.initialPosition,
this.scanner.eofPosition,
this.reportReferenceInfo,
this.sourceEnds,
this.nodesToCategories);
return parsedUnit;
} catch (AbortCompilation e) {
} finally {
this.diet = old;
this.dietInt = oldInt;
reset();
}
return parsedUnit;
}
private void rememberCategories() {
if (this.useSourceJavadocParser) {
SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
char[][] categories = sourceJavadocParser.categories;
if (categories.length > 0) {
this.nodesToCategories.put(this.astStack[this.astPtr], categories);
sourceJavadocParser.categories = CharOperation.NO_CHAR_CHAR;
}
}
}
private void reset() {
this.sourceEnds = new HashtableOfObjectToInt();
this.nodesToCategories = new HashMap();
}
public void setRequestor(ISourceElementRequestor requestor) {
this.requestor = requestor;
this.notifier.requestor = requestor;
}
}