fixed https://sourceforge.net/tracker/index.php?func=detail&aid=1431163&group_id...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / UninitializedVariableHandler.java
1 package net.sourceforge.phpdt.internal.compiler.parser;
2
3 import java.util.ArrayList;
4
5 public class UninitializedVariableHandler {
6
7         private class Function {
8                 private int count;
9                 private String name;
10
11                 public Function(String name, int count) {
12                         this.name=name;
13                         this.count=count;
14                 }
15         }
16
17         private String functionName=null;
18         private int argumentCount=0;
19         private ArrayList functions=new ArrayList();
20
21         public UninitializedVariableHandler() {
22                 add("ereg",3);
23                 add("eregi",3);
24                 add("fsockopen",3);
25                 add("preg_match",3);
26                 add("preg_match_all",3);
27                 add("preg_replace",5);
28                 add("preg_replace_callback",5);
29         }
30
31         private void add(String name, int countFrom) {
32                 functions.add(new Function(name,countFrom));
33         }
34
35         protected boolean reportError() {
36                 if (functionName!=null) {
37                         for (int i=0; i<functions.size();i++) {
38                                 Function function=(Function) functions.get(i);
39                                 if (functionName.equalsIgnoreCase(function.name) && argumentCount>=function.count) {
40                                         return false;
41                                 }
42                         }
43                 }
44                 return true;
45         }
46
47         public void setFunctionName(String functionName) {
48                 this.functionName=functionName;
49         }
50
51         public void incrementArgumentCount() {
52                 argumentCount++;
53         }
54 }