Java Code Examples for org.eclipse.jdt.core.dom.PrimitiveType#toCode()

The following examples show how to use org.eclipse.jdt.core.dom.PrimitiveType#toCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: ChangeTypeAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ParameterGuesser.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: ParameterGuesser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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()]);
}
 
Example 8
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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()]);
}
 
Example 9
Source File: ParameterGuesser.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private boolean isPrimitiveType(String type) {
	return PrimitiveType.toCode(type) != null;
}
 
Example 10
Source File: ParameterGuesser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isPrimitiveType(String type) {
	return PrimitiveType.toCode(type) != null;
}