diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java index 5bb5733..8970e8f 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -5265,6 +5265,16 @@ public class ASTTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase * @deprecated (Uses getLeadingComment() which is deprecated) */ public void testTryStatement() { + if (this.ast.apiLevel() <= AST.JLS3) { + // node type introduced in 4.0 API + try { + final TryStatement x = this.ast.newTryStatement(); + x.resources(); + assertTrue("should not be reached if jls level <= JLS3", false); + } catch (UnsupportedOperationException e) { + // pass + } + } long previousCount = this.ast.modificationCount(); final TryStatement x = this.ast.newTryStatement(); assertTrue(this.ast.modificationCount() > previousCount); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TryStatement.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TryStatement.java index bb4b322..79575e1 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TryStatement.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TryStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -352,7 +352,7 @@ public class TryStatement extends Statement { */ public List resources() { // more efficient than just calling unsupportedIn2_3() to check - if (this.resources != null) { + if (this.resources == null) { unsupportedIn2_3(); } return this.resources; diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java index 9394af1..b53e418 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 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 @@ -1528,9 +1528,9 @@ public class NaiveASTFlattener extends ASTVisitor { public boolean visit(TryStatement node) { printIndent(); this.buffer.append("try ");//$NON-NLS-1$ - List resources = node.resources(); if (node.getAST().apiLevel() >= AST.JLS4) { - if (!node.resources().isEmpty()) { + List resources = node.resources(); + if (!resources.isEmpty()) { this.buffer.append('('); for (Iterator it = resources.iterator(); it.hasNext(); ) { VariableDeclarationExpression variable = (VariableDeclarationExpression) it.next();