Some javadoc added
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / MethodDeclaration.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
14 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
15 import net.sourceforge.phpdt.internal.compiler.lookup.*;
16 import net.sourceforge.phpdt.internal.compiler.parser.*;
17 import net.sourceforge.phpdt.internal.compiler.util.*;
18
19 public class MethodDeclaration extends AbstractMethodDeclaration {
20         
21         public TypeReference returnType;
22
23         /**
24          * MethodDeclaration constructor comment.
25          */
26         public MethodDeclaration(CompilationResult compilationResult) {
27                 super(compilationResult);
28         }
29
30
31         public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
32
33                 //fill up the method body with statement
34                 if (ignoreFurtherInvestigation)
35                         return;
36                 parser.parse(this, unit);
37         }
38
39         public void resolveStatements(ClassScope upperScope) {
40
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
45                 }
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);
49
50                 if (CharOperation.equals(scope.enclosingSourceType().sourceName, selector))
51                         scope.problemReporter().methodWithConstructorName(this);
52
53                 // by grammatical construction, interface methods are always abstract
54                 if (!scope.enclosingSourceType().isInterface()){
55
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);
62                         } else {
63                                 // the method HAS a body --> abstract native modifiers are forbiden
64                                 if (((modifiers & AccNative) != 0) || ((modifiers & AccAbstract) != 0))
65                                         scope.problemReporter().methodNeedingNoBody(this);
66                         }
67                 }
68                 super.resolveStatements(upperScope); 
69         }
70
71         public String returnTypeToString(int tab) {
72
73                 if (returnType == null)
74                         return ""; //$NON-NLS-1$
75                 return returnType.toString(tab) + " "; //$NON-NLS-1$
76         }
77
78         public void traverse(
79                 IAbstractSyntaxTreeVisitor visitor,
80                 ClassScope classScope) {
81
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);
89                         }
90                         if (thrownExceptions != null) {
91                                 int thrownExceptionsLength = thrownExceptions.length;
92                                 for (int i = 0; i < thrownExceptionsLength; i++)
93                                         thrownExceptions[i].traverse(visitor, scope);
94                         }
95                         if (statements != null) {
96                                 int statementsLength = statements.length;
97                                 for (int i = 0; i < statementsLength; i++)
98                                         statements[i].traverse(visitor, scope);
99                         }
100                 }
101                 visitor.endVisit(this, classScope);
102         }
103 }