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.2 2004/02/27 17:25:25 cell
11 * Fix NPE for files without an extension
13 * Revision 1.1 2004/02/26 02:25:42 agfitzp
14 * renamed packages to match xml & css
16 * Revision 1.1 2004/02/05 03:10:08 agfitzp
19 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
20 * Experimental work for Classes view
21 * Revision 1.3 2003/05/30 20:53:08 agfitzp
22 * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
24 * Revision 1.2 2003/05/28 20:47:56 agfitzp Outline the document, not the file.
26 * Revision 1.1 2003/05/28 15:17:11 agfitzp net.sourceforge.phpeclipse.js.core 0.0.1 code
29 * ========================================================================
32 package net.sourceforge.phpeclipse.js.core.parser;
34 import java.util.LinkedList;
35 import java.util.List;
37 import org.eclipse.core.resources.IContainer;
38 import org.eclipse.core.resources.IFile;
39 import org.eclipse.core.resources.IFolder;
40 import org.eclipse.core.resources.IProject;
41 import org.eclipse.core.resources.IResource;
42 import org.eclipse.core.runtime.CoreException;
43 import org.eclipse.jface.text.IDocument;
45 import net.sourceforge.phpeclipse.js.core.model.*;
50 public class JSSyntaxModelFactory {
51 private static JSSyntaxModelFactory instance = new JSSyntaxModelFactory();
54 * Creates a new JSSyntaxModelFactory.
56 private JSSyntaxModelFactory() {
63 public JSElementList getContentOutline(IProject aProject) {
64 return new JSElementList(getSyntacticElements(aProject));
72 public JSElementList getContentOutline(IFile adaptable) {
73 return new JSElementList(getSyntacticElements(adaptable));
81 public JSElementList getContentOutline(IDocument document) {
82 return new JSElementList(getSyntacticElements(document));
86 * Returns the singleton.
90 public static JSSyntaxModelFactory getInstance() {
99 private List getSyntacticElements(IProject aProject) {
101 JSParser aParser = new JSParser();
102 Object[] jsFiles = getJSFilesFor(aProject);
104 for (i = 0; i < jsFiles.length; i++) {
105 aParser.parse((IFile) jsFiles[i]);
107 return aParser.getElementList();
114 private Object[] getJSFilesFor(IProject project) {
115 LinkedList files = new LinkedList();
116 collectJSFiles(project, files);
117 return files.toArray();
120 private void collectJSFiles(IContainer aContainer, LinkedList files) {
123 IResource[] members = aContainer.members();
124 for (i = 0; i < members.length; i++) {
125 IResource aResource = members[i];
126 if (aResource.getType() == IResource.FILE) {
127 IFile aFile = (IFile) aResource;
128 String ext = aFile.getFileExtension();
129 if ((ext != null) && ext.equals("js")) {
132 } else if (aResource.getType() == IResource.FOLDER) {
133 collectJSFiles((IFolder) aResource, files);
136 } catch (CoreException e) {
145 private List getSyntacticElements(IFile file) {
146 return (new JSParser()).parse(file);
154 private List getSyntacticElements(IDocument document) {
155 return (new JSParser()).parse(document);