org.eclipse.jdt.core.dom.PrimitiveType#toCode ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.PrimitiveType#toCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException {
	if (element != null && element.exists()) {
		String type= null;
		if (element instanceof IMethod)
			type= ((IMethod) element).getReturnType();
		else if (element instanceof IField) {
			final IField field= (IField) element;
			if (JdtFlags.isEnum(field))
				return false;
			type= field.getTypeSignature();
		} else if (element instanceof ILocalVariable)
			return true;
		else if (element instanceof IType) {
			final IType clazz= (IType) element;
			if (JdtFlags.isEnum(clazz))
				return false;
			return true;
		}
		if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null)
			return false;
		return true;
	}
	return false;
}
 

public static boolean isGeneralizeTypeAvailable(final IStructuredSelection selection) throws JavaModelException {
	if (selection.size() == 1) {
		final Object element= selection.getFirstElement();
		if (element instanceof IMethod) {
			final IMethod method= (IMethod) element;
			if (!method.exists())
				return false;
			final String type= method.getReturnType();
			if (PrimitiveType.toCode(Signature.toString(type)) == null)
				return Checks.isAvailable(method);
		} else if (element instanceof IField) {
			final IField field= (IField) element;
			if (!field.exists())
				return false;
			if (!JdtFlags.isEnum(field))
				return Checks.isAvailable(field);
		}
	}
	return false;
}
 

private static IMember getMember(IStructuredSelection selection) throws JavaModelException {
	if (selection.size() != 1)
		return null;

	Object element= selection.getFirstElement();
	if (!(element instanceof IMember))
		return null;

	if (element instanceof IMethod) {
		IMethod method= (IMethod)element;
		String returnType= method.getReturnType();
		if (PrimitiveType.toCode(Signature.toString(returnType)) != null)
			return null;
		return method;
	} else if (element instanceof IField && !JdtFlags.isEnum((IMember) element)) {
		return (IField)element;
	}
	return null;
}
 
源代码4 项目: eclipse.jdt.ls   文件: ParameterGuesser.java

private PrimitiveType.Code getPrimitiveTypeCode(String type) {
	PrimitiveType.Code code= PrimitiveType.toCode(type);
	if (code != null) {
		return code;
	}
	if (fEnclosingElement != null && JavaModelUtil.is50OrHigher(fEnclosingElement.getJavaProject())) {
		if (code == PrimitiveType.SHORT) {
			if ("java.lang.Short".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.INT) {
			if ("java.lang.Integer".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.LONG) {
			if ("java.lang.Long".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.FLOAT) {
			if ("java.lang.Float".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.DOUBLE) {
			if ("java.lang.Double".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.CHAR) {
			if ("java.lang.Character".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.BYTE) {
			if ("java.lang.Byte".equals(type)) { //$NON-NLS-1$
				return code;
			}
		}
	}
	return null;
}
 

public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException {
	if (element != null && element.exists()) {
		String type = null;
		if (element instanceof IMethod) {
			type = ((IMethod) element).getReturnType();
		} else if (element instanceof IField) {
			final IField field = (IField) element;
			if (JdtFlags.isEnum(field)) {
				return false;
			}
			type = field.getTypeSignature();
		} else if (element instanceof ILocalVariable) {
			return true;
		} else if (element instanceof IType) {
			final IType clazz = (IType) element;
			if (JdtFlags.isEnum(clazz)) {
				return false;
			}
			return true;
		}
		if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) {
			return false;
		}
		return true;
	}
	return false;
}
 

private PrimitiveType.Code getPrimitiveTypeCode(String type) {
	PrimitiveType.Code code= PrimitiveType.toCode(type);
	if (code != null) {
		return code;
	}
	if (fEnclosingElement != null && JavaModelUtil.is50OrHigher(fEnclosingElement.getJavaProject())) {
		if (code == PrimitiveType.SHORT) {
			if ("java.lang.Short".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.INT) {
			if ("java.lang.Integer".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.LONG) {
			if ("java.lang.Long".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.FLOAT) {
			if ("java.lang.Float".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.DOUBLE) {
			if ("java.lang.Double".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.CHAR) {
			if ("java.lang.Character".equals(type)) { //$NON-NLS-1$
				return code;
			}
		} else if (code == PrimitiveType.BYTE) {
			if ("java.lang.Byte".equals(type)) { //$NON-NLS-1$
				return code;
			}
		}
	}
	return null;
}
 

public static ITypeBinding[] getNarrowingTypes(AST ast, ITypeBinding type) {
	ArrayList<ITypeBinding> res= new ArrayList<ITypeBinding>();
	res.add(type);
	if (type.isPrimitive()) {
		Code code= PrimitiveType.toCode(type.getName());
		for (int i= 0; i < CODE_ORDER.length && code != CODE_ORDER[i]; i++) {
			String typeName= CODE_ORDER[i].toString();
			res.add(ast.resolveWellKnownType(typeName));
		}
	}
	return res.toArray(new ITypeBinding[res.size()]);
}
 

public static ITypeBinding[] getRelaxingTypes(AST ast, ITypeBinding type) {
	ArrayList<ITypeBinding> res= new ArrayList<ITypeBinding>();
	res.add(type);
	if (type.isArray()) {
		res.add(ast.resolveWellKnownType("java.lang.Object")); //$NON-NLS-1$
		// The following two types are not available in some j2me implementations, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=288060 :
		ITypeBinding serializable= ast.resolveWellKnownType("java.io.Serializable"); //$NON-NLS-1$
		if (serializable != null)
			res.add(serializable);
		ITypeBinding cloneable= ast.resolveWellKnownType("java.lang.Cloneable"); //$NON-NLS-1$
		if (cloneable != null)
			res.add(cloneable);
	} else if (type.isPrimitive()) {
		Code code= PrimitiveType.toCode(type.getName());
		boolean found= false;
		for (int i= 0; i < CODE_ORDER.length; i++) {
			if (found) {
				String typeName= CODE_ORDER[i].toString();
				res.add(ast.resolveWellKnownType(typeName));
			}
			if (code == CODE_ORDER[i]) {
				found= true;
			}
		}
	} else {
		collectRelaxingTypes(res, type);
	}
	return res.toArray(new ITypeBinding[res.size()]);
}
 
源代码9 项目: eclipse.jdt.ls   文件: ParameterGuesser.java

private boolean isPrimitiveType(String type) {
	return PrimitiveType.toCode(type) != null;
}
 

private boolean isPrimitiveType(String type) {
	return PrimitiveType.toCode(type) != null;
}
 
 同类方法