*
* @return the normal formal parameter that was parsed
*/
protected NormalFormalParameter parseNormalFormalParameter() {
CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
FinalConstVarOrType holder = parseFinalConstVarOrType(true);
Token thisKeyword = null;
Token period = null;
if (matchesKeyword(Keyword.THIS)) {
thisKeyword = getAndAdvance();
period = expect(TokenType.PERIOD);
}
SimpleIdentifier identifier = parseSimpleIdentifier();
if (matches(TokenType.OPEN_PAREN)) {
FormalParameterList parameters = parseFormalParameterList();
if (thisKeyword == null) {
if (holder.getKeyword() != null) {
reportErrorForToken(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.getKeyword());
}
return new FunctionTypedFormalParameter(
commentAndMetadata.getComment(),
commentAndMetadata.getMetadata(),
holder.getType(),
identifier,
parameters);
} else {
return new FieldFormalParameter(
commentAndMetadata.getComment(),
commentAndMetadata.getMetadata(),
holder.getKeyword(),
holder.getType(),
thisKeyword,
period,
identifier,
parameters);
}
}
TypeName type = holder.getType();
if (type != null) {
if (tokenMatchesKeyword(type.getName().getBeginToken(), Keyword.VOID)) {
reportErrorForToken(ParserErrorCode.VOID_PARAMETER, type.getName().getBeginToken());
} else if (holder.getKeyword() != null
&& tokenMatchesKeyword(holder.getKeyword(), Keyword.VAR)) {
reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.getKeyword());
}
}
if (thisKeyword != null) {
return new FieldFormalParameter(
commentAndMetadata.getComment(),
commentAndMetadata.getMetadata(),
holder.getKeyword(),
holder.getType(),
thisKeyword,
period,
identifier,
null);
}
return new SimpleFormalParameter(
commentAndMetadata.getComment(),
commentAndMetadata.getMetadata(),
holder.getKeyword(),
holder.getType(),
identifier);
}