当前位置: 首页>>代码示例>>Java>>正文


Java NumberLiteral类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.NumberLiteral的典型用法代码示例。如果您正苦于以下问题:Java NumberLiteral类的具体用法?Java NumberLiteral怎么用?Java NumberLiteral使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NumberLiteral类属于org.eclipse.jdt.core.dom包,在下文中一共展示了NumberLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getForInitializer

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:GenerateForLoopAssistProposal.java

示例2: analyze

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
/**
 * @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());
    }
}
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:28,代码来源:TestCasesGenerator.java

示例3: rewriteInfixExpression

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:38,代码来源:ConvertConstantsToEnumRefactoring.java

示例4: getIndexBindingFromFragment

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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();
}
 
开发者ID:eclipse,项目名称:che,代码行数:10,代码来源:ConvertForLoopOperation.java

示例5: retrieveTypeClass

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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!");
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:27,代码来源:TestExtractingVisitor.java

示例6: getExplicitMultiplicity

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:21,代码来源:MultiplicityProvider.java

示例7: visit

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
@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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:20,代码来源:BigDecimalConstructorResolution.java

示例8: isValidSQLSetUpdateOrGet

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:23,代码来源:SQLOffByOneResolution.java

示例9: makeFixedMethodInvocation

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
@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;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:24,代码来源:SQLOffByOneResolution.java

示例10: fillNumberLiteral

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
/**
 * 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));
}
 
开发者ID:jgalenson,项目名称:codehint,代码行数:28,代码来源:ExpressionSkeleton.java

示例11: hasNonStaticFieldsWithInitializers

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:mrmonday,项目名称:j2d,代码行数:22,代码来源:J2dVisitor.java

示例12: RefinementNumber

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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());
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:14,代码来源:RefinementNumber.java

示例13: createInfixInvocationFromPostPrefixExpression

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:GetterSetterUtil.java

示例14: getNumber

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
/**
    * @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;
   }
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:17,代码来源:TestCasesGenerator.java

示例15: createResultVisitor

import org.eclipse.jdt.core.dom.NumberLiteral; //导入依赖的package包/类
@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;
			}
		}
	};
}
 
开发者ID:Ragnaroek,项目名称:eclipse-astparser,代码行数:50,代码来源:Wait.java


注:本文中的org.eclipse.jdt.core.dom.NumberLiteral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。