RC2 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / JavaModelInfo.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.IJavaModel;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.ResourcesPlugin;
17
18 /**
19  * Implementation of IJavaModel. A Java Model is specific to a
20  * workspace.
21  *
22  * @see IJavaModel
23  */
24 public class JavaModelInfo extends OpenableElementInfo {
25
26         /**
27          * A array with all the non-java projects contained by this model
28          */
29         Object[] nonJavaResources;
30
31 /**
32  * Constructs a new Java Model Info 
33  */
34 protected JavaModelInfo() {
35 }
36 /**
37  * Compute the non-java resources contained in this java project.
38  */
39 private Object[] computeNonJavaResources() {
40         IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
41         int length = projects.length;
42         Object[] nonJavaResources = null;
43         int index = 0;
44         for (int i = 0; i < length; i++) {
45                 IProject project = projects[i];
46                 if (!JavaProject.hasJavaNature(project)) {
47                         if (nonJavaResources == null) {
48                                 nonJavaResources = new Object[length];
49                         }
50                         nonJavaResources[index++] = project;
51                 }
52         }
53         if (index == 0) return NO_NON_JAVA_RESOURCES;
54         if (index < length) {
55                 System.arraycopy(nonJavaResources, 0, nonJavaResources = new Object[index], 0, index);
56         }
57         return nonJavaResources;
58 }
59
60 /**
61  * Returns an array of non-java resources contained in the receiver.
62  */
63 Object[] getNonJavaResources() {
64
65         Object[] nonJavaResources = this.nonJavaResources;
66         if (nonJavaResources == null) {
67                 nonJavaResources = computeNonJavaResources();
68                 this.nonJavaResources = nonJavaResources;
69         }
70         return nonJavaResources;
71 }
72 }