List of usage examples for org.eclipse.jdt.core.dom PrimitiveType SHORT
Code SHORT
To view the source code for org.eclipse.jdt.core.dom PrimitiveType SHORT.
Click Source Link
From source file:de.crowdcode.kissmda.core.jdt.DataTypeUtils.java
License:Apache License
private void createPrimitiveTypeCodes() { primitiveTypeCodes = new HashMap<String, Code>(); primitiveTypeCodes.put("integer", PrimitiveType.INT); primitiveTypeCodes.put("int", PrimitiveType.INT); primitiveTypeCodes.put("short", PrimitiveType.SHORT); primitiveTypeCodes.put("double", PrimitiveType.DOUBLE); primitiveTypeCodes.put("long", PrimitiveType.LONG); primitiveTypeCodes.put("boolean", PrimitiveType.BOOLEAN); primitiveTypeCodes.put("byte", PrimitiveType.BYTE); primitiveTypeCodes.put("character", PrimitiveType.CHAR); primitiveTypeCodes.put("char", PrimitiveType.CHAR); primitiveTypeCodes.put("float", PrimitiveType.FLOAT); primitiveTypeCodes.put("void", PrimitiveType.VOID); // Publish an event to the bus eventBus.post(new PrimitiveTypeCodesCreatedEvent(primitiveTypeCodes)); }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelperTest.java
License:Apache License
private Map<String, Code> createPrimitiveTypeCodes() { Map<String, Code> primitiveTypeCodes = new HashMap<String, Code>(); primitiveTypeCodes.put("integer", PrimitiveType.INT); primitiveTypeCodes.put("short", PrimitiveType.SHORT); primitiveTypeCodes.put("byte", PrimitiveType.BYTE); primitiveTypeCodes.put("boolean", PrimitiveType.BOOLEAN); return primitiveTypeCodes; }
From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java
License:Open Source License
public boolean visit(PrimitiveType node) { IValue type;/* ww w . j a va2 s .co m*/ if (node.getPrimitiveTypeCode().equals(PrimitiveType.BOOLEAN)) { type = values.constructor(Java.CONS_BOOLEAN); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.BYTE)) { type = values.constructor(Java.CONS_BYTE); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.CHAR)) { type = values.constructor(Java.CONS_CHAR); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.DOUBLE)) { type = values.constructor(Java.CONS_DOUBLE); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.FLOAT)) { type = values.constructor(Java.CONS_FLOAT); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.INT)) { type = values.constructor(Java.CONS_INT); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.LONG)) { type = values.constructor(Java.CONS_LONG); } else if (node.getPrimitiveTypeCode().equals(PrimitiveType.SHORT)) { type = values.constructor(Java.CONS_SHORT); } else { type = values.constructor(Java.CONS_VOID); } ownValue = constructRascalNode(node, type); return false; }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
public boolean visit(CastExpression node) { Type type = node.getType();/* w ww . j av a 2 s. c om*/ /* * TODO: some casting should have its meaning! * int to byte, int to short, long to int will lost values */ Expression expression = node.getExpression(); if (type.isPrimitiveType()) { ITypeBinding resolveTypeBinding = expression.resolveTypeBinding(); if (resolveTypeBinding != null) { String name = resolveTypeBinding.getName(); PrimitiveType pType = (PrimitiveType) type; if (pType.getPrimitiveTypeCode() == PrimitiveType.INT || pType.getPrimitiveTypeCode() == PrimitiveType.BYTE || pType.getPrimitiveTypeCode() == PrimitiveType.SHORT || pType.getPrimitiveTypeCode() == PrimitiveType.LONG) { if ("char".equals(name)) { buffer.append("("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(").charCodeAt (0)"); return false; } else if ("float".equals(name) || "double".equals(name)) { //buffer.append("Math.round ("); buffer.append("Clazz."); buffer.append(name); buffer.append("To"); String targetType = pType.getPrimitiveTypeCode().toString(); buffer.append(targetType.substring(0, 1).toUpperCase()); buffer.append(targetType.substring(1)); buffer.append(" ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(")"); return false; } } if (pType.getPrimitiveTypeCode() == PrimitiveType.CHAR) { if ("char".equals(name)) { // buffer.append("("); // node.getExpression().accept(this); // buffer.append (").charCodeAt (0)"); // return false; } else if ("float".equals(name) || "double".equals(name)) { // TODO: buffer.append("Clazz."); buffer.append(name); buffer.append("ToChar ("); // buffer.append("String.fromCharCode ("); // buffer.append("Math.round ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } // buffer.append (")"); buffer.append(")"); return false; } else if ("int".equals(name) || "byte".equals(name) // || "double".equals(name) || "float".equals(name) || "short".equals(name) || "long".equals(name)) { Object constantValue = expression.resolveConstantExpressionValue(); if (constantValue != null) { if (constantValue instanceof Integer) { int value = ((Integer) constantValue).intValue(); if ((value >= '0' && value <= '9') || (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z')) { buffer.append('\''); buffer.append((char) value); buffer.append('\''); return false; } } else if (constantValue instanceof Long) { long value = ((Long) constantValue).longValue(); if ((value >= '0' && value <= '9') || (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z')) { buffer.append('\''); buffer.append((char) value); buffer.append('\''); return false; } } } buffer.append("String.fromCharCode ("); if (expression instanceof ParenthesizedExpression) { ParenthesizedExpression pe = (ParenthesizedExpression) expression; pe.getExpression().accept(this); } else { expression.accept(this); } buffer.append(")"); return false; } } } } expression.accept(this); return false; }
From source file:net.sf.j2s.core.astvisitors.ASTScriptVisitor.java
License:Open Source License
private String prepareSimpleSerializable(TypeDeclaration node, List bodyDeclarations) { StringBuffer fieldsSerializables = new StringBuffer(); ITypeBinding binding = node.resolveBinding(); boolean isSimpleSerializable = binding != null && (Bindings.findTypeInHierarchy(binding, "net.sf.j2s.ajax.SimpleSerializable") != null); for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) { ASTNode element = (ASTNode) iter.next(); if (element instanceof FieldDeclaration) { if (node.isInterface()) { /*/*from w ww . j ava 2s .c om*/ * As members of interface should be treated * as final and for javascript interface won't * get instantiated, so the member will be * treated specially. */ continue; } FieldDeclaration fieldDeclaration = (FieldDeclaration) element; if (isSimpleSerializable) { List fragments = fieldDeclaration.fragments(); int modifiers = fieldDeclaration.getModifiers(); if ((Modifier.isPublic(modifiers)/* || Modifier.isProtected(modifiers)*/) && !Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { Type type = fieldDeclaration.getType(); int dims = 0; if (type.isArrayType()) { dims = 1; type = ((ArrayType) type).getComponentType(); } String mark = null; if (type.isPrimitiveType()) { PrimitiveType pType = (PrimitiveType) type; Code code = pType.getPrimitiveTypeCode(); if (code == PrimitiveType.FLOAT) { mark = "F"; } else if (code == PrimitiveType.DOUBLE) { mark = "D"; } else if (code == PrimitiveType.INT) { mark = "I"; } else if (code == PrimitiveType.LONG) { mark = "L"; } else if (code == PrimitiveType.SHORT) { mark = "S"; } else if (code == PrimitiveType.BYTE) { mark = "B"; } else if (code == PrimitiveType.CHAR) { mark = "C"; } else if (code == PrimitiveType.BOOLEAN) { mark = "b"; } } ITypeBinding resolveBinding = type.resolveBinding(); if ("java.lang.String".equals(resolveBinding.getQualifiedName())) { mark = "s"; } else { ITypeBinding t = resolveBinding; do { String typeName = t.getQualifiedName(); if ("java.lang.Object".equals(typeName)) { break; } if ("net.sf.j2s.ajax.SimpleSerializable".equals(typeName)) { mark = "O"; break; } t = t.getSuperclass(); if (t == null) { break; } } while (true); } if (mark != null) { for (Iterator xiter = fragments.iterator(); xiter.hasNext();) { VariableDeclarationFragment var = (VariableDeclarationFragment) xiter.next(); int curDim = dims + var.getExtraDimensions(); if (curDim <= 1) { if (fieldsSerializables.length() > 0) { fieldsSerializables.append(", "); } /* * Fixed bug for the following scenario: * class NT extends ... { * public boolean typing; * public void typing() { * } * } */ String fieldName = var.getName().toString(); if (checkKeyworkViolation(fieldName)) { fieldName = "$" + fieldName; } String prefix = null; if (binding != null && checkSameName(binding, fieldName)) { prefix = "$"; } if (binding != null && isInheritedFieldName(binding, fieldName)) { fieldName = getFieldName(binding, fieldName); } if (prefix != null) { fieldName = prefix + fieldName; } fieldsSerializables.append("\"" + fieldName + "\", \""); if (mark.charAt(0) == 's' && curDim == 1) { fieldsSerializables.append("AX"); } else if (curDim == 1) { fieldsSerializables.append("A"); fieldsSerializables.append(mark); } else { fieldsSerializables.append(mark); } fieldsSerializables.append("\""); } } } } } } } return fieldsSerializables.toString(); }
From source file:net.sf.j2s.core.astvisitors.ASTTigerVisitor.java
License:Open Source License
protected void boxingNode(ASTNode element) { if (element instanceof Expression) { Expression exp = (Expression) element; if (exp.resolveBoxing()) { ITypeBinding typeBinding = exp.resolveTypeBinding(); if (typeBinding.isPrimitive()) { String name = typeBinding.getName(); Code type = PrimitiveType.toCode(name); String primitiveTypeName = null; if (type == PrimitiveType.INT) { primitiveTypeName = "Integer"; } else if (type == PrimitiveType.LONG) { primitiveTypeName = "Long"; } else if (type == PrimitiveType.FLOAT) { primitiveTypeName = "Float"; } else if (type == PrimitiveType.DOUBLE) { primitiveTypeName = "Double"; } else if (type == PrimitiveType.BOOLEAN) { primitiveTypeName = "Boolean"; } else if (type == PrimitiveType.BYTE) { primitiveTypeName = "Byte"; } else if (type == PrimitiveType.SHORT) { primitiveTypeName = "Short"; } else if (type == PrimitiveType.CHAR) { primitiveTypeName = "Character"; }// w ww . ja v a2s.c om if (primitiveTypeName != null) { getBuffer().append("new " + primitiveTypeName + " ("); element.accept(this.visitor); getBuffer().append(")"); return; } } } else if (exp.resolveUnboxing()) { ITypeBinding typeBinding = exp.resolveTypeBinding(); if (!typeBinding.isPrimitive()) { String name = typeBinding.getQualifiedName(); String primitiveName = null; if ("java.lang.Integer".equals(name)) { primitiveName = "int"; } else if ("java.lang.Long".equals(name)) { primitiveName = "long"; } else if ("java.lang.Float".equals(name)) { primitiveName = "float"; } else if ("java.lang.Double".equals(name)) { primitiveName = "double"; } else if ("java.lang.Boolean".equals(name)) { primitiveName = "boolean"; } else if ("java.lang.Byte".equals(name)) { primitiveName = "byte"; } else if ("java.lang.Short".equals(name)) { primitiveName = "short"; } else if ("java.lang.Character".equals(name)) { primitiveName = "char"; } if (primitiveName != null) { getBuffer().append("("); element.accept(this.visitor); getBuffer().append(")." + primitiveName + "Value ()"); return; } } } } element.accept(this.visitor); }
From source file:org.decojer.cavaj.utils.Expressions.java
License:Open Source License
/** * New type./*from w w w.j a va 2s .co m*/ * * @param t * type * @param context * context * @return AST type */ @SuppressWarnings("deprecation") public static Type newType(@Nonnull final T t, @Nonnull final Element context) { final AST ast = context.getCu().getAst(); // handle array first because annot(array()) is special if (t.isArray()) { if (ast.apiLevel() <= AST.JLS4) { final T componentT = t.getComponentT(); assert componentT != null; return ast.newArrayType(newType(componentT, context)); } final T elementT = t.getElementT(); assert elementT != null; for (T checkT = t; checkT != null && checkT.isArray(); checkT = checkT.getComponentT()) { if (checkT.isAnnotated()) { final ArrayType arrayType = ast.newArrayType(newType(elementT, context)); final List<Dimension> dimensions = arrayType.dimensions(); dimensions.clear(); for (T componentT = t; componentT != null && componentT.isArray(); componentT = componentT.getComponentT()) { final Dimension dimension = ast.newDimension(); final List<IExtendedModifier> annotations = dimension.annotations(); assert annotations != null; if (componentT.isAnnotated()) { Annotations.decompileAnnotations(componentT, annotations, context); } dimensions.add(dimension); } return arrayType; } } return ast.newArrayType(newType(elementT, context), t.getDimensions()); } if (t.isAnnotated()) { Type type = newType(t.getRawT(), context); if (ast.apiLevel() <= AST.JLS4) { log.warn("Cannot decompile type annotations for type '" + t + "' in Eclipse AST JLS4!"); return type; } // parameterized type is not directly annotateable in Eclipse; but DecoJer thinks the // whole type is meant, not just the generic type, hence translate here AnnotatableType annotatableType = (AnnotatableType) (type instanceof ParameterizedType ? ((ParameterizedType) type).getType() : type); qualified: if (annotatableType instanceof SimpleType) { // direct annotation of qualified types adds the annotations as first element, // strange Java spec doesn't allow "@A package.Name" but wants "package.@A Name" final Name typeName = ((SimpleType) annotatableType).getName(); if (!(typeName instanceof QualifiedName)) { break qualified; } final Name qualifier = ((QualifiedName) typeName).getQualifier(); final SimpleName name = ((QualifiedName) typeName).getName(); // cannot delete mandory childs, copy them annotatableType = ast.newNameQualifiedType((Name) ASTNode.copySubtree(ast, qualifier), (SimpleName) ASTNode.copySubtree(ast, name)); if (type instanceof ParameterizedType) { ((ParameterizedType) type).setType(annotatableType); } else { type = annotatableType; } } final List<IExtendedModifier> annotations = annotatableType.annotations(); assert annotations != null; Annotations.decompileAnnotations(t, annotations, context); return type; } // doesn't work, now with Dimension (see above): if (t.isArray()) { return // ast.newArrayType(newType(t.getComponentT(), contextT)); } if (t.isParameterized()) { final T genericT = t.getGenericT(); assert genericT != null; final ParameterizedType parameterizedType = ast.newParameterizedType(newType(genericT, context)); for (final T typeArg : t.getTypeArgs()) { assert typeArg != null; parameterizedType.typeArguments().add(newType(typeArg, context)); } return parameterizedType; } if (t.isWildcard()) { final T boundT = t.getBoundT(); if (boundT == null) { return ast.newWildcardType(); } if (t.isSubclassOf()) { final WildcardType wildcardType = ast.newWildcardType(); // default...newWildcardType.setUpperBound(true); wildcardType.setBound(newType(boundT, context)); return wildcardType; } final WildcardType wildcardType = ast.newWildcardType(); wildcardType.setUpperBound(false); wildcardType.setBound(newType(boundT, context)); return wildcardType; } if (t.isMulti()) { log.warn("Convert type for multi-type '" + t + "'!"); // prefer boolean for multi-type with 0 or 1, synchronous to newLiteral()! // prefer byte before char if no explicit char type given } if (t.is(T.BOOLEAN)) { return ast.newPrimitiveType(PrimitiveType.BOOLEAN); } if (t.is(T.BYTE)) { return ast.newPrimitiveType(PrimitiveType.BYTE); } if (t.is(T.CHAR)) { return ast.newPrimitiveType(PrimitiveType.CHAR); } if (t.is(T.SHORT)) { return ast.newPrimitiveType(PrimitiveType.SHORT); } if (t.is(T.INT)) { return ast.newPrimitiveType(PrimitiveType.INT); } if (t.is(T.FLOAT)) { return ast.newPrimitiveType(PrimitiveType.FLOAT); } if (t.is(T.LONG)) { return ast.newPrimitiveType(PrimitiveType.LONG); } if (t.is(T.DOUBLE)) { return ast.newPrimitiveType(PrimitiveType.DOUBLE); } if (t.is(T.VOID)) { return ast.newPrimitiveType(PrimitiveType.VOID); } if (t.isQualified()) { final T qualifierT = t.getQualifierT(); assert qualifierT != null : "cannot be null for qualified"; // could be ParamT etc., not decompileable with name as target; // restrict qualifications to really necessary enclosings: // t = Outer.Inner.InnerInner, t = Outer.Inner ==> Inner final T contextT = context.getT(); assert contextT != null; if (contextT.getFullName().startsWith(qualifierT.getFullName())) { // TODO full name has too much info yet (like annotations) return ast.newSimpleType(newSimpleName(t.getSimpleIdentifier(), ast)); } return ast.newQualifiedType(newType(qualifierT, context), newSimpleName(t.getSimpleIdentifier(), ast)); } // else fall through... return ast.newSimpleType(newTypeName(t, context)); }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
protected PrimitiveType.Code getPrimitiveTypeCode(char[] name) { switch (name[0]) { case 'i': if (name.length == 3 && name[1] == 'n' && name[2] == 't') { return PrimitiveType.INT; }/*from ww w . j a va 2s .c o m*/ break; case 'l': if (name.length == 4 && name[1] == 'o' && name[2] == 'n' && name[3] == 'g') { return PrimitiveType.LONG; } break; case 'd': if (name.length == 6 && name[1] == 'o' && name[2] == 'u' && name[3] == 'b' && name[4] == 'l' && name[5] == 'e') { return PrimitiveType.DOUBLE; } break; case 'f': if (name.length == 5 && name[1] == 'l' && name[2] == 'o' && name[3] == 'a' && name[4] == 't') { return PrimitiveType.FLOAT; } break; case 'b': if (name.length == 4 && name[1] == 'y' && name[2] == 't' && name[3] == 'e') { return PrimitiveType.BYTE; } else if (name.length == 7 && name[1] == 'o' && name[2] == 'o' && name[3] == 'l' && name[4] == 'e' && name[5] == 'a' && name[6] == 'n') { return PrimitiveType.BOOLEAN; } break; case 'c': if (name.length == 4 && name[1] == 'h' && name[2] == 'a' && name[3] == 'r') { return PrimitiveType.CHAR; } break; case 's': if (name.length == 5 && name[1] == 'h' && name[2] == 'o' && name[3] == 'r' && name[4] == 't') { return PrimitiveType.SHORT; } break; case 'v': if (name.length == 4 && name[1] == 'o' && name[2] == 'i' && name[3] == 'd') { return PrimitiveType.VOID; } } return null; // cannot be reached }
From source file:org.eclipse.xtend.core.javaconverter.ASTFlattenerUtils.java
License:Open Source License
public boolean needPrimitiveCast(final Type type) { if ((type instanceof PrimitiveType)) { return ((Objects.equal(((PrimitiveType) type).getPrimitiveTypeCode(), PrimitiveType.CHAR) || Objects.equal(((PrimitiveType) type).getPrimitiveTypeCode(), PrimitiveType.BYTE)) || Objects.equal(((PrimitiveType) type).getPrimitiveTypeCode(), PrimitiveType.SHORT)); }//from w ww . j a va2s . c o m return false; }
From source file:org.evosuite.testcarver.codegen.JUnitCodeGenerator.java
License:Open Source License
private Type createAstArrayType(final String type, final AST ast) { // NOTE: see asm4 guide p. 11 for more insights about internal type representation final int arrayDim = type.lastIndexOf('[') + 1; if (type.contains("[L")) { // --- object array // TODO use regex for extraction String extractedType = type.substring(type.indexOf('L') + 1, type.length() - 1); extractedType = extractedType.replaceFirst("java\\.lang\\.", ""); extractedType = extractedType.replace('$', '.'); return ast.newArrayType(this.createAstType(extractedType, ast), arrayDim); } else {/* ww w . ja va2s. c o m*/ // --- primitive type array if (type.contains("[I")) // int[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.INT), arrayDim); } else if (type.contains("[B")) // byte[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.BYTE), arrayDim); } else if (type.contains("[C")) // char[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.CHAR), arrayDim); } else if (type.contains("[D")) // double[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.DOUBLE), arrayDim); } else if (type.contains("[Z")) // boolean[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.BOOLEAN), arrayDim); } else if (type.contains("[F")) // float[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.FLOAT), arrayDim); } else if (type.contains("[S")) // short[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.SHORT), arrayDim); } else if (type.contains("[J")) // long[] { return ast.newArrayType(ast.newPrimitiveType(PrimitiveType.LONG), arrayDim); } else { throw new RuntimeException("Can not create array type for " + type); } } }