Search through include files for a class declaration (incomplete, problems with recus...
authoraxelcl <axelcl>
Mon, 30 Jan 2006 21:18:58 +0000 (21:18 +0000)
committeraxelcl <axelcl>
Mon, 30 Jan 2006 21:18:58 +0000 (21:18 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/ParserUtil.java [new file with mode: 0644]

diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/ParserUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/ParserUtil.java
new file mode 100644 (file)
index 0000000..5e7a44e
--- /dev/null
@@ -0,0 +1,45 @@
+package net.sourceforge.phpdt.internal.compiler.parser;
+
+import java.util.List;
+
+import net.sourceforge.phpdt.core.ICompilationUnit;
+import net.sourceforge.phpdt.core.IType;
+import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.core.JavaModelException;
+import net.sourceforge.phpdt.internal.compiler.ast.ImportReference;
+import net.sourceforge.phpdt.internal.compiler.ast.SingleTypeReference;
+
+import org.eclipse.core.resources.IFile;
+
+public class ParserUtil {
+
+       public static SingleTypeReference getTypeReference(Scanner scanner, List includesList, char[] ident) {
+               String identStr = new String(ident);
+               ImportReference ir;
+               IFile file = null;
+               for (int i = 0; i < includesList.size(); i++) {
+                       ir = (ImportReference) includesList.get(i);
+                       file = ir.getFile();
+                       if (file != null) {
+                               ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
+                               if (unit != null) {
+                                       try {
+                                               // TODO avoid recursion here. Sometimes we get a java.lang.StackOverflowError
+                                               IType[] types = unit.getAllTypes();
+                                               if (types != null) {
+                                                       for (int j = 0; j < types.length; j++) {
+                                                               if (types[j].getElementName().equals(identStr)) {
+                                                                       return new SingleTypeReference(file, ident, scanner.getCurrentTokenStartPosition(), scanner
+                                                                                       .getCurrentTokenEndPosition());
+                                                               }
+                                                       }
+                                               }
+                                       } catch (JavaModelException e) {
+                                               e.printStackTrace();
+                                       }
+                               }
+                       }
+               }
+               return null;
+       }
+}