⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 j2meclasspathcontainer.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
package eclipseme.core.internal;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;

import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.MidletSuiteFactory;
import eclipseme.core.model.device.IDevice;

/**
 * A classpath container implementation that reflects the classpath
 * provided by the platform definition currently associated with
 * an IJavaProject.
 * <p>
 * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
 * change before reaching stability. It is being made available at this early stage to solicit feedback
 * from pioneering adopters on the understanding that any code that uses this API will almost 
 * certainly be broken as the API evolves.
 * </p>
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.5 $
 * <br>
 * $Date: 2006/02/11 21:26:57 $
 * <br>
 * @author Yang Liu
 * @author Craig Setera
 */

public class J2MEClasspathContainer implements IClasspathContainer {
	/** Name of the J2ME Classpath Container */
	public static final String J2ME_CONTAINER = "J2MELIB";

	// The classpath container path and project
	private IJavaProject project;
	private IPath path;

	// The description of this classpath container.
	private String description;

	// The classpath entries cache.
	private IClasspathEntry[] cachedEntries;

	/**
	 * Construct a new classpath container for the specified project.  
	 * 
	 * @param project
	 * @param path
	 * @throws CoreException
	 */
	public J2MEClasspathContainer(IJavaProject project, IPath path)
			throws CoreException 
	{
		this.project = project;
		this.path = path;
	}

	/**
	 * @see org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries()
	 */
	public IClasspathEntry[] getClasspathEntries() {
		if (cachedEntries == null) {
			IDevice device = getProjectDevice(project);

			if (device != null) {
				// Stash the classpath entries specified by the device
				cachedEntries = device.getClasspath().asClasspathEntries();
			} else {
				cachedEntries = new IClasspathEntry[0];
			}
		}
		
		return cachedEntries;
	}

	/**
	 * @see org.eclipse.jdt.core.IClasspathContainer#getDescription()
	 */
	public String getDescription() {
		if (description == null) {
			this.description = "J2ME library (failed to get library information)";

			IDevice device = getProjectDevice(project);
			if (device != null) {
				// Stash the description
				StringBuffer sb = new StringBuffer();
				sb
					.append("J2ME library [ ")
					.append(device.getGroupName())
					.append("/")
					.append(device.getName())
					.append(" ]");
				this.description = sb.toString(); 				
			}
		}

		return description;
	}

	/**
	 * @see org.eclipse.jdt.core.IClasspathContainer#getKind()
	 */
	public int getKind() {
		return K_APPLICATION;
	}

	/**
	 * @see org.eclipse.jdt.core.IClasspathContainer#getPath()
	 */
	public IPath getPath() {
		return path;
	}
	
	/**
	 * Return the device for the specified project or <code>null</code>
	 * if the project cannot be determined.
	 * 
	 * @param project
	 * @return
	 */
	private IDevice getProjectDevice(IJavaProject project) {
		IDevice device = null;

		IMidletSuiteProject midletSuite = MidletSuiteFactory.getMidletSuiteProject(project);
		if (midletSuite != null) {
			device = midletSuite.getDevice();
		}
		
		return device;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -