/******************************************************************************* * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.core.tests.dom; import java.util.List; import junit.framework.Test; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Expression; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; @SuppressWarnings("rawtypes") public class ASTConverter16Test extends ConverterTestSetup { ICompilationUnit workingCopy; public void setUpSuite() throws Exception { super.setUpSuite(); this.ast = AST.newAST(getJLS3()); } public ASTConverter16Test(String name) { super(name); } static { // TESTS_NUMBERS = new int[] { 284 }; // TESTS_RANGE = new int[] { 277, -1 }; // TESTS_NAMES = new String[] {"test0204"}; } public static Test suite() { return buildModelTestSuite(ASTConverter16Test.class); } protected void tearDown() throws Exception { super.tearDown(); if (this.workingCopy != null) { this.workingCopy.discardWorkingCopy(); this.workingCopy = null; } } /* * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203342 */ public void test0001() throws JavaModelException { String contents = "public class X {\n" + " public static final double VAR = 0x0.0000000000001P-1022;\n" + "}"; this.workingCopy = getWorkingCopy("/Converter16/src/X.java", true/*resolve*/); ASTNode node = buildAST( contents, this.workingCopy); assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); CompilationUnit unit = (CompilationUnit) node; assertProblemsSize(unit, 0); node = getASTNode(unit, 0, 0); assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType()); FieldDeclaration fieldDeclaration = (FieldDeclaration) node; final List fragments = fieldDeclaration.fragments(); assertEquals("Wrong size", 1, fragments.size()); VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); final Expression initializer = fragment.getInitializer(); assertEquals("Not a number literal", ASTNode.NUMBER_LITERAL, initializer.getNodeType()); checkSourceRange(initializer, "0x0.0000000000001P-1022", contents); } }