Fixed: 1760857 - Avoid refreshing the preview when phpeditor got focus.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / ParserUtil.java
1 package net.sourceforge.phpdt.internal.compiler.parser;
2
3 import java.util.List;
4
5 import net.sourceforge.phpdt.core.ICompilationUnit;
6 import net.sourceforge.phpdt.core.IType;
7 import net.sourceforge.phpdt.core.JavaCore;
8 import net.sourceforge.phpdt.core.JavaModelException;
9 import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
10 import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
11
12 import org.eclipse.core.resources.IFile;
13
14 public class ParserUtil {
15
16         public static SingleTypeReference getTypeReference(Scanner scanner,
17                         List includesList, char[] ident) {
18                 String identStr = new String(ident);
19                 ImportReference ir;
20                 IFile file = null;
21                 for (int i = 0; i < includesList.size(); i++) {
22                         ir = (ImportReference) includesList.get(i);
23                         file = ir.getFile();
24                         if (file != null) {
25                                 ICompilationUnit unit = JavaCore
26                                                 .createCompilationUnitFrom(file);
27                                 if (unit != null) {
28                                         try {
29                                                 // TODO avoid recursion here. Sometimes we get a
30                                                 // java.lang.StackOverflowError
31                                                 IType[] types = unit.getAllTypes();
32                                                 if (types != null) {
33                                                         for (int j = 0; j < types.length; j++) {
34                                                                 if (types[j].getElementName().equals(identStr)) {
35                                                                         return new SingleTypeReference(
36                                                                                         file,
37                                                                                         ident,
38                                                                                         scanner
39                                                                                                         .getCurrentTokenStartPosition(),
40                                                                                         scanner
41                                                                                                         .getCurrentTokenEndPosition());
42                                                                 }
43                                                         }
44                                                 }
45                                         } catch (JavaModelException e) {
46                                                 e.printStackTrace();
47                                         }
48                                 }
49                         }
50                 }
51                 return null;
52         }
53 }