Java 类org.eclipse.jdt.core.dom.PrimitiveType.Code 实例源码

项目:eclipse-astparser    文件:MethodExpression.java   
private boolean testPrimitiveTypeEquals(final Class<?> expected, final Code actual)
{
    String name = actual.toString();
    if( name.equals(PrimitiveType.BOOLEAN.toString()) ) {
        return expected.equals(Boolean.TYPE);
    } else if(name.equals(PrimitiveType.INT.toString())) {
        return expected.equals(Integer.TYPE);
    } else if(name.equals(PrimitiveType.CHAR.toString())) {
        return expected.equals(Character.TYPE);
    } else if(name.equals(PrimitiveType.SHORT.toString())) {
        return expected.equals(Short.TYPE);
    } else if(name.equals(PrimitiveType.LONG.toString())) {
        return expected.equals(Long.TYPE);
    } else if(name.equals(PrimitiveType.FLOAT.toString())) {
        return expected.equals(Float.TYPE);
    } else if(name.equals(PrimitiveType.DOUBLE.toString())) {
        return expected.equals(Double.TYPE);
    } else if(name.equals(PrimitiveType.BYTE.toString())) {
        return expected.equals(Byte.TYPE);
    } else if(name.equals(PrimitiveType.VOID.toString())) {
        return expected.equals(Void.TYPE);
    }
    System.err.println("warning: unknown primitive type: " + actual);
    throw new UnsupportedOperationException();
    //return false;
}
项目:che    文件: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;
}
项目:che    文件:ASTResolving.java   
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()]);
}
项目:che    文件:ASTResolving.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件: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;
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:ASTResolving.java   
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()]);
}
项目:EASyProducer    文件:InvocationRemovalVisitor.java   
/**
 * Mapping between types.
 * 
 * @param type
 *            type
 * @return code of the type
 */
private int determineType(Type type) {
    int expressionType = -1;
    if (type.isPrimitiveType()) {
        PrimitiveType prim = (PrimitiveType) type;
        Code code = prim.getPrimitiveTypeCode();
        if (code.equals(PrimitiveType.INT) | code.equals(PrimitiveType.DOUBLE) | code.equals(PrimitiveType.FLOAT)
                | code.equals(PrimitiveType.LONG)) {
            expressionType = Expression.NUMBER_LITERAL;
        } else if (code.equals(PrimitiveType.BOOLEAN)) {
            expressionType = Expression.BOOLEAN_LITERAL;
        } else if (code.equals(PrimitiveType.CHAR)) {
            expressionType = Expression.CHARACTER_LITERAL;
        }
    }
    if (type.isSimpleType()) {
        // String, Double
        SimpleType simple = (SimpleType) type;
        String simpleTypeName = simple.getName().getFullyQualifiedName();
        if (simpleTypeName.equals("String")) {
            expressionType = Expression.STRING_LITERAL;
        } else if (simpleTypeName.equals("Double") | simpleTypeName.equals("Long") 
            | simpleTypeName.equals("Float")) {
            expressionType = Expression.NUMBER_LITERAL;
        } else if (simpleTypeName.equals("Boolean")) {
            expressionType = Expression.BOOLEAN_LITERAL;
        } else {
            /* 
             * WARNING: If the type is not one of the above it will be set to Expression.NULL_LITERAL resulting 
             * that for every expression the replacement will be 'null'!!!
             */
            expressionType = Expression.NULL_LITERAL;
        }
    }
    return expressionType;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件: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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTResolving.java   
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()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTResolving.java   
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()]);
}
项目:reflectify    文件:FieldAssignmentProposalCreator.java   
private MethodInvocation createSetValueMethodInvocation(IVariableBinding fieldBind, AST ast) {
    MethodInvocation result = ast.newMethodInvocation();
    ITypeBinding     fieldType = fieldBind.getType();
    if (fieldType.isPrimitive()) {
        Code code = PrimitiveType.toCode(fieldType.getName());
        if (PrimitiveType.BOOLEAN.equals(code)) {
            result.setName(ast.newSimpleName("setBoolean")); //$NON-NLS-1$
        } else if (PrimitiveType.BYTE.equals(code)) {
            result.setName(ast.newSimpleName("setByte")); //$NON-NLS-1$
        } else if (PrimitiveType.CHAR.equals(code)) {
            result.setName(ast.newSimpleName("setChar")); //$NON-NLS-1$
        } else if (PrimitiveType.DOUBLE.equals(code)) {
            result.setName(ast.newSimpleName("setDouble")); //$NON-NLS-1$
        } else if (PrimitiveType.FLOAT.equals(code)) {
            result.setName(ast.newSimpleName("setFloat")); //$NON-NLS-1$
        } else if (PrimitiveType.INT.equals(code)) {
            result.setName(ast.newSimpleName("setInt")); //$NON-NLS-1$
        } else if (PrimitiveType.LONG.equals(code)) {
            result.setName(ast.newSimpleName("setLong")); //$NON-NLS-1$
        } else if (PrimitiveType.SHORT.equals(code)) {
            result.setName(ast.newSimpleName("setShort")); //$NON-NLS-1$
        }
    } else {
        result.setName(ast.newSimpleName("set")); //$NON-NLS-1$
    }
    return result;
}
项目:reflectify    文件:FieldAccessProposalCreator.java   
private MethodInvocation createGetFieldValueInvocation(IVariableBinding field,  AST ast) {
    MethodInvocation result    = ast.newMethodInvocation();
    ITypeBinding     fieldType = field.getType();
    if (fieldType.isPrimitive()) {
        Code code = PrimitiveType.toCode(fieldType.getName());
        if (PrimitiveType.BOOLEAN.equals(code)) {
            result.setName(ast.newSimpleName("getBoolean")); //$NON-NLS-1$
        } else if (PrimitiveType.BYTE.equals(code)) {
            result.setName(ast.newSimpleName("getByte")); //$NON-NLS-1$
        } else if (PrimitiveType.CHAR.equals(code)) {
            result.setName(ast.newSimpleName("getChar")); //$NON-NLS-1$
        } else if (PrimitiveType.DOUBLE.equals(code)) {
            result.setName(ast.newSimpleName("getDouble")); //$NON-NLS-1$
        } else if (PrimitiveType.FLOAT.equals(code)) {
            result.setName(ast.newSimpleName("getFloat")); //$NON-NLS-1$
        } else if (PrimitiveType.INT.equals(code)) {
            result.setName(ast.newSimpleName("getInt")); //$NON-NLS-1$
        } else if (PrimitiveType.LONG.equals(code)) {
            result.setName(ast.newSimpleName("getLong")); //$NON-NLS-1$
        } else if (PrimitiveType.SHORT.equals(code)) {
            result.setName(ast.newSimpleName("getShort")); //$NON-NLS-1$
        }
    } else {
        result.setName(ast.newSimpleName("get")); //$NON-NLS-1$
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:ParameterGuesser.java   
private List<Variable> evaluateVisibleMatches(String expectedType, IJavaElement[] suggestions) throws JavaModelException {
    IType currentType= null;
    if (fEnclosingElement != null) {
        currentType= (IType) fEnclosingElement.getAncestor(IJavaElement.TYPE);
    }

    ArrayList<Variable> res= new ArrayList<Variable>();
    for (int i= 0; i < suggestions.length; i++) {
        Variable variable= createVariable(suggestions[i], currentType, expectedType, i);
        if (variable != null) {
            if (fAlreadyMatchedNames.contains(variable.name)) {
                variable.alreadyMatched= true;
            }
            res.add(variable);
        }
    }

    // add 'this'
    if (currentType != null && !(fEnclosingElement instanceof IMethod && Flags.isStatic(((IMethod) fEnclosingElement).getFlags()))) {
        String fullyQualifiedName= currentType.getFullyQualifiedName('.');
        if (fullyQualifiedName.equals(expectedType)) {
            ImageDescriptor desc= new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.FINAL | JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE);
            res.add(new Variable(fullyQualifiedName, "this", Variable.LITERALS, false, res.size(), new char[] {'.'}, desc));  //$NON-NLS-1$
        }
    }

    Code primitiveTypeCode= getPrimitiveTypeCode(expectedType);
    if (primitiveTypeCode == null) {
        // add 'null'
        res.add(new Variable(expectedType, "null", Variable.LITERALS, false, res.size(), NO_TRIGGERS, null));  //$NON-NLS-1$
    } else {
        String typeName= primitiveTypeCode.toString();
        boolean isAutoboxing= !typeName.equals(expectedType);
        if (primitiveTypeCode == PrimitiveType.BOOLEAN) {
            // add 'true', 'false'
            res.add(new Variable(typeName, "true", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null)); //$NON-NLS-1$
            res.add(new Variable(typeName, "false", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null)); //$NON-NLS-1$
        } else {
            // add 0
            res.add(new Variable(typeName, "0", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null));   //$NON-NLS-1$
        }
    }
    return res;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ParameterGuesser.java   
private List<Variable> evaluateVisibleMatches(String expectedType, IJavaElement[] suggestions) throws JavaModelException {
    IType currentType= null;
    if (fEnclosingElement != null) {
        currentType= (IType) fEnclosingElement.getAncestor(IJavaElement.TYPE);
    }

    ArrayList<Variable> res= new ArrayList<Variable>();
    for (int i= 0; i < suggestions.length; i++) {
        Variable variable= createVariable(suggestions[i], currentType, expectedType, i);
        if (variable != null) {
            if (fAlreadyMatchedNames.contains(variable.name)) {
                variable.alreadyMatched= true;
            }
            res.add(variable);
        }
    }

    // add 'this'
    if (currentType != null && !(fEnclosingElement instanceof IMethod && Flags.isStatic(((IMethod) fEnclosingElement).getFlags()))) {
        String fullyQualifiedName= currentType.getFullyQualifiedName('.');
        if (fullyQualifiedName.equals(expectedType)) {
            ImageDescriptor desc= new JavaElementImageDescriptor(JavaPluginImages.DESC_FIELD_PUBLIC, JavaElementImageDescriptor.FINAL | JavaElementImageDescriptor.STATIC, JavaElementImageProvider.SMALL_SIZE);
            res.add(new Variable(fullyQualifiedName, "this", Variable.LITERALS, false, res.size(), new char[] {'.'}, desc));  //$NON-NLS-1$
        }
    }

    Code primitiveTypeCode= getPrimitiveTypeCode(expectedType);
    if (primitiveTypeCode == null) {
        // add 'null'
        res.add(new Variable(expectedType, "null", Variable.LITERALS, false, res.size(), NO_TRIGGERS, null));  //$NON-NLS-1$
    } else {
        String typeName= primitiveTypeCode.toString();
        boolean isAutoboxing= !typeName.equals(expectedType);
        if (primitiveTypeCode == PrimitiveType.BOOLEAN) {
            // add 'true', 'false'
            res.add(new Variable(typeName, "true", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null)); //$NON-NLS-1$
            res.add(new Variable(typeName, "false", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null)); //$NON-NLS-1$
        } else {
            // add 0
            res.add(new Variable(typeName, "0", Variable.LITERALS, isAutoboxing, res.size(), NO_TRIGGERS, null));   //$NON-NLS-1$
        }
    }
    return res;
}
项目:jsglr    文件:java3.java   
private Code asTypeCode(IStrategoTerm term) {
    return PrimitiveType.toCode(((IStrategoString)term).stringValue());
}