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

📄 preverificationutils.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 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.core.internal.preverifier;

import eclipseme.preverifier.results.IClassErrorInformation;
import eclipseme.preverifier.results.IFieldErrorInformation;
import eclipseme.preverifier.results.IMethodErrorInformation;
import eclipseme.preverifier.results.PreverificationError;
import eclipseme.preverifier.results.PreverificationErrorLocationType;
import eclipseme.preverifier.results.PreverificationErrorType;

/**
 * Some preverification utility functions until a better place comes
 * along to place them.
 * <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/09/12 00:42:30 $
 * <br>
 * @author Craig Setera
 */
public class PreverificationUtils {
	/**
	 * Return the error text for the specified preverification error.
	 * 
	 * @param error
	 * @return
	 */
	public static String getErrorText(PreverificationError error) {
		StringBuffer errorText = new StringBuffer();
		
		// If details were passed in, we just use that outright
		String detail = error.getDetail();
		if ((detail != null) && (detail.length() > 0)) {
			errorText.append(detail);
		} else {
			appendErrorInformation(errorText, error);
		}
		
		return errorText.toString();
	}

	/**
	 * Append the error information specific to the
	 * preverification error.
	 * 
	 * @param errorText
	 * @param error
	 */
	private static void appendErrorInformation(
		StringBuffer errorText, 
		PreverificationError error) 
	{
		appendErrorTypeInformation(errorText, error);
		
		if (error.getType() != PreverificationErrorType.FINALIZERS) {
			appendErrorLocationInformation(errorText, error);
		}
	}

	/**
	 * Append the error type information to the text.
	 * 
	 * @param errorText
	 * @param error
	 */
	private static void appendErrorLocationInformation(
		StringBuffer errorText, 
		PreverificationError error) 
	{
		IClassErrorInformation classInfo = error.getLocation().getClassInformation();
		IMethodErrorInformation methodInfo = error.getLocation().getMethodInformation();
		IFieldErrorInformation fieldInfo = error.getLocation().getFieldInformation();
		
		switch (error.getLocation().getLocationType().getTypeCode()) {
			case PreverificationErrorLocationType.CLASS_DEFINITION_CODE:
				errorText
					.append(" in class ")
					.append(classInfo.getName())
					.append(" or superclass");
				break;

			case PreverificationErrorLocationType.CLASS_FIELD_CODE:
				errorText
					.append(" for class field ")
					.append(fieldInfo.getName());
				break;

			case PreverificationErrorLocationType.METHOD_SIGNATURE_CODE:
				errorText
					.append(" in method declaration for ")
					.append(methodInfo.getName());
				break;

			case PreverificationErrorLocationType.METHOD_FIELD_CODE:
				errorText
					.append(" in method ")
					.append(methodInfo.getName())
					.append(" of class ")
					.append(classInfo.getName());
				break;

			case PreverificationErrorLocationType.METHOD_INSTRUCTION_CODE:
				errorText
					.append(" in method definition for ")
					.append(methodInfo.getName());
				break;
		}
	}
	
	/**
	 * Append the error type information to the text.
	 * 
	 * @param errorText
	 * @param error
	 */
	private static void appendErrorTypeInformation(
		StringBuffer errorText, 
		PreverificationError error) 
	{
		// No detailed message was provided, so we will build one
		// up
		switch (error.getType().getErrorCode()) {
			case PreverificationErrorType.FINALIZERS_CODE:
				errorText.append("Finalizers not allowed");
				break;
			
			case PreverificationErrorType.FLOATING_POINT_CODE:
				errorText.append("Floating point not allowed");
				break;
				
			case PreverificationErrorType.MISSING_TYPE_CODE:
				errorText.append("Missing type");
				break;
				
			case PreverificationErrorType.NATIVE_CODE:
				errorText.append("Native method implementations not allowed");
				break;
				
			case PreverificationErrorType.UNKNOWN_ERROR_CODE:
				errorText.append("Unknown error during preverification");
				break;
		}
	}
	
	private PreverificationUtils() {
		super();
	}
}

⌨️ 快捷键说明

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