1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
14 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
15 import net.sourceforge.phpdt.internal.compiler.lookup.ClassScope;
16 import net.sourceforge.phpdt.internal.compiler.parser.Parser;
17 import net.sourceforge.phpdt.internal.compiler.util.CharOperation;
19 public class MethodDeclaration extends AbstractMethodDeclaration {
21 public TypeReference returnType;
24 * MethodDeclaration constructor comment.
26 public MethodDeclaration(CompilationResult compilationResult) {
27 super(compilationResult);
31 public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
33 //fill up the method body with statement
34 if (ignoreFurtherInvestigation)
36 parser.parse(this, unit);
39 public void resolveStatements(ClassScope upperScope) {
41 // ========= abort on fatal error =============
42 if (this.returnType != null && this.binding != null) {
43 this.returnType.binding = this.binding.returnType;
44 // record the return type binding
46 // look if the name of the method is correct
47 if (binding != null && isTypeUseDeprecated(binding.returnType, scope))
48 scope.problemReporter().deprecatedType(binding.returnType, returnType);
50 if (CharOperation.equals(scope.enclosingSourceType().sourceName, selector))
51 scope.problemReporter().methodWithConstructorName(this);
53 // by grammatical construction, interface methods are always abstract
54 if (!scope.enclosingSourceType().isInterface()){
56 // if a method has an semicolon body and is not declared as abstract==>error
57 // native methods may have a semicolon body
58 if ((modifiers & AccSemicolonBody) != 0) {
59 if ((modifiers & AccNative) == 0)
60 if ((modifiers & AccAbstract) == 0)
61 scope.problemReporter().methodNeedingAbstractModifier(this);
63 // the method HAS a body --> abstract native modifiers are forbiden
64 if (((modifiers & AccNative) != 0) || ((modifiers & AccAbstract) != 0))
65 scope.problemReporter().methodNeedingNoBody(this);
68 super.resolveStatements(upperScope);
71 public String returnTypeToString(int tab) {
73 if (returnType == null)
74 return ""; //$NON-NLS-1$
75 return returnType.toString(tab) + " "; //$NON-NLS-1$
79 IAbstractSyntaxTreeVisitor visitor,
80 ClassScope classScope) {
82 if (visitor.visit(this, classScope)) {
83 if (returnType != null)
84 returnType.traverse(visitor, scope);
85 if (arguments != null) {
86 int argumentLength = arguments.length;
87 for (int i = 0; i < argumentLength; i++)
88 arguments[i].traverse(visitor, scope);
90 if (thrownExceptions != null) {
91 int thrownExceptionsLength = thrownExceptions.length;
92 for (int i = 0; i < thrownExceptionsLength; i++)
93 thrownExceptions[i].traverse(visitor, scope);
95 if (statements != null) {
96 int statementsLength = statements.length;
97 for (int i = 0; i < statementsLength; i++)
98 statements[i].traverse(visitor, scope);
101 visitor.endVisit(this, classScope);