2 * $RCSfile: JSSyntaxModelFactory.java,v $
4 * Copyright 2002 CH-1700 Fribourg, Switzerland All rights reserved.
6 * ========================================================================
7 * Modifications history
8 * ========================================================================
9 * $Log: not supported by cvs2svn $
10 * Revision 1.1 2004/09/02 18:14:38 jsurfer
11 * intial source from ttp://www.sf.net/projects/wdte
13 * Revision 1.2 2004/02/27 17:25:25 cell
14 * Fix NPE for files without an extension
16 * Revision 1.1 2004/02/26 02:25:42 agfitzp
17 * renamed packages to match xml & css
19 * Revision 1.1 2004/02/05 03:10:08 agfitzp
22 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
23 * Experimental work for Classes view
24 * Revision 1.3 2003/05/30 20:53:08 agfitzp
25 * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
27 * Revision 1.2 2003/05/28 20:47:56 agfitzp Outline the document, not the file.
29 * Revision 1.1 2003/05/28 15:17:11 agfitzp net.sourceforge.phpeclipse.js.core 0.0.1 code
32 * ========================================================================
35 package net.sourceforge.phpeclipse.js.core.parser;
37 import java.util.LinkedList;
38 import java.util.List;
40 import net.sourceforge.phpeclipse.js.core.model.JSElementList;
42 import org.eclipse.core.resources.IContainer;
43 import org.eclipse.core.resources.IFile;
44 import org.eclipse.core.resources.IFolder;
45 import org.eclipse.core.resources.IProject;
46 import org.eclipse.core.resources.IResource;
47 import org.eclipse.core.runtime.CoreException;
48 import org.eclipse.jface.text.IDocument;
53 public class JSSyntaxModelFactory {
54 private static JSSyntaxModelFactory instance = new JSSyntaxModelFactory();
57 * Creates a new JSSyntaxModelFactory.
59 private JSSyntaxModelFactory() {
66 public JSElementList getContentOutline(IProject aProject) {
67 return new JSElementList(getSyntacticElements(aProject));
75 public JSElementList getContentOutline(IFile adaptable) {
76 return new JSElementList(getSyntacticElements(adaptable));
84 public JSElementList getContentOutline(IDocument document) {
85 return new JSElementList(getSyntacticElements(document));
89 * Returns the singleton.
93 public static JSSyntaxModelFactory getInstance() {
102 private List getSyntacticElements(IProject aProject) {
104 JSParser aParser = new JSParser();
105 Object[] jsFiles = getJSFilesFor(aProject);
107 for (i = 0; i < jsFiles.length; i++) {
108 aParser.parse((IFile) jsFiles[i]);
110 return aParser.getElementList();
117 private Object[] getJSFilesFor(IProject project) {
118 LinkedList files = new LinkedList();
119 collectJSFiles(project, files);
120 return files.toArray();
123 private void collectJSFiles(IContainer aContainer, LinkedList files) {
126 IResource[] members = aContainer.members();
127 for (i = 0; i < members.length; i++) {
128 IResource aResource = members[i];
129 if (aResource.getType() == IResource.FILE) {
130 IFile aFile = (IFile) aResource;
131 String ext = aFile.getFileExtension();
132 if ((ext != null) && ext.equals("js")) {
135 } else if (aResource.getType() == IResource.FOLDER) {
136 collectJSFiles((IFolder) aResource, files);
139 } catch (CoreException e) {
148 private List getSyntacticElements(IFile file) {
149 return (new JSParser()).parse(file);
157 private List getSyntacticElements(IDocument document) {
158 return (new JSParser()).parse(document);