| /******************************************************************************* |
| * Copyright (c) 2000, 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-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 junit.framework.TestSuite; |
| |
| 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.AbstractTypeDeclaration; |
| import org.eclipse.jdt.core.dom.Annotation; |
| import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration; |
| import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration; |
| import org.eclipse.jdt.core.dom.BodyDeclaration; |
| import org.eclipse.jdt.core.dom.ClassInstanceCreation; |
| import org.eclipse.jdt.core.dom.CompilationUnit; |
| import org.eclipse.jdt.core.dom.ConstructorInvocation; |
| import org.eclipse.jdt.core.dom.EnhancedForStatement; |
| import org.eclipse.jdt.core.dom.EnumConstantDeclaration; |
| import org.eclipse.jdt.core.dom.EnumDeclaration; |
| import org.eclipse.jdt.core.dom.Expression; |
| import org.eclipse.jdt.core.dom.FieldDeclaration; |
| import org.eclipse.jdt.core.dom.IExtendedModifier; |
| import org.eclipse.jdt.core.dom.ImportDeclaration; |
| import org.eclipse.jdt.core.dom.MarkerAnnotation; |
| import org.eclipse.jdt.core.dom.MemberValuePair; |
| import org.eclipse.jdt.core.dom.MethodDeclaration; |
| import org.eclipse.jdt.core.dom.Modifier; |
| import org.eclipse.jdt.core.dom.Name; |
| import org.eclipse.jdt.core.dom.NormalAnnotation; |
| import org.eclipse.jdt.core.dom.PackageDeclaration; |
| import org.eclipse.jdt.core.dom.ParameterizedType; |
| import org.eclipse.jdt.core.dom.QualifiedName; |
| import org.eclipse.jdt.core.dom.QualifiedType; |
| import org.eclipse.jdt.core.dom.SimpleName; |
| import org.eclipse.jdt.core.dom.SimpleType; |
| import org.eclipse.jdt.core.dom.SingleMemberAnnotation; |
| import org.eclipse.jdt.core.dom.SingleVariableDeclaration; |
| import org.eclipse.jdt.core.dom.Statement; |
| import org.eclipse.jdt.core.dom.Type; |
| import org.eclipse.jdt.core.dom.TypeDeclaration; |
| import org.eclipse.jdt.core.dom.TypeParameter; |
| import org.eclipse.jdt.core.dom.VariableDeclarationFragment; |
| import org.eclipse.jdt.core.dom.VariableDeclarationStatement; |
| import org.eclipse.jdt.core.dom.WildcardType; |
| |
| public class ASTConverter15Test extends ConverterTestSetup { |
| |
| public ASTConverter15Test(String name) { |
| super(name); |
| } |
| |
| public static Test suite() { |
| if (true) { |
| return new Suite(ASTConverter15Test.class); |
| } |
| TestSuite suite = new Suite(ASTConverter15Test.class.getName()); |
| suite.addTest(new ASTConverter15Test("test0032")); |
| return suite; |
| } |
| |
| public void test0001() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0001", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List types = compilationUnit.types(); |
| assertEquals("Wrong number of types", 1, types.size()); |
| AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(0); |
| assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType()); |
| TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration; |
| List modifiers = typeDeclaration2.modifiers(); |
| assertEquals("Wrong number of modifiers", 1, modifiers.size()); |
| Modifier modifier = (Modifier) modifiers.get(0); |
| checkSourceRange(modifier, "public", source); |
| |
| ASTNode node = getASTNode(compilationUnit, 0, 0); |
| assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType()); |
| FieldDeclaration fieldDeclaration = (FieldDeclaration) node; |
| modifiers = fieldDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 3, modifiers.size()); |
| modifier = (Modifier) modifiers.get(0); |
| checkSourceRange(modifier, "public", source); |
| modifier = (Modifier) modifiers.get(1); |
| checkSourceRange(modifier, "static", source); |
| modifier = (Modifier) modifiers.get(2); |
| checkSourceRange(modifier, "final", source); |
| |
| node = getASTNode(compilationUnit, 0, 1); |
| assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
| MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
| modifiers = methodDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| modifier = (Modifier) modifiers.get(0); |
| checkSourceRange(modifier, "private", source); |
| modifier = (Modifier) modifiers.get(1); |
| checkSourceRange(modifier, "static", source); |
| List parameters = methodDeclaration.parameters(); |
| assertEquals("Wrong number of parameters", 1, parameters.size()); |
| SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0); |
| modifiers = variableDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 1, modifiers.size()); |
| modifier = (Modifier) modifiers.get(0); |
| checkSourceRange(modifier, "final", source); |
| |
| node = getASTNode(compilationUnit, 0, 2); |
| assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
| methodDeclaration = (MethodDeclaration) node; |
| modifiers = methodDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| modifier = (Modifier) modifiers.get(0); |
| checkSourceRange(modifier, "public", source); |
| modifier = (Modifier) modifiers.get(1); |
| checkSourceRange(modifier, "static", source); |
| } |
| |
| public void test0002() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0002", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| } |
| |
| public void test0003() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0003", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List types = compilationUnit.types(); |
| assertEquals("Wrong number of types", 3, types.size()); |
| AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(2); |
| assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType()); |
| TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration; |
| List modifiers = typeDeclaration2.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| ASTNode modifier = (ASTNode) modifiers.get(0); |
| checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\"))", source); |
| assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType()); |
| SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier; |
| checkSourceRange(annotation.getTypeName(), "Author", source); |
| Expression value = annotation.getValue(); |
| assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType()); |
| NormalAnnotation normalAnnotation = (NormalAnnotation) value; |
| checkSourceRange(normalAnnotation.getTypeName(), "Name", source); |
| List values = normalAnnotation.values(); |
| assertEquals("wrong size", 2, values.size()); |
| MemberValuePair memberValuePair = (MemberValuePair) values.get(0); |
| checkSourceRange(memberValuePair, "first=\"Joe\"", source); |
| checkSourceRange(memberValuePair.getName(), "first", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source); |
| memberValuePair = (MemberValuePair) values.get(1); |
| checkSourceRange(memberValuePair, "last=\"Hacker\"", source); |
| checkSourceRange(memberValuePair.getName(), "last", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source); |
| modifier = (ASTNode) modifiers.get(1); |
| checkSourceRange(modifier, "public", source); |
| } |
| |
| public void test0004() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0004", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List types = compilationUnit.types(); |
| assertEquals("Wrong number of types", 3, types.size()); |
| AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(2); |
| assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType()); |
| TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration; |
| List modifiers = typeDeclaration2.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| ASTNode modifier = (ASTNode) modifiers.get(1); |
| checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\"))", source); |
| assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType()); |
| SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier; |
| checkSourceRange(annotation.getTypeName(), "Author", source); |
| Expression value = annotation.getValue(); |
| assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType()); |
| NormalAnnotation normalAnnotation = (NormalAnnotation) value; |
| checkSourceRange(normalAnnotation.getTypeName(), "Name", source); |
| List values = normalAnnotation.values(); |
| assertEquals("wrong size", 2, values.size()); |
| MemberValuePair memberValuePair = (MemberValuePair) values.get(0); |
| checkSourceRange(memberValuePair, "first=\"Joe\"", source); |
| checkSourceRange(memberValuePair.getName(), "first", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source); |
| memberValuePair = (MemberValuePair) values.get(1); |
| checkSourceRange(memberValuePair, "last=\"Hacker\"", source); |
| checkSourceRange(memberValuePair.getName(), "last", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source); |
| modifier = (ASTNode) modifiers.get(0); |
| checkSourceRange(modifier, "public", source); |
| } |
| |
| public void test0005() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0005", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List types = compilationUnit.types(); |
| assertEquals("Wrong number of types", 4, types.size()); |
| AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(3); |
| assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType()); |
| TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration; |
| List modifiers = typeDeclaration2.modifiers(); |
| assertEquals("Wrong number of modifiers", 3, modifiers.size()); |
| ASTNode modifier = (ASTNode) modifiers.get(0); |
| checkSourceRange(modifier, "@Retention", source); |
| assertEquals("wrong type", ASTNode.MARKER_ANNOTATION, modifier.getNodeType()); |
| MarkerAnnotation markerAnnotation = (MarkerAnnotation) modifier; |
| checkSourceRange(markerAnnotation.getTypeName(), "Retention", source); |
| modifier = (ASTNode) modifiers.get(2); |
| checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\", age=32))", source); |
| assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType()); |
| SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier; |
| checkSourceRange(annotation.getTypeName(), "Author", source); |
| Expression value = annotation.getValue(); |
| assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType()); |
| NormalAnnotation normalAnnotation = (NormalAnnotation) value; |
| checkSourceRange(normalAnnotation.getTypeName(), "Name", source); |
| List values = normalAnnotation.values(); |
| assertEquals("wrong size", 3, values.size()); |
| MemberValuePair memberValuePair = (MemberValuePair) values.get(0); |
| checkSourceRange(memberValuePair, "first=\"Joe\"", source); |
| checkSourceRange(memberValuePair.getName(), "first", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source); |
| memberValuePair = (MemberValuePair) values.get(1); |
| checkSourceRange(memberValuePair, "last=\"Hacker\"", source); |
| checkSourceRange(memberValuePair.getName(), "last", source); |
| checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source); |
| memberValuePair = (MemberValuePair) values.get(2); |
| checkSourceRange(memberValuePair, "age=32", source); |
| checkSourceRange(memberValuePair.getName(), "age", source); |
| checkSourceRange(memberValuePair.getValue(), "32", source); |
| modifier = (ASTNode) modifiers.get(1); |
| checkSourceRange(modifier, "public", source); |
| |
| typeDeclaration = (AbstractTypeDeclaration) types.get(0); |
| assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_DECLARATION, typeDeclaration.getNodeType()); |
| AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) typeDeclaration; |
| List bodyDeclarations = annotationTypeDeclaration.bodyDeclarations(); |
| assertEquals("Wrong size", 3, bodyDeclarations.size()); |
| BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); |
| assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, bodyDeclaration.getNodeType()); |
| AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration = (AnnotationTypeMemberDeclaration) bodyDeclaration; |
| checkSourceRange(annotationTypeMemberDeclaration, "String first() default \"Joe\";", source); |
| Expression expression = annotationTypeMemberDeclaration.getDefault(); |
| checkSourceRange(expression, "\"Joe\"", source); |
| bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(2); |
| assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, bodyDeclaration.getNodeType()); |
| annotationTypeMemberDeclaration = (AnnotationTypeMemberDeclaration) bodyDeclaration; |
| checkSourceRange(annotationTypeMemberDeclaration, "int age();", source); |
| expression = annotationTypeMemberDeclaration.getDefault(); |
| assertNull("Got a default", expression); |
| } |
| |
| public void test0006() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0006", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| PackageDeclaration packageDeclaration = compilationUnit.getPackage(); |
| assertNotNull("No package declaration", packageDeclaration); |
| checkSourceRange(packageDeclaration, "@Retention package test0006;", source); |
| List annotations = packageDeclaration.annotations(); |
| assertEquals("Wrong size", 1, annotations.size()); |
| Annotation annotation = (Annotation) annotations.get(0); |
| checkSourceRange(annotation, "@Retention", source); |
| assertEquals("Not a marker annotation", annotation.getNodeType(), ASTNode.MARKER_ANNOTATION); |
| MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation; |
| checkSourceRange(markerAnnotation.getTypeName(), "Retention", source); |
| } |
| |
| public void test0007() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0007", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List imports = compilationUnit.imports(); |
| assertEquals("Wrong size", 2, imports.size()); |
| ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0); |
| checkSourceRange(importDeclaration, "import java.util.*;", source); |
| assertFalse("is static", importDeclaration.isStatic()); |
| importDeclaration = (ImportDeclaration) imports.get(1); |
| checkSourceRange(importDeclaration, "import static java.io.File.*;", source); |
| assertTrue("not static", importDeclaration.isStatic()); |
| } |
| |
| public void test0008() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0008", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runConversion(AST.JLS2, sourceUnit, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| List imports = compilationUnit.imports(); |
| assertEquals("Wrong size", 2, imports.size()); |
| ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(1); |
| assertTrue("Not malformed", isMalformed(importDeclaration)); |
| } |
| |
| public void test0009() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0009", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 0, 0, 0); |
| assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT); |
| EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; |
| checkSourceRange(enhancedForStatement, "for (String s : args) {System.out.println(s);}", source); |
| SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter(); |
| checkSourceRange(singleVariableDeclaration, "String s", source); |
| Type type = singleVariableDeclaration.getType(); |
| checkSourceRange(type, "String", source); |
| SimpleName simpleName = singleVariableDeclaration.getName(); |
| assertEquals("Wrong name", "s", simpleName.getIdentifier()); |
| checkSourceRange(simpleName, "s", source); |
| Expression expression = enhancedForStatement.getExpression(); |
| checkSourceRange(expression, "args", source); |
| Statement body = enhancedForStatement.getBody(); |
| checkSourceRange(body, "{System.out.println(s);}", source); |
| } |
| |
| public void test0010() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0010", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 1, 0, 0); |
| assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT); |
| EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; |
| checkSourceRange(enhancedForStatement, "for (@Foo final String s : args) {System.out.println(s);}", source); |
| SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter(); |
| checkSourceRange(singleVariableDeclaration, "@Foo final String s", source); |
| SimpleName simpleName = singleVariableDeclaration.getName(); |
| List modifiers = singleVariableDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0); |
| checkSourceRange((ASTNode) modifier, "@Foo", source); |
| modifier = (IExtendedModifier) modifiers.get(1); |
| checkSourceRange((ASTNode) modifier, "final", source); |
| Type type = singleVariableDeclaration.getType(); |
| checkSourceRange(type, "String", source); |
| assertEquals("Wrong name", "s", simpleName.getIdentifier()); |
| checkSourceRange(simpleName, "s", source); |
| Expression expression = enhancedForStatement.getExpression(); |
| checkSourceRange(expression, "args", source); |
| Statement body = enhancedForStatement.getBody(); |
| checkSourceRange(body, "{System.out.println(s);}", source); |
| } |
| |
| public void test0011() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0011", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 1, 0, 0); |
| assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT); |
| EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node; |
| checkSourceRange(enhancedForStatement, "for (@Foo final String s[] : args) {System.out.println(s);}", source); |
| SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter(); |
| checkSourceRange(singleVariableDeclaration, "@Foo final String s[]", source); |
| SimpleName simpleName = singleVariableDeclaration.getName(); |
| List modifiers = singleVariableDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0); |
| checkSourceRange((ASTNode) modifier, "@Foo", source); |
| modifier = (IExtendedModifier) modifiers.get(1); |
| checkSourceRange((ASTNode) modifier, "final", source); |
| assertEquals("Wrong dimension", 1, singleVariableDeclaration.getExtraDimensions()); |
| Type type = singleVariableDeclaration.getType(); |
| checkSourceRange(type, "String", source); |
| assertEquals("Wrong name", "s", simpleName.getIdentifier()); |
| checkSourceRange(simpleName, "s", source); |
| Expression expression = enhancedForStatement.getExpression(); |
| checkSourceRange(expression, "args", source); |
| Statement body = enhancedForStatement.getBody(); |
| checkSourceRange(body, "{System.out.println(s);}", source); |
| } |
| |
| public void test0012() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0012", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runConversion(AST.JLS3, sourceUnit, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 1, 0); |
| assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); |
| MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
| List parameters = methodDeclaration.parameters(); |
| assertEquals("wrong size", 1, parameters.size()); |
| SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0); |
| checkSourceRange(parameter, "@Foo final String[][]... args", source); |
| List modifiers = parameter.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| ASTNode modifier = (ASTNode) modifiers.get(0); |
| checkSourceRange(modifier, "@Foo", source); |
| modifier = (ASTNode) modifiers.get(1); |
| checkSourceRange(modifier, "final", source); |
| assertEquals("Wrong name", "args", parameter.getName().getIdentifier()); |
| assertTrue("Not a variable argument", parameter.isVarargs()); |
| } |
| |
| public void test0013() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0013", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| // TODO NPE when resolveBindings = true |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 0); |
| assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); |
| TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
| SimpleName name = typeDeclaration.getName(); |
| assertEquals("Wrong name", "Convertible", name.getIdentifier()); |
| checkSourceRange(name, "Convertible", source); |
| List typeParameters = typeDeclaration.typeParameters(); |
| assertEquals("Wrong size", 1, typeParameters.size()); |
| TypeParameter typeParameter = (TypeParameter) typeParameters.get(0); |
| checkSourceRange(typeParameter, "T", source); |
| checkSourceRange(typeParameter.getName(), "T", source); |
| node = getASTNode(compilationUnit, 1); |
| assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); |
| typeDeclaration = (TypeDeclaration) node; |
| name = typeDeclaration.getName(); |
| assertEquals("Wrong name", "ReprChange", name.getIdentifier()); |
| checkSourceRange(name, "ReprChange", source); |
| typeParameters = typeDeclaration.typeParameters(); |
| assertEquals("Wrong size", 2, typeParameters.size()); |
| typeParameter = (TypeParameter) typeParameters.get(0); |
| checkSourceRange(typeParameter.getName(), "A", source); |
| checkSourceRange(typeParameter, "A extends Convertible<B>", source); |
| typeParameter = (TypeParameter) typeParameters.get(1); |
| checkSourceRange(typeParameter.getName(), "B", source); |
| checkSourceRange(typeParameter, "B extends Convertible<A>", source); |
| List typeBounds = typeParameter.typeBounds(); |
| assertEquals("Wrong size", 1, typeBounds.size()); |
| Type typeBound = (Type) typeBounds.get(0); |
| checkSourceRange(typeBound, "Convertible<A>", source); |
| assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeBound.getNodeType()); |
| ParameterizedType parameterizedType = (ParameterizedType) typeBound; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "A", source); |
| } |
| |
| public void test0014() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0014", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| ASTNode node = getASTNode(compilationUnit, 1); |
| assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); |
| TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
| SimpleName name = typeDeclaration.getName(); |
| assertEquals("Wrong name", "X", name.getIdentifier()); |
| checkSourceRange(name, "X", source); |
| List typeParameters = typeDeclaration.typeParameters(); |
| assertEquals("Wrong size", 1, typeParameters.size()); |
| TypeParameter typeParameter = (TypeParameter) typeParameters.get(0); |
| checkSourceRange(typeParameter.getName(), "A", source); |
| checkSourceRange(typeParameter, "A extends Convertible<Convertible<A>>", source); |
| List typeBounds = typeParameter.typeBounds(); |
| assertEquals("Wrong size", 1, typeBounds.size()); |
| Type typeBound = (Type) typeBounds.get(0); |
| checkSourceRange(typeBound, "Convertible<Convertible<A>>", source); |
| assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeBound.getNodeType()); |
| ParameterizedType parameterizedType = (ParameterizedType) typeBound; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "Convertible<A>", source); |
| assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeArgument.getNodeType()); |
| parameterizedType = (ParameterizedType) typeArgument; |
| typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "A", source); |
| } |
| |
| public void test0015() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0015", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0); |
| assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); |
| TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
| SimpleName name = typeDeclaration.getName(); |
| assertEquals("Wrong name", "X", name.getIdentifier()); |
| checkSourceRange(name, "X", source); |
| List typeParameters = typeDeclaration.typeParameters(); |
| assertEquals("Wrong size", 1, typeParameters.size()); |
| TypeParameter typeParameter = (TypeParameter) typeParameters.get(0); |
| checkSourceRange(typeParameter.getName(), "A", source); |
| checkSourceRange(typeParameter, "A extends Object & java.io.Serializable & Comparable", source); |
| List typeBounds = typeParameter.typeBounds(); |
| assertEquals("Wrong size", 3, typeBounds.size()); |
| Type typeBound = (Type) typeBounds.get(0); |
| checkSourceRange(typeBound, "Object", source); |
| typeBound = (Type) typeBounds.get(1); |
| checkSourceRange(typeBound, "java.io.Serializable", source); |
| typeBound = (Type) typeBounds.get(2); |
| checkSourceRange(typeBound, "Comparable", source); |
| } |
| |
| public void test0016() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0016", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| // char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| } |
| |
| public void test0017() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0017", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 1, 0, 0); |
| assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); |
| VariableDeclarationStatement statement = (VariableDeclarationStatement) node; |
| Type type = statement.getType(); |
| assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "Integer", source); |
| Type innerType = parameterizedType.getType(); |
| assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE); |
| QualifiedType qualifiedType = (QualifiedType) innerType; |
| checkSourceRange(qualifiedType.getName(), "B", source); |
| Type qualifier = qualifiedType.getQualifier(); |
| checkSourceRange(qualifier, "test0017.A<String>", source); |
| assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType2 = (ParameterizedType) qualifier; |
| typeArguments = parameterizedType2.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "String", source); |
| innerType = parameterizedType2.getType(); |
| assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE); |
| SimpleType simpleType = (SimpleType) innerType; |
| checkSourceRange(simpleType, "test0017.A", source); |
| Name name = simpleType.getName(); |
| assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME); |
| QualifiedName qualifiedName = (QualifiedName) name; |
| checkSourceRange(qualifiedName.getQualifier(), "test0017", source); |
| checkSourceRange(qualifiedName.getName(), "A", source); |
| } |
| |
| public void test0018() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0018", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 1, 0, 0); |
| assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); |
| VariableDeclarationStatement statement = (VariableDeclarationStatement) node; |
| Type type = statement.getType(); |
| assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "Float", source); |
| Type innerType = parameterizedType.getType(); |
| assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE); |
| QualifiedType qualifiedType = (QualifiedType) innerType; |
| checkSourceRange(qualifiedType.getName(), "C", source); |
| Type qualifier = qualifiedType.getQualifier(); |
| checkSourceRange(qualifier, "test0018.A<String>.B", source); |
| assertTrue("Not a qualified type", qualifier.getNodeType() == ASTNode.QUALIFIED_TYPE); |
| qualifiedType = (QualifiedType) qualifier; |
| checkSourceRange(qualifiedType.getName(), "B", source); |
| qualifier = qualifiedType.getQualifier(); |
| checkSourceRange(qualifier, "test0018.A<String>", source); |
| assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType2 = (ParameterizedType) qualifier; |
| typeArguments = parameterizedType2.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "String", source); |
| innerType = parameterizedType2.getType(); |
| assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE); |
| SimpleType simpleType = (SimpleType) innerType; |
| checkSourceRange(simpleType, "test0018.A", source); |
| Name name = simpleType.getName(); |
| assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME); |
| QualifiedName qualifiedName = (QualifiedName) name; |
| checkSourceRange(qualifiedName.getQualifier(), "test0018", source); |
| checkSourceRange(qualifiedName.getName(), "A", source); |
| } |
| |
| public void test0019() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0019", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 1, 0, 0); |
| assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); |
| VariableDeclarationStatement statement = (VariableDeclarationStatement) node; |
| Type type = statement.getType(); |
| assertTrue("Not a qualified type", type.getNodeType() == ASTNode.QUALIFIED_TYPE); |
| QualifiedType qualifiedType = (QualifiedType) type; |
| checkSourceRange(qualifiedType.getName(), "C", source); |
| Type qualifier = qualifiedType.getQualifier(); |
| checkSourceRange(qualifier, "test0019.A<String>.B<Integer>", source); |
| assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) qualifier; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "Integer", source); |
| Type innerType = parameterizedType.getType(); |
| assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE); |
| qualifiedType = (QualifiedType) innerType; |
| checkSourceRange(qualifiedType.getName(), "B", source); |
| qualifier = qualifiedType.getQualifier(); |
| checkSourceRange(qualifier, "test0019.A<String>", source); |
| assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType2 = (ParameterizedType) qualifier; |
| typeArguments = parameterizedType2.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "String", source); |
| innerType = parameterizedType2.getType(); |
| assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE); |
| SimpleType simpleType = (SimpleType) innerType; |
| checkSourceRange(simpleType, "test0019.A", source); |
| Name name = simpleType.getName(); |
| assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME); |
| QualifiedName qualifiedName = (QualifiedName) name; |
| checkSourceRange(qualifiedName.getQualifier(), "test0019", source); |
| checkSourceRange(qualifiedName.getName(), "A", source); |
| } |
| |
| public void test0020() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0020", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 0); |
| assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); |
| MethodDeclaration declaration = (MethodDeclaration) node; |
| List parameters = declaration.parameters(); |
| assertEquals("Wrong size", 1, parameters.size()); |
| SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0); |
| Type type = singleVariableDeclaration.getType(); |
| assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "?", source); |
| } |
| |
| public void test0021() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0021", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 0); |
| assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); |
| MethodDeclaration declaration = (MethodDeclaration) node; |
| List parameters = declaration.parameters(); |
| assertEquals("Wrong size", 1, parameters.size()); |
| SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0); |
| Type type = singleVariableDeclaration.getType(); |
| assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "? extends E", source); |
| assertTrue("Not a wildcard type", typeArgument.getNodeType() == ASTNode.WILDCARD_TYPE); |
| WildcardType wildcardType = (WildcardType) typeArgument; |
| Type bound = wildcardType.getBound(); |
| checkSourceRange(bound, "E", source); |
| assertTrue("Not an upper bound", wildcardType.isUpperBound()); |
| } |
| |
| public void test0022() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0022", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 0); |
| assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); |
| MethodDeclaration declaration = (MethodDeclaration) node; |
| List parameters = declaration.parameters(); |
| assertEquals("Wrong size", 1, parameters.size()); |
| SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0); |
| Type type = singleVariableDeclaration.getType(); |
| assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| List typeArguments = parameterizedType.typeArguments(); |
| assertEquals("Wrong size", 1, typeArguments.size()); |
| Type typeArgument = (Type) typeArguments.get(0); |
| checkSourceRange(typeArgument, "? super E", source); |
| assertTrue("Not a wildcard type", typeArgument.getNodeType() == ASTNode.WILDCARD_TYPE); |
| WildcardType wildcardType = (WildcardType) typeArgument; |
| Type bound = wildcardType.getBound(); |
| checkSourceRange(bound, "E", source); |
| assertFalse("Is an upper bound", wildcardType.isUpperBound()); |
| } |
| |
| public void test0023() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0023", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 5); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
| MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
| assertEquals("Wrong name", "zip", methodDeclaration.getName().getIdentifier()); |
| List typeParameters = methodDeclaration.typeParameters(); |
| assertNotNull("No type parameters", typeParameters); |
| assertEquals("Wrong size", 1, typeParameters.size()); |
| TypeParameter typeParameter = (TypeParameter) typeParameters.get(0); |
| checkSourceRange(typeParameter, "T", source); |
| } |
| |
| public void test0024() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0024", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 1, 0); |
| assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); |
| VariableDeclarationStatement declarationStatement = (VariableDeclarationStatement) node; |
| List fragments = declarationStatement.fragments(); |
| assertEquals("wrong size", 1, fragments.size()); |
| VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); |
| Expression expression = fragment.getInitializer(); |
| assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType()); |
| ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression; |
| List typeArguments = classInstanceCreation.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| Type type = (Type) typeArguments.get(0); |
| checkSourceRange(type, "String", source); |
| } |
| |
| public void test0025() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0025", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 0, 0); |
| assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType()); |
| ConstructorInvocation constructorInvocation = (ConstructorInvocation) node; |
| List typeArguments = constructorInvocation.typeArguments(); |
| assertEquals("wrong size", 1, typeArguments.size()); |
| Type type = (Type) typeArguments.get(0); |
| checkSourceRange(type, "E", source); |
| } |
| |
| public void test0026() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0026", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode node = getASTNode(compilationUnit, 0); |
| assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType()); |
| EnumDeclaration enumDeclaration = (EnumDeclaration) node; |
| List modifiers = enumDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 2, modifiers.size()); |
| IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0); |
| assertTrue("Not a modifier", extendedModifier instanceof Modifier); |
| Modifier modifier = (Modifier) extendedModifier; |
| checkSourceRange(modifier, "public", source); |
| extendedModifier = (IExtendedModifier) modifiers.get(1); |
| assertTrue("Not a modifier", extendedModifier instanceof Modifier); |
| modifier = (Modifier) extendedModifier; |
| checkSourceRange(modifier, "abstract", source); |
| assertEquals("wrong name", "X", enumDeclaration.getName().getIdentifier()); |
| EnumConstantDeclaration[] enumConstantDeclarations = enumDeclaration.getEnumConstants(); |
| assertEquals("wrong size", 4, enumConstantDeclarations.length); |
| List bodyDeclarations = enumDeclaration.bodyDeclarations(); |
| assertEquals("wrong size", 6, bodyDeclarations.size()); |
| EnumConstantDeclaration enumConstantDeclaration = enumConstantDeclarations[0]; |
| checkSourceRange(enumConstantDeclaration.getName(), "PLUS", source); |
| checkSourceRange(enumConstantDeclaration, "PLUS {\n" + |
| " double eval(double x, double y) { return x + y; }\n" + |
| " }", source); |
| assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size()); |
| bodyDeclarations = enumConstantDeclaration.bodyDeclarations(); |
| assertEquals("wrong size", 1, bodyDeclarations.size()); |
| BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); |
| MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; |
| checkSourceRange(methodDeclaration.getName(), "eval", source); |
| checkSourceRange(methodDeclaration, "double eval(double x, double y) { return x + y; }", source); |
| assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size()); |
| |
| enumConstantDeclaration = enumConstantDeclarations[1]; |
| checkSourceRange(enumConstantDeclaration.getName(), "MINUS", source); |
| checkSourceRange(enumConstantDeclaration, "MINUS {\n" + |
| " double eval(double x, double y) { return x - y; }\n" + |
| " }", source); |
| bodyDeclarations = enumConstantDeclaration.bodyDeclarations(); |
| assertEquals("wrong size", 1, bodyDeclarations.size()); |
| bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); |
| methodDeclaration = (MethodDeclaration) bodyDeclaration; |
| checkSourceRange(methodDeclaration.getName(), "eval", source); |
| checkSourceRange(methodDeclaration, "double eval(double x, double y) { return x - y; }", source); |
| assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size()); |
| |
| enumConstantDeclaration = enumConstantDeclarations[2]; |
| checkSourceRange(enumConstantDeclaration.getName(), "TIMES", source); |
| checkSourceRange(enumConstantDeclaration, "TIMES {\n" + |
| " double eval(double x, double y) { return x * y; }\n" + |
| " }", source); |
| bodyDeclarations = enumConstantDeclaration.bodyDeclarations(); |
| assertEquals("wrong size", 1, bodyDeclarations.size()); |
| bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); |
| methodDeclaration = (MethodDeclaration) bodyDeclaration; |
| checkSourceRange(methodDeclaration.getName(), "eval", source); |
| checkSourceRange(methodDeclaration, "double eval(double x, double y) { return x * y; }", source); |
| assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size()); |
| |
| enumConstantDeclaration = enumConstantDeclarations[3]; |
| checkSourceRange(enumConstantDeclaration.getName(), "DIVIDED_BY", source); |
| checkSourceRange(enumConstantDeclaration, "DIVIDED_BY {\n" + |
| " double eval(double x, double y) { return x / y; }\n" + |
| " }", source); |
| bodyDeclarations = enumConstantDeclaration.bodyDeclarations(); |
| assertEquals("wrong size", 1, bodyDeclarations.size()); |
| bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType()); |
| methodDeclaration = (MethodDeclaration) bodyDeclaration; |
| checkSourceRange(methodDeclaration.getName(), "eval", source); |
| checkSourceRange(methodDeclaration, "double eval(double x, double y) { return x / y; }", source); |
| assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size()); |
| } |
| |
| public void test0027() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0027", "Coin.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType()); |
| EnumDeclaration enumDeclaration = (EnumDeclaration) node; |
| List modifiers = enumDeclaration.modifiers(); |
| assertEquals("Wrong number of modifiers", 1, modifiers.size()); |
| IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0); |
| assertTrue("Not a modifier", extendedModifier instanceof Modifier); |
| Modifier modifier = (Modifier) extendedModifier; |
| checkSourceRange(modifier, "public", source); |
| assertEquals("wrong name", "Coin", enumDeclaration.getName().getIdentifier()); |
| EnumConstantDeclaration[] enumConstantDeclarations = enumDeclaration.getEnumConstants(); |
| assertEquals("wrong size", 4, enumConstantDeclarations.length); |
| EnumConstantDeclaration enumConstantDeclaration = enumConstantDeclarations[0]; |
| checkSourceRange(enumConstantDeclaration.getName(), "PENNY", source); |
| checkSourceRange(enumConstantDeclaration, "PENNY(1)", source); |
| List arguments = enumConstantDeclaration.arguments(); |
| assertEquals("wrong size", 1, arguments.size()); |
| Expression argument = (Expression) arguments.get(0); |
| checkSourceRange(argument, "1", source); |
| assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType()); |
| |
| enumConstantDeclaration = enumConstantDeclarations[1]; |
| checkSourceRange(enumConstantDeclaration.getName(), "NICKEL", source); |
| checkSourceRange(enumConstantDeclaration, "NICKEL(5)", source); |
| arguments = enumConstantDeclaration.arguments(); |
| assertEquals("wrong size", 1, arguments.size()); |
| argument = (Expression) arguments.get(0); |
| checkSourceRange(argument, "5", source); |
| assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType()); |
| |
| enumConstantDeclaration = enumConstantDeclarations[2]; |
| checkSourceRange(enumConstantDeclaration.getName(), "DIME", source); |
| checkSourceRange(enumConstantDeclaration, "DIME(10)", source); |
| arguments = enumConstantDeclaration.arguments(); |
| assertEquals("wrong size", 1, arguments.size()); |
| argument = (Expression) arguments.get(0); |
| checkSourceRange(argument, "10", source); |
| assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType()); |
| |
| |
| enumConstantDeclaration = enumConstantDeclarations[3]; |
| checkSourceRange(enumConstantDeclaration.getName(), "QUARTER", source); |
| checkSourceRange(enumConstantDeclaration, "QUARTER(25)", source); |
| arguments = enumConstantDeclaration.arguments(); |
| assertEquals("wrong size", 1, arguments.size()); |
| argument = (Expression) arguments.get(0); |
| checkSourceRange(argument, "25", source); |
| assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType()); |
| } |
| |
| public void test0028() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0028", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode node = getASTNode(compilationUnit, 0, 0); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
| MethodDeclaration methodDeclaration = (MethodDeclaration) node; |
| checkSourceRange(methodDeclaration.getName(), "foo", source); |
| checkSourceRange(methodDeclaration, "void foo() {\n" + |
| " if (args.length < 2) {\n" + |
| " System.out.println(\"Usage: X <double> <double>\");\n" + |
| " return;\n" + |
| " }\n" + |
| " double x = Double.parseDouble(args[0]);\n" + |
| " double y = Double.parseDouble(args[1]);\n" + |
| "\n" + |
| " for (X op : X.values())\n" + |
| " System.out.println(x + \" \" + op + \" \" + y + \" = \" + op.eval(x, y));\n" + |
| " }", source); |
| node = getASTNode(compilationUnit, 0, 1); |
| assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); |
| methodDeclaration = (MethodDeclaration) node; |
| checkSourceRange(methodDeclaration.getName(), "bar", source); |
| checkSourceRange(methodDeclaration, "abstract double bar(double x, double y);", source); |
| } |
| |
| public void test0029() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0029", "ArrayList.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| } |
| |
| public void _test0030() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0030", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 0, 0, 0); |
| assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType()); |
| checkSourceRange(node, "<X>this();", source); |
| } |
| |
| public void test0031() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0031", "E.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| } |
| |
| public void test0032() throws JavaModelException { |
| ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0032", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| char[] source = sourceUnit.getSource().toCharArray(); |
| ASTNode result = runJLS3Conversion(sourceUnit, false, true); |
| assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); |
| CompilationUnit compilationUnit = (CompilationUnit) result; |
| assertEquals("wrong size", 0, compilationUnit.getProblems().length); |
| ASTNode node = getASTNode(compilationUnit, 1); |
| assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); |
| TypeDeclaration typeDeclaration = (TypeDeclaration) node; |
| List superInterfaces = typeDeclaration.superInterfaceTypes(); |
| assertEquals("wrong size", 1, superInterfaces.size()); |
| Type type = (Type) superInterfaces.get(0); |
| assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, type.getNodeType()); |
| ParameterizedType parameterizedType = (ParameterizedType) type; |
| Type type2 = parameterizedType.getType(); |
| checkSourceRange(type2, "C", source); |
| } |
| } |
| |