List of usage examples for org.eclipse.jdt.core.dom NumberLiteral getToken
public String getToken()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(NumberLiteral node) { this.fBuffer.append(node.getToken()); return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(NumberLiteral node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.LITERAL); b.setLiteral(node.getToken()); expressions.push(b.build());// ww w . j a va2s. c o m return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(NumberLiteral node) { this.buffer.append(node.getToken()); return false; }
From source file:com.google.dart.java2dart.SyntaxTranslator.java
License:Open Source License
@Override public boolean visit(org.eclipse.jdt.core.dom.NumberLiteral node) { String token = node.getToken(); if (token.contains(".") || !StringUtils.startsWithIgnoreCase(token, "0x") && (StringUtils.endsWithIgnoreCase(token, "F") || StringUtils.endsWithIgnoreCase(token, "D"))) { token = StringUtils.removeEndIgnoreCase(token, "F"); token = StringUtils.removeEndIgnoreCase(token, "D"); if (!token.contains(".")) { token += ".0"; }/*from ww w .j ava 2 s. co m*/ return done(new DoubleLiteral(token(TokenType.DOUBLE, token), 0)); } else { token = StringUtils.removeEndIgnoreCase(token, "L"); return done(new IntegerLiteral(token(TokenType.INT, token), BigInteger.valueOf(0))); } }
From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java
License:Open Source License
@Override public boolean visit(NumberLiteral node) { String token = node.getToken(); ITypeBinding binding = Types.getTypeBinding(node); assert binding.isPrimitive(); char kind = binding.getKey().charAt(0); // Primitive types have single-character keys. // Convert floating point literals to C format. No checking is // necessary, since the format was verified by the parser. if (kind == 'D' || kind == 'F') { if (token.matches(FLOATING_POINT_SUFFIX_REGEX)) { token = token.substring(0, token.length() - 1); // strip suffix }/* w w w.j a v a2 s. com*/ if (token.matches(HEX_LITERAL_REGEX)) { token = Double.toString(Double.parseDouble(token)); } else if (!token.matches(EXPONENTIAL_FLOATING_POINT_REGEX)) { if (token.indexOf('.') == -1) { token += ".0"; // C requires a fractional part, except in exponential form. } } if (kind == 'F') { token += 'f'; } } else if (kind == 'J') { if (token.equals("0x8000000000000000L") || token.equals("-9223372036854775808L")) { // Convert min long literal to an expression token = "-0x7fffffffffffffffLL - 1"; } else { // Convert Java long literals to long long for Obj-C if (token.startsWith("0x")) { buffer.append("(long long) "); // Ensure constant is treated as signed. } int pos = token.length() - 1; int numLs = 0; while (pos > 0 && token.charAt(pos) == 'L') { numLs++; pos--; } if (numLs == 1) { token += 'L'; } } } else if (kind == 'I') { if (token.startsWith("0x")) { buffer.append("(int) "); // Ensure constant is treated as signed. } if (token.equals("0x80000000") || token.equals("-2147483648")) { // Convert min int literal to an expression token = "-0x7fffffff - 1"; } } buffer.append(token); return false; }
From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java
License:Apache License
@Override public boolean visit(NumberLiteral node) { sb.print(node.getToken()); return false; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link NumberLiteral}s. */ @Override/* www .j a v a 2s. co m*/ public boolean visit(NumberLiteral node) { sync(node); String value = node.getToken(); if (value.startsWith("-")) { // jdt normally parses negative numeric literals as a unary minus on an // unsigned literal, but in the case of Long.MIN_VALUE and // Integer.MIN_VALUE it creates a signed literal without a unary minus // expression. // // Unfortunately in both cases the input token stream will still have // the '-' token followed by an unsigned numeric literal token. We // hack around this by checking for a leading '-' in the text of the // given numeric literal, and emitting two separate tokens if it is // present to match the input stream. token("-"); value = value.substring(1); } token(value); return false; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java
License:Open Source License
public static Object getValue(ASTNode node) { switch (node.getNodeType()) { // case ASTNode.ANONYMOUS_CLASS_DECLARATION: // return "Anonymous class declaration"; // case ASTNode.ARRAY_ACCESS: // return "Array access"; // case ASTNode.ARRAY_CREATION: // return "Array creation"; // case ASTNode.ARRAY_INITIALIZER: // return "Array initializer"; // case ASTNode.ARRAY_TYPE: // ArrayType arrayType = (ArrayType)node; // return "Array type: " + arrayType.getElementType().toString(); // case ASTNode.ASSERT_STATEMENT: // return "Assert statement"; // case ASTNode.ASSIGNMENT: // return "Assignment"; // case ASTNode.BLOCK: // return "Block"; case ASTNode.BOOLEAN_LITERAL: BooleanLiteral booleanLiteral = (BooleanLiteral) node; return booleanLiteral.booleanValue(); // case ASTNode.BREAK_STATEMENT: // return "Break statement"; // case ASTNode.CAST_EXPRESSION: // return "Cast expression"; // case ASTNode.CATCH_CLAUSE: // return "Catch clause"; case ASTNode.CHARACTER_LITERAL: CharacterLiteral characterLiteral = (CharacterLiteral) node; return characterLiteral.charValue(); // case ASTNode.CLASS_INSTANCE_CREATION: // return "Class instance creation"; // case ASTNode.COMPILATION_UNIT: // return "Compilation unit"; // case ASTNode.CONDITIONAL_EXPRESSION: // return "Conditional Expression"; // case ASTNode.CONSTRUCTOR_INVOCATION: // return "constructor invocation"; // case ASTNode.CONTINUE_STATEMENT: // return "continue statement"; // case ASTNode.DO_STATEMENT: // return "Do statement"; // case ASTNode.EMPTY_STATEMENT: // return "Empty statement"; // case ASTNode.EXPRESSION_STATEMENT: // return "Expression statement"; // case ASTNode.FIELD_ACCESS: // return "field access"; // case ASTNode.FIELD_DECLARATION: // return "Field declaration"; // case ASTNode.FOR_STATEMENT: // return "For statement"; // case ASTNode.IF_STATEMENT: // return "If statement"; // case ASTNode.IMPORT_DECLARATION: // return "Import declaration"; // case ASTNode.INFIX_EXPRESSION: // return "Infix expression"; // case ASTNode.INITIALIZER: // return "Initializer"; // case ASTNode.INSTANCEOF_EXPRESSION: // return "Instanceof expression"; // case ASTNode.JAVADOC: // return "Javadoc"; // case ASTNode.LABELED_STATEMENT: // return "Labeled statement"; // case ASTNode.METHOD_DECLARATION: // return "Method declaration"; // case ASTNode.METHOD_INVOCATION: // return "Method invocation"; // case ASTNode.NULL_LITERAL: // return "Null literal"; case ASTNode.NUMBER_LITERAL: NumberLiteral numberLiteral = (NumberLiteral) node; String token = numberLiteral.getToken(); try {/*ww w. j a v a 2s . co m*/ return Integer.parseInt(token); } catch (Exception ex) { } try { return Long.parseLong(token); } catch (Exception ex) { } try { return Double.parseDouble(token); } catch (Exception ex) { } try { return Float.parseFloat(token); } catch (Exception ex) { } return Double.NaN; // case ASTNode.PACKAGE_DECLARATION: // return "Package declaration"; // case ASTNode.PARENTHESIZED_EXPRESSION: // return "Parenthesized expression"; // case ASTNode.POSTFIX_EXPRESSION: // return "Postfix expression"; // case ASTNode.PREFIX_EXPRESSION: // return "Prefix expression"; // case ASTNode.PRIMITIVE_TYPE: // PrimitiveType primitiveType = (PrimitiveType) node; // return "Primitive type: " + primitiveType.getPrimitiveTypeCode().toString(); case ASTNode.QUALIFIED_NAME: QualifiedName qualifiedName = (QualifiedName) node; return new AstUtils.QualifiedNameValue(qualifiedName.getQualifier().getFullyQualifiedName(), qualifiedName.getName().getIdentifier()); // case ASTNode.RETURN_STATEMENT: // return "Return statement"; // case ASTNode.SIMPLE_NAME: // SimpleName simpleName = (SimpleName) node; // return "Simple name: " + simpleName.getIdentifier(); // case ASTNode.SIMPLE_TYPE: // SimpleType simpleType = (SimpleType) node; // return "Simple type (" + simpleType.getName().toString() + ")"; // case ASTNode.SINGLE_VARIABLE_DECLARATION: // return "Single variable declaration"; case ASTNode.STRING_LITERAL: StringLiteral stringLiteral = (StringLiteral) node; return stringLiteral.getLiteralValue(); // case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: // return "Super constructor invocation"; // case ASTNode.SUPER_FIELD_ACCESS: // return "Super field access"; // case ASTNode.SUPER_METHOD_INVOCATION: // return "Super method invocation"; // case ASTNode.SWITCH_CASE: // return "Switch case"; // case ASTNode.SWITCH_STATEMENT: // return "Switch statement"; // case ASTNode.SYNCHRONIZED_STATEMENT: // return "Synchronized statement"; // case ASTNode.THIS_EXPRESSION: // return "This expression"; // case ASTNode.THROW_STATEMENT: // return "Throw statement"; // case ASTNode.TRY_STATEMENT: // return "Try statement"; // case ASTNode.TYPE_DECLARATION: // return "Type declaration"; // case ASTNode.TYPE_DECLARATION_STATEMENT: // return "Type declaration statement"; case ASTNode.TYPE_LITERAL: TypeLiteral typeLiteral = (TypeLiteral) node; return new AstUtils.TypeLiteralValue(typeLiteral.toString()); // case ASTNode.VARIABLE_DECLARATION_EXPRESSION: // return "Varialbe declaration expression"; // case ASTNode.VARIABLE_DECLARATION_FRAGMENT: // return "Variable declaration fragment"; // case ASTNode.VARIABLE_DECLARATION_STATEMENT: // return "Variable declaration statement"; // case ASTNode.WHILE_STATEMENT: // return "While statement"; } return null; }
From source file:com.motorolamobility.preflighting.core.internal.utils.ProjectUtils.java
License:Apache License
/** * Extract all needed information from a CompilationUnit and fill the * internal source file model (SourceFileElement). Fill all invoked Methods * and resource constants// w ww . j ava 2 s. com * * @param javaCompilationUnit * JDT model of a .java source file. * @param parent * SourceFolderElement, the source folder model containing this * compilation unit. * @return */ public static SourceFileElement readFromJava(final CompilationUnit javaCompilationUnit, Element parent) { File file = (File) javaCompilationUnit.getProperty(JAVA_FILE_PROPERTY); final SourceFileElement sourceFileElement = new SourceFileElement(file, parent); /* Fill type information */ Object type = javaCompilationUnit.types().get(0); /* * Grab the class * declaration */ if (type instanceof TypeDeclaration) { TypeDeclaration typeDeclaration = (TypeDeclaration) type; ITypeBinding superClassType = typeDeclaration.resolveBinding().getSuperclass(); String superClass = superClassType != null ? superClassType.getQualifiedName() : null; sourceFileElement.setSuperclassName(superClass); String typeFullName = typeDeclaration.resolveBinding().getQualifiedName(); sourceFileElement.setClassFullPath(typeFullName); } javaCompilationUnit.accept(new ASTVisitor() { /* * Visit method declaration, searching for instructions. */ @Override public boolean visit(MethodDeclaration node) { // Fill Method information Method method = new Method(); SimpleName name = node.getName(); method.setMethodName(name.getFullyQualifiedName()); int modifiers = node.getModifiers(); boolean methodType = isMethodVirtual(modifiers); method.setStatic(ProjectUtils.isStatic(modifiers)); /* * Extract information regarding method parameters */ List<SingleVariableDeclaration> parameters = node.parameters(); for (SingleVariableDeclaration param : parameters) { ITypeBinding typeBinding = param.getType().resolveBinding(); if (typeBinding != null) { String paramTypeName = typeBinding.getName(); method.getParameterTypes().add(paramTypeName); } } method.setConstructor(node.isConstructor()); IMethodBinding binding = node.resolveBinding(); if (binding != null) { String returnTypeStr = binding.getReturnType().getName(); method.setReturnType(returnTypeStr); } Block body = node.getBody(); int lineNumber = body != null ? javaCompilationUnit.getLineNumber(body.getStartPosition()) : javaCompilationUnit.getLineNumber(node.getStartPosition()); method.setLineNumber(lineNumber); // Navigate through statements... if (body != null) { analizeBody(javaCompilationUnit, method, body); } sourceFileElement.addMethod(getMethodTypeString(methodType), method); return super.visit(node); } /* * Visit field declaration, only for R.java file. Extracting * declared constants. */ @Override public boolean visit(FieldDeclaration node) { if (sourceFileElement.getName().equals("R.java")) { String typeName = node.getType().resolveBinding().getName(); int modifiers = node.getModifiers(); boolean isStatic = isStatic(modifiers); Field field = new Field(); field.setType(typeName); field.setStatic(isStatic); field.setVisibility(getVisibility(modifiers)); field.setFinal(isFinal(modifiers)); if (isStatic) { List<VariableDeclarationFragment> fragments = node.fragments(); // TODO Verify what to do when // there's more than one // fragment... enum? for (VariableDeclarationFragment fragment : fragments) { IVariableBinding binding = fragment.resolveBinding(); String name = binding.getName(); String declaringClassName = binding.getDeclaringClass().getName(); field.setName(declaringClassName + "." + name); Expression initializer = fragment.getInitializer(); if (initializer != null) { if (initializer instanceof NumberLiteral) { NumberLiteral numberInitializer = (NumberLiteral) initializer; String value = numberInitializer.getToken(); field.setValue(value); } } } sourceFileElement.getStaticFields().add(field); } } return super.visit(node); } @Override public boolean visit(QualifiedName node) { //visit to recognize R.string or R.layout usage if ((node.getQualifier() != null) && node.getQualifier().isQualifiedName()) { if (node.getQualifier().toString().equals(R_STRING)) { sourceFileElement.getUsedStringConstants().add(node.getName().toString()); } else if (node.getQualifier().toString().equals(R_LAYOUT)) { sourceFileElement.getUsedLayoutConstants().add(node.getName().toString()); } } return super.visit(node); } }); return sourceFileElement; }
From source file:edu.cmu.cs.crystal.cfg.eclipse.EclipseCFG.java
License:Open Source License
@Override public void endVisit(NumberLiteral node) { EclipseCFGNode num = nodeMap.get(node); num.setName(node.getToken()); }