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

项目:che    文件:GenerateForLoopAssistProposal.java   
/**
 * Generates a {@link VariableDeclarationExpression}, which initializes the loop variable to
 * iterate over an array.
 *
 * @param ast the current {@link AST} instance
 * @param loopVariableName the name of the variable which should be initialized
 * @return a filled {@link VariableDeclarationExpression}, declaring a int variable, which is
 *     initializes with 0
 */
private VariableDeclarationExpression getForInitializer(AST ast, SimpleName loopVariableName) {
  // initializing fragment
  VariableDeclarationFragment firstDeclarationFragment = ast.newVariableDeclarationFragment();
  firstDeclarationFragment.setName(loopVariableName);
  NumberLiteral startIndex = ast.newNumberLiteral();
  firstDeclarationFragment.setInitializer(startIndex);

  // declaration
  VariableDeclarationExpression variableDeclaration =
      ast.newVariableDeclarationExpression(firstDeclarationFragment);
  PrimitiveType variableType = ast.newPrimitiveType(PrimitiveType.INT);
  variableDeclaration.setType(variableType);

  return variableDeclaration;
}
项目:junit-tools    文件:TestCasesGenerator.java   
/**
 * @param expression
 */
public void analyze(Expression expression) {
    // param == null, null == param
    if (expression.getNodeType() == ASTNode.NULL_LITERAL) {
    setNullLiteral((NullLiteral) expression);
    } else if (expression.getNodeType() == ASTNode.SIMPLE_NAME) {
    setSimpleName((SimpleName) expression);
    } else if (expression.getNodeType() == ASTNode.NUMBER_LITERAL) {
    setNumberLiteral((NumberLiteral) expression);
    } else if (expression.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
    setPrefixExpression((PrefixExpression) expression);
    } else if (expression.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
    setPostfixExpression((PostfixExpression) expression);
    } else if (expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION
        || expression.getNodeType() == ASTNode.INFIX_EXPRESSION
        || expression.getNodeType() == ASTNode.METHOD_INVOCATION) {
    // addTestCasesToMerge(processIfExpressions(expression,
    // tmlMethod));
    } else {
    // TODO
    System.out.println("Expression could not be analyzed: "
        + expression.getNodeType() + ". Expression: "
        + expression.toString());
    }
}
项目:Constants-to-Enum-Eclipse-Plugin    文件:ConvertConstantsToEnumRefactoring.java   
private RefactoringStatus rewriteInfixExpression(ASTRewrite astRewrite,
        ImportRewrite importRewrite, InfixExpression ie,
        String fullyQualifiedTypeName) {
    final RefactoringStatus status = new RefactoringStatus();
    final AST ast = ie.getAST();

    final Expression leftExpCopy = (Expression) ASTNode.copySubtree(ast,
            ie.getLeftOperand());
    final Expression rightExpCopy = (Expression) ASTNode.copySubtree(ast,
            ie.getRightOperand());

    final NumberLiteral zero = ast.newNumberLiteral();
    astRewrite.replace(ie.getRightOperand(), zero, null);

    final MethodInvocation newInvocation = ast.newMethodInvocation();
    newInvocation.setExpression(leftExpCopy);
    newInvocation.setName(ast.newSimpleName("compareTo")); //$NON-NLS-1$
    newInvocation.arguments().add(rightExpCopy);

    astRewrite.replace(ie.getLeftOperand(), newInvocation, null);

    if (((ASTNode) newInvocation.arguments().get(0)).getNodeType() == ASTNode.SIMPLE_NAME
            && this.fieldsToRefactor.contains(((SimpleName) ie
                    .getRightOperand()).resolveBinding().getJavaElement()))
        this.rewriteReference(astRewrite, importRewrite,
                (SimpleName) newInvocation.arguments().get(0),
                fullyQualifiedTypeName);

    if (((ASTNode) newInvocation.getExpression()).getNodeType() == ASTNode.SIMPLE_NAME
            && this.fieldsToRefactor.contains(((SimpleName) ie
                    .getLeftOperand()).resolveBinding().getJavaElement()))
        this.rewriteReference(astRewrite, importRewrite,
                (SimpleName) newInvocation.getExpression(),
                fullyQualifiedTypeName);

    return status;
}
项目:che    文件:ConvertForLoopOperation.java   
private IVariableBinding getIndexBindingFromFragment(VariableDeclarationFragment fragment) {
  Expression initializer = fragment.getInitializer();
  if (!(initializer instanceof NumberLiteral)) return null;

  NumberLiteral number = (NumberLiteral) initializer;
  if (!LITERAL_0.equals(number.getToken())) return null;

  return (IVariableBinding) fragment.getName().resolveBinding();
}
项目:evosuite    文件:TestExtractingVisitor.java   
private Class<?> retrieveTypeClass(NumberLiteral numberLiteral) {
    Object value = numberLiteral.resolveConstantExpressionValue();
    if (numberLiteral.resolveBoxing()) {
        return value.getClass();
    }
    if (value instanceof Integer) {
        return Integer.TYPE;
    }
    if (value instanceof Long) {
        return Long.TYPE;
    }
    if (value instanceof Double) {
        return Double.TYPE;
    }
    if (value instanceof Float) {
        return Float.TYPE;
    }
    if (value instanceof Short) {
        return Short.TYPE;
    }
    if (value instanceof Byte) {
        return Byte.TYPE;
    }
    throw new UnsupportedOperationException("Retrieval of type "
            + numberLiteral.getClass() + " not implemented yet!");
}
项目:txtUML    文件:MultiplicityProvider.java   
private static Integer getExplicitMultiplicity(TypeDeclaration typeDeclaration, String annotationName) {
    for (Object modifier : typeDeclaration.modifiers()) {
        if (modifier instanceof SingleMemberAnnotation) {
            SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier;
            if (annotation.getTypeName().toString().equals(annotationName)) {
                Expression value = annotation.getValue();
                if (value instanceof NumberLiteral) {
                    NumberLiteral num = (NumberLiteral) value;
                    try {
                        return new Integer(Integer.parseInt(num.getToken()));
                    } catch (NumberFormatException e) {
                        // Just let it fall through to returning 'null'
                        // below.
                    }
                }
            }
        }
    }
    return null;
}
项目:fb-contrib-eclipse-quick-fixes    文件:BigDecimalConstructorResolution.java   
@Override
public boolean visit(ClassInstanceCreation node) {
    if (badBigDecimalConstructor != null) {
        return false;
    }
    Type type = node.getType();
    if (type instanceof SimpleType
            && "BigDecimal".equals(((SimpleType) type).getName().getFullyQualifiedName())) {

        @SuppressWarnings("unchecked")
        List<Expression> args = node.arguments();
        if (args.size() == 1 && args.get(0) instanceof NumberLiteral) {
            badBigDecimalConstructor = node;
            this.decimalVar = (NumberLiteral) node.arguments().get(0);
        }
    }

    return true;
}
项目:fb-contrib-eclipse-quick-fixes    文件:SQLOffByOneResolution.java   
private boolean isValidSQLSetUpdateOrGet(MethodInvocation node) {
    String typeName = node.getExpression().resolveTypeBinding().getQualifiedName();
    if (!types.contains(typeName)) {
        return false;
    }
    // ResultSet and PreparedStatement have lots of methods
    // we don't want to change the wrong ones
    String calledMethod = node.getName().getFullyQualifiedName();
    if (typeName.contains("PreparedStatement")) {
        // e.g. setInteger(int paramIndex, int val)
        return calledMethod.startsWith("set") && node.arguments().size() == 2;
    }

    List<?> args = node.arguments();
    if (!((calledMethod.startsWith("get") && args.size() == 1) || (calledMethod.startsWith("update") && args.size() == 2))) {
        return false;
    }
    // there are two versions of resultSet.getString [and updateString]
    // getString(String colName) and getString(int colIndex)
    // we only want to update the latter
    return args.get(0) instanceof NumberLiteral;
}
项目:fb-contrib-eclipse-quick-fixes    文件:SQLOffByOneResolution.java   
@SuppressWarnings("unchecked")
private MethodInvocation makeFixedMethodInvocation(MethodInvocation node) {
    MethodInvocation fixedMethodInvocation = rootAST.newMethodInvocation();
    // move targets didn't seem to work, so I'm using copy targets instead
    fixedMethodInvocation.setExpression((Expression) rewrite.createCopyTarget(node.getExpression()));
    fixedMethodInvocation.setName((SimpleName) rewrite.createCopyTarget(node.getName()));

    List<Expression> oldArguments = node.arguments();

    // we know from isValidSQLSetUpdateOrGet that the first arg is the numberLiteral
    NumberLiteral intArg = (NumberLiteral) oldArguments.get(0);

    String incrementedArg = Integer.toString(Integer.parseInt(intArg.getToken()) + 1);

    List<Expression> newArguments = fixedMethodInvocation.arguments();
    newArguments.add(rootAST.newNumberLiteral(incrementedArg));

    for (int i = 1; i < oldArguments.size(); i++) {
        newArguments.add((Expression) rewrite.createCopyTarget(oldArguments.get(i)));
    }

    return fixedMethodInvocation;
}
项目:codehint    文件:ExpressionSkeleton.java   
/**
 * Fills number literal skeleton pieces.
 * @param node The number literal part of the skeleton.
 * @return The synthesized expressions corresponding to this
 * skeleton piece and the type constraint representing their types.
 */
private ExpressionsAndTypeConstraints fillNumberLiteral(Expression node) {
    String str = ((NumberLiteral)node).getToken();
    int lastChar = str.charAt(str.length() - 1);
    // Rules taken from: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html.
    IJavaType resultType = null;
    IJavaValue value = null;
    if (lastChar == 'l' || lastChar == 'L') {
        resultType = EclipseUtils.getFullyQualifiedType("long", stack, target, typeCache);
        value = target.newValue(Long.parseLong(str));
    } else if (lastChar == 'f' || lastChar == 'f') {
        resultType = EclipseUtils.getFullyQualifiedType("float", stack, target, typeCache);
        value = target.newValue(Float.parseFloat(str));
    } else if (lastChar == 'd' || lastChar == 'd' || str.indexOf('.') != -1) {
        resultType = EclipseUtils.getFullyQualifiedType("double", stack, target, typeCache);
        value = target.newValue(Double.parseDouble(str));
    } else {
        resultType = intType;
        value = target.newValue(Integer.parseInt(str));
    }
    return new ExpressionsAndTypeConstraints(expressionMaker.makeNumber(str, value, resultType, thread), new SupertypeBound(resultType));
}
项目:j2d    文件:J2dVisitor.java   
private boolean hasNonStaticFieldsWithInitializers(ASTNode node) {
    if (node instanceof TypeDeclaration) {
        TypeDeclaration td = (TypeDeclaration)node;
        for (FieldDeclaration fd : td.getFields()) {
            if (!hasStaticModifier(fd)) {
                for (Object o : fd.fragments()) {
                    VariableDeclarationFragment vdf = (VariableDeclarationFragment)o;
                    if (vdf.getInitializer() != null &&
                        (vdf.getInitializer() instanceof BooleanLiteral ||
                         vdf.getInitializer() instanceof NumberLiteral ||
                         vdf.getInitializer() instanceof StringLiteral)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    // TODO is this correct for enums?
    return false;
}
项目:bayou    文件:RefinementNumber.java   
public RefinementNumber(Expression e) {
    if (knownConstants(e))
        return;

    if (! (e instanceof NumberLiteral)) {
        this.exists = false;
        this.value = 0;
        return;
    }

    this.exists = true;
    this.value = Float.parseFloat(((NumberLiteral) e).getToken());
}
项目:eclipse.jdt.ls    文件:GetterSetterUtil.java   
private static Expression createInfixInvocationFromPostPrefixExpression(InfixExpression.Operator operator, Expression getterExpression, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
    InfixExpression infix = ast.newInfixExpression();
    infix.setLeftOperand(getterExpression);
    infix.setOperator(operator);
    NumberLiteral number = ast.newNumberLiteral();
    number.setToken("1"); //$NON-NLS-1$
    infix.setRightOperand(number);
    ITypeBinding infixType = infix.resolveTypeBinding();
    return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
项目:junit-tools    文件:TestCasesGenerator.java   
/**
    * @param numberLiteral
    */
   protected Number getNumber(NumberLiteral numberLiteral) {
String sNumber = numberLiteral.getToken();
Number number = 0;

try {
    number = Integer.parseInt(sNumber);

} catch (NumberFormatException e) {
    number = 0;
}

return number;
   }
项目:eclipse-astparser    文件:Wait.java   
@Override
protected ResultVisitor createResultVisitor() 
{
    return new MethodInvocationResultVisitor("wait") 
    {
        @Override
        public void visitMethodInvocation(final MethodInvocation node) {
            if( !checkWaitTimout(node) ) {
                setMatch(false); //passt doch nicht, zuruecksetzen
                setMatchedNode(null);
            }
        }

        private boolean checkWaitTimout(final MethodInvocation invocation) 
        {
            List<?> arguments = invocation.arguments();

            if(fTimeout < 0) {
                return arguments.size() == 0;
            } else { //Timeout angegeben
                if(arguments.size() == 1) { //genau 1 Argument fuer wait
                    Object o = arguments.get(0);
                    if(o instanceof NumberLiteral) {
                        NumberLiteral literal = (NumberLiteral)o;
                        try {
                            long time = Long.valueOf(literal.getToken());
                            if(!fAnyTimout) { //nicht irgendein timeout
                                return time == fTimeout; //nur true wenn genau das timeout angegeben wurde
                            } else { //irgendein timeout muss angegeben sein
                                //wenn Ausfuehrung hierhin kommt wurde ein long als Timeout angegeben
                                return true; 
                            }
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                            return false;
                        }   
                    } else { //kein NumberLiteral angegeben, z.B. Methodenaufruf oder new Long(1)...
                        if(fAnyTimout) { //irgendein timeout ist erfuellt
                            return true; //deshalb true zurueckgeben
                        } else { //ein genaues NumberLiteral Timeout jedoch nicht
                            return false; //deshalb false
                        }
                    }
                }
                return false;
            }
        }
    };
}
项目:che    文件:GetterSetterUtil.java   
private static Expression createInfixInvocationFromPostPrefixExpression(
    InfixExpression.Operator operator,
    Expression getterExpression,
    AST ast,
    ITypeBinding variableType,
    boolean is50OrHigher) {
  InfixExpression infix = ast.newInfixExpression();
  infix.setLeftOperand(getterExpression);
  infix.setOperator(operator);
  NumberLiteral number = ast.newNumberLiteral();
  number.setToken("1"); // $NON-NLS-1$
  infix.setRightOperand(number);
  ITypeBinding infixType = infix.resolveTypeBinding();
  return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
项目:evosuite    文件:TestExtractingVisitor.java   
private VariableReference retrieveVariableReference(ArrayCreation arrayCreation) {
    Class<?> arrayType = retrieveTypeClass(arrayCreation.getType());
    List<?> dimensions = ((AbstractList<?>) arrayCreation.getStructuralProperty(ArrayCreation.DIMENSIONS_PROPERTY));
    if (dimensions.size() > 1) {
        throw new RuntimeException("Multidimensional arrays not implemented!");
    }
    Integer length = (Integer) ((NumberLiteral) dimensions.get(0)).resolveConstantExpressionValue();
    // ArrayReference arrayReference = new
    // ValidArrayReference(testCase.getReference(), arrayType, length);
    ArrayStatement arrayAssignment = new ArrayStatement(testCase.getReference(),
            arrayType, length);
    testCase.addStatement(arrayAssignment);
    return arrayAssignment.getReturnValue();
}
项目:evosuite    文件:TestExtractingVisitor.java   
private VariableReference retrieveVariableReference(NumberLiteral numberLiteral,
        Class<?> numberClass) {
    Object value = numberLiteral.resolveConstantExpressionValue();
    PrimitiveStatement<?> numberAssignment = createPrimitiveStatement(numberClass,
                                                                      value);
    testCase.addStatement(numberAssignment);
    return numberAssignment.getReturnValue();
}
项目:evosuite    文件:TestExtractingVisitor.java   
private VariableReference retrieveVariableReference(PrefixExpression prefixExpr,
        Class<?> numberClass) {
    if (prefixExpr.getOperator() == org.eclipse.jdt.core.dom.PrefixExpression.Operator.MINUS) {
        NumberLiteral numberLiteral = (NumberLiteral) prefixExpr.getOperand();
        Number value = (Number) numberLiteral.resolveConstantExpressionValue();
        value = negate(value);
        PrimitiveStatement<?> numberAssignment = createPrimitiveStatement(numberClass,
                                                                          value);
        testCase.addStatement(numberAssignment);
        return numberAssignment.getReturnValue();
    }
    throw new UnsupportedOperationException("Prefix " + prefixExpr
            + " not implemented!");
}
项目:Eclipse-Postfix-Code-Completion    文件:GetterSetterUtil.java   
private static Expression createInfixInvocationFromPostPrefixExpression(InfixExpression.Operator operator, Expression getterExpression, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
    InfixExpression infix= ast.newInfixExpression();
    infix.setLeftOperand(getterExpression);
    infix.setOperator(operator);
    NumberLiteral number= ast.newNumberLiteral();
    number.setToken("1"); //$NON-NLS-1$
    infix.setRightOperand(number);
    ITypeBinding infixType= infix.resolveTypeBinding();
    return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
项目:Eclipse-Postfix-Code-Completion    文件:ConvertForLoopOperation.java   
private IVariableBinding getIndexBindingFromFragment(VariableDeclarationFragment fragment) {
    Expression initializer= fragment.getInitializer();
    if (!(initializer instanceof NumberLiteral))
        return null;

    NumberLiteral number= (NumberLiteral)initializer;
    if (!LITERAL_0.equals(number.getToken()))
        return null;

    return (IVariableBinding)fragment.getName().resolveBinding();
}
项目:Eclipse-Postfix-Code-Completion    文件:ConvertForLoopOperation.java   
private boolean isOneLiteral(Expression expression) {
    if (!(expression instanceof NumberLiteral))
        return false;

    NumberLiteral literal= (NumberLiteral)expression;
    return LITERAL_1.equals(literal.getToken());
}
项目:Eclipse-Postfix-Code-Completion    文件:GenerateForLoopAssistProposal.java   
/**
 * Generates a {@link VariableDeclarationExpression}, which initializes the loop variable to
 * iterate over an array.
 * 
 * @param ast the current {@link AST} instance
 * @param loopVariableName the name of the variable which should be initialized
 * @return a filled {@link VariableDeclarationExpression}, declaring a int variable, which is
 *         initializes with 0
 */
private VariableDeclarationExpression getForInitializer(AST ast, SimpleName loopVariableName) {
    // initializing fragment
    VariableDeclarationFragment firstDeclarationFragment= ast.newVariableDeclarationFragment();
    firstDeclarationFragment.setName(loopVariableName);
    NumberLiteral startIndex= ast.newNumberLiteral();
    firstDeclarationFragment.setInitializer(startIndex);

    // declaration
    VariableDeclarationExpression variableDeclaration= ast.newVariableDeclarationExpression(firstDeclarationFragment);
    PrimitiveType variableType= ast.newPrimitiveType(PrimitiveType.INT);
    variableDeclaration.setType(variableType);

    return variableDeclaration;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:GetterSetterUtil.java   
private static Expression createInfixInvocationFromPostPrefixExpression(InfixExpression.Operator operator, Expression getterExpression, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
    InfixExpression infix= ast.newInfixExpression();
    infix.setLeftOperand(getterExpression);
    infix.setOperator(operator);
    NumberLiteral number= ast.newNumberLiteral();
    number.setToken("1"); //$NON-NLS-1$
    infix.setRightOperand(number);
    ITypeBinding infixType= infix.resolveTypeBinding();
    return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ConvertForLoopOperation.java   
private IVariableBinding getIndexBindingFromFragment(VariableDeclarationFragment fragment) {
    Expression initializer= fragment.getInitializer();
    if (!(initializer instanceof NumberLiteral))
        return null;

    NumberLiteral number= (NumberLiteral)initializer;
    if (!LITERAL_0.equals(number.getToken()))
        return null;

    return (IVariableBinding)fragment.getName().resolveBinding();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ConvertForLoopOperation.java   
private boolean isOneLiteral(Expression expression) {
    if (!(expression instanceof NumberLiteral))
        return false;

    NumberLiteral literal= (NumberLiteral)expression;
    return LITERAL_1.equals(literal.getToken());
}
项目:jenkins.py    文件:MethodMaker.java   
/**
 * Creates a pexec.isImplemented(id) expression.
 */
private Expression getIsImplementedExpr(int id) {
    // pexec.
    Name pexec = ast.newSimpleName("pexec");
    // pexec.isImplemented
    SimpleName methodName = ast.newSimpleName("isImplemented");
    // pexec.isImplemented(id)
    NumberLiteral idArg = ast.newNumberLiteral(new Integer(id).toString());
    MethodInvocation mi = ast.newMethodInvocation();
    mi.setExpression(pexec);
    mi.setName(methodName);
    mi.arguments().add(idArg);
    return mi;
}
项目:j2d    文件:J2dVisitor.java   
@Override
public boolean visit(NumberLiteral node) {
    //System.out.println("Found: " + node.getClass());
    String number = node.toString();
    // Floating point literals are doubles by default in D
    if (number.endsWith("D") || number.endsWith("d")) {
        number = number.substring(0, number.length() - 1);
    }
    // 10l -> 10L
    if (number.endsWith("l")) {
        number = number.substring(0, number.length() - 1) + "L";
    }
    print(number);
    return false;
}
项目:pandionj    文件:VarParser.java   
@Override
public boolean visit(Assignment node) {
    if(node.getLeftHandSide() instanceof SimpleName) {
        String varName = node.getLeftHandSide().toString(); 
        VariableOperation.Type op = null;

        if(node.getOperator() == Assignment.Operator.PLUS_ASSIGN && node.getRightHandSide() instanceof NumberLiteral || 
                isAcumulationAssign(node, InfixExpression.Operator.PLUS, (e) -> e instanceof NumberLiteral))
            op = Type.INC;

        else if(node.getOperator() == Assignment.Operator.MINUS_ASSIGN && node.getRightHandSide() instanceof NumberLiteral ||
                isAcumulationAssign(node, InfixExpression.Operator.MINUS, (e) -> e instanceof NumberLiteral))
            op = Type.DEC;

        if(op != null)
            current.addOperation(new VariableOperation(varName, op));
        else {
            op = Type.SUBS;
            Object[] params = new Object[0];
            if(node.getOperator() == Assignment.Operator.PLUS_ASSIGN ||
                    isAcumulationAssign(node, InfixExpression.Operator.PLUS, (e) -> true)) {
                op = Type.ACC;
                params = new Object[] {GathererType.SUM};
            }
            else if(node.getOperator() == Assignment.Operator.MINUS_ASSIGN ||
                    isAcumulationAssign(node, InfixExpression.Operator.MINUS, (e) -> true)) {
                op = Type.ACC;
                params = new Object[] {GathererType.MINUS};
            }
            else if(node.getOperator() == Assignment.Operator.TIMES_ASSIGN ||
                    isAcumulationAssign(node, InfixExpression.Operator.TIMES, (e) -> true)) {
                //                          node.getOperator() == Assignment.Operator.DIVIDE_ASSIGN ||
                //                          isAcumulationAssign(node, InfixExpression.Operator.DIVIDE, (e) -> true)) {
                op = Type.ACC;
                params = new Object[] {GathererType.PROD};
            }

            current.addOperation(new VariableOperation(varName, op, params));
        }
    }
    return true;
}
项目:pandionj    文件:VarParser.java   
@Override
public void preVisit(ASTNode node) {
    if(!(node instanceof SimpleName || node instanceof QualifiedName || node instanceof NumberLiteral))
        ok = false;
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) {
    String name= null;
    if (assignedExpression instanceof CastExpression) {
        assignedExpression= ((CastExpression)assignedExpression).getExpression();
    }
    if (assignedExpression instanceof Name) {
        Name simpleNode= (Name)assignedExpression;
        IBinding binding= simpleNode.resolveBinding();
        if (binding instanceof IVariableBinding) {
            return getBaseName((IVariableBinding)binding, project);
        }

        return ASTNodes.getSimpleNameIdentifier(simpleNode);
    } else if (assignedExpression instanceof MethodInvocation) {
        name= ((MethodInvocation)assignedExpression).getName().getIdentifier();
    } else if (assignedExpression instanceof SuperMethodInvocation) {
        name= ((SuperMethodInvocation)assignedExpression).getName().getIdentifier();
    } else if (assignedExpression instanceof FieldAccess) {
        return ((FieldAccess)assignedExpression).getName().getIdentifier();
    } else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) {
        String string= assignedExpression instanceof StringLiteral ? ((StringLiteral)assignedExpression).getLiteralValue() : ((NumberLiteral)assignedExpression).getToken();
        StringBuffer res= new StringBuffer();
        boolean needsUnderscore= false;
        for (int i= 0; i < string.length(); i++) {
            char ch= string.charAt(i);
            if (Character.isJavaIdentifierPart(ch)) {
                if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
                    res.append('_');
                }
                res.append(ch);
                needsUnderscore= false;
            } else {
                needsUnderscore= res.length() > 0;
            }
        }
        if (res.length() > 0) {
            return res.toString();
        }
    }
    if (name != null) {
        for (int i= 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
            String curr= KNOWN_METHOD_NAME_PREFIXES[i];
            if (name.startsWith(curr)) {
                if (name.equals(curr)) {
                    return null; // don't suggest 'get' as variable name
                } else if (Character.isUpperCase(name.charAt(curr.length()))) {
                    return name.substring(curr.length());
                }
            }
        }
    }
    return name;
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@Override
public void endVisit(NumberLiteral node) {
    // Leaf node.
}
项目:junit-tools    文件:TestCasesGenerator.java   
public NumberLiteral getNumberLiteral() {
    return (NumberLiteral) getExpressionFromList(numberLiterals, 0);
}
项目:junit-tools    文件:TestCasesGenerator.java   
public void setNumberLiteral(NumberLiteral numberLiteral) {
    this.expressionOrder.put(numberLiteral, filledCount++);
    this.numberLiterals.add(numberLiteral);
}
项目:che    文件:StubUtility.java   
private static String getBaseNameFromExpression(
    IJavaProject project, Expression assignedExpression, int variableKind) {
  String name = null;
  if (assignedExpression instanceof CastExpression) {
    assignedExpression = ((CastExpression) assignedExpression).getExpression();
  }
  if (assignedExpression instanceof Name) {
    Name simpleNode = (Name) assignedExpression;
    IBinding binding = simpleNode.resolveBinding();
    if (binding instanceof IVariableBinding)
      return getBaseName((IVariableBinding) binding, project);

    return ASTNodes.getSimpleNameIdentifier(simpleNode);
  } else if (assignedExpression instanceof MethodInvocation) {
    name = ((MethodInvocation) assignedExpression).getName().getIdentifier();
  } else if (assignedExpression instanceof SuperMethodInvocation) {
    name = ((SuperMethodInvocation) assignedExpression).getName().getIdentifier();
  } else if (assignedExpression instanceof FieldAccess) {
    return ((FieldAccess) assignedExpression).getName().getIdentifier();
  } else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD
      && (assignedExpression instanceof StringLiteral
          || assignedExpression instanceof NumberLiteral)) {
    String string =
        assignedExpression instanceof StringLiteral
            ? ((StringLiteral) assignedExpression).getLiteralValue()
            : ((NumberLiteral) assignedExpression).getToken();
    StringBuffer res = new StringBuffer();
    boolean needsUnderscore = false;
    for (int i = 0; i < string.length(); i++) {
      char ch = string.charAt(i);
      if (Character.isJavaIdentifierPart(ch)) {
        if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
          res.append('_');
        }
        res.append(ch);
        needsUnderscore = false;
      } else {
        needsUnderscore = res.length() > 0;
      }
    }
    if (res.length() > 0) {
      return res.toString();
    }
  }
  if (name != null) {
    for (int i = 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
      String curr = KNOWN_METHOD_NAME_PREFIXES[i];
      if (name.startsWith(curr)) {
        if (name.equals(curr)) {
          return null; // don't suggest 'get' as variable name
        } else if (Character.isUpperCase(name.charAt(curr.length()))) {
          return name.substring(curr.length());
        }
      }
    }
  }
  return name;
}
项目:che    文件:ConvertForLoopOperation.java   
private boolean isOneLiteral(Expression expression) {
  if (!(expression instanceof NumberLiteral)) return false;

  NumberLiteral literal = (NumberLiteral) expression;
  return LITERAL_1.equals(literal.getToken());
}
项目:che    文件:InferTypeArgumentsConstraintCreator.java   
@Override
public void endVisit(NumberLiteral node) {
  ITypeBinding typeBinding = node.resolveTypeBinding();
  ImmutableTypeVariable2 cv = fTCModel.makeImmutableTypeVariable(typeBinding, node);
  setConstraintVariable(node, cv);
}
项目:che    文件:SemanticHighlightingReconciler.java   
@Override
public boolean visit(NumberLiteral node) {
  return visitLiteral(node);
}
项目:evosuite    文件:TestExtractingVisitor.java   
private VariableReference retrieveVariableReference(NumberLiteral numberLiteral) {
    Class<?> numberClass = retrieveTypeClass(numberLiteral);
    return retrieveVariableReference(numberLiteral, numberClass);
}
项目:evosuite    文件:LoggingVisitor.java   
/** {@inheritDoc} */
@Override
public void endVisit(NumberLiteral node) {
    logger.warn("Method endVisitNumberLiteral for " + node + " for " + node + " not implemented!");
    super.endVisit(node);
}