📄 midletpropertytester.java
字号:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.ui.internal;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.utils.Utils;
/**
* A property tester implementation for querying properties of a Midlet
* class resource.
* <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.2 $
* <br>
* $Date: 2005/07/07 02:36:26 $
* <br>
* @author Craig Setera
*/
public class MidletPropertyTester extends PropertyTester {
private static final String PROPERTY_IS_MIDLET = "isMidlet";
/**
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
*/
public boolean test(
Object receiver,
String property,
Object[] args,
Object expectedValue)
{
boolean returnValue = false;
if (PROPERTY_IS_MIDLET.equals(property)) {
try {
if (receiver instanceof IResource) {
returnValue = isMidlet((IResource) receiver);
} else if (receiver instanceof IJavaElement) {
returnValue = isMidlet((IJavaElement) receiver);
}
} catch (JavaModelException e) {
EclipseMECorePlugin.log(IStatus.WARNING, e);
}
}
return returnValue;
}
/**
* Return a boolean indicating whether the specified resource
* is a midlet class.
*
* @param resource
* @return
* @throws JavaModelException
*/
private boolean isMidlet(IResource resource)
throws JavaModelException
{
return isMidlet(JavaCore.create(resource));
}
/**
* Return a boolean indicating whether the specified resource
* is a midlet class.
*
* @param javaElement
* @return
* @throws JavaModelException
*/
private boolean isMidlet(IJavaElement javaElement)
throws JavaModelException
{
boolean isMidlet = false;
IType type = null;
if (javaElement != null) {
switch (javaElement.getElementType()) {
case IJavaElement.CLASS_FILE:
type = ((IClassFile) javaElement).getType();
break;
case IJavaElement.COMPILATION_UNIT:
type = ((ICompilationUnit) javaElement).findPrimaryType();
break;
case IJavaElement.TYPE:
type = (IType) javaElement;
break;
}
isMidlet = Utils.isMidlet(type, new NullProgressMonitor());
}
return isMidlet;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -