1.1 --- a/test/tools/javac/processing/model/element/TestResourceVariable.java Mon Jan 31 19:06:32 2011 -0800 1.2 +++ b/test/tools/javac/processing/model/element/TestResourceVariable.java Tue Feb 01 10:11:05 2011 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -23,7 +23,7 @@ 1.11 1.12 /* 1.13 * @test 1.14 - * @bug 6911256 6964740 6967842 1.15 + * @bug 6911256 6964740 6967842 6961571 1.16 * @summary Test that the resource variable kind is appropriately set 1.17 * @author Joseph D. Darcy 1.18 * @library ../../../lib 1.19 @@ -31,8 +31,6 @@ 1.20 * @compile -processor TestResourceVariable -proc:only TestResourceVariable.java 1.21 */ 1.22 1.23 -// Bug should be filed for this misbehavior 1.24 - 1.25 import java.io.*; 1.26 import javax.annotation.processing.*; 1.27 import javax.lang.model.*; 1.28 @@ -82,6 +80,33 @@ 1.29 try(TestResourceVariable trv1 = this; TestResourceVariable trv2 = trv1) {} 1.30 } 1.31 1.32 + /** 1.33 + * Verify that a resource variable modeled as an element behaves 1.34 + * as expected under 6 and 7 specific visitors. 1.35 + */ 1.36 + private static void testResourceVariable(Element element) { 1.37 + ElementVisitor visitor6 = new ElementKindVisitor6<Void, Void>() {}; 1.38 + 1.39 + try { 1.40 + visitor6.visit(element); 1.41 + throw new RuntimeException("Expected UnknownElementException not thrown."); 1.42 + } catch (UnknownElementException uee) { 1.43 + ; // Expected. 1.44 + } 1.45 + 1.46 + ElementKindVisitor7 visitor7 = new ElementKindVisitor7<Object, Void>() { 1.47 + @Override 1.48 + public Object visitVariableAsResourceVariable(VariableElement e, 1.49 + Void p) { 1.50 + return e; // a non-null value 1.51 + } 1.52 + }; 1.53 + 1.54 + if (visitor7.visit(element) == null) { 1.55 + throw new RuntimeException("Null result of resource variable visitation."); 1.56 + } 1.57 + } 1.58 + 1.59 class ResourceVariableScanner extends TreeScanner<Void, CompilationUnitTree> { 1.60 private Trees trees; 1.61 1.62 @@ -92,17 +117,14 @@ 1.63 @Override 1.64 public Void visitVariable(VariableTree node, CompilationUnitTree cu) { 1.65 Element element = trees.getElement(trees.getPath(cu, node)); 1.66 - if (element == null) { 1.67 - System.out.println("Null variable element: " + node); 1.68 - } else { 1.69 - System.out.println("Name: " + element.getSimpleName() + 1.70 - "\tKind: " + element.getKind()); 1.71 - } 1.72 - if (element != null && 1.73 - element.getKind() == ElementKind.RESOURCE_VARIABLE) { 1.74 + 1.75 + System.out.println("Name: " + element.getSimpleName() + 1.76 + "\tKind: " + element.getKind()); 1.77 + if (element.getKind() == ElementKind.RESOURCE_VARIABLE) { 1.78 + testResourceVariable(element); 1.79 resourceVariableCount++; 1.80 } 1.81 return super.visitVariable(node, cu); 1.82 } 1.83 - } 1.84 + } 1.85 }