Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 190034 Details for
Bug 338402
[1.7][compiler][enh] Open issues in try with resources implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch - part 2
patch.txt (text/plain), 31.53 KB, created by
Srikanth Sankaran
on 2011-03-01 08:32:00 EST
(
hide
)
Description:
Patch - part 2
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-03-01 08:32:00 EST
Size:
31.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java,v >retrieving revision 1.18.8.1 >diff -u -r1.18.8.1 ASTVisitor.java >--- compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java 31 Jan 2011 15:58:28 -0000 1.18.8.1 >+++ compiler/org/eclipse/jdt/internal/compiler/ASTVisitor.java 1 Mar 2011 13:19:23 -0000 >@@ -437,9 +437,6 @@ > public void endVisit(TryStatement tryStatement, BlockScope scope) { > // do nothing by default > } >- public void endVisit(TryStatementWithResources tryStatementWithResources, BlockScope scope) { >- // do nothing by default >- } > public void endVisit( > TypeDeclaration localTypeDeclaration, > BlockScope scope) { >@@ -885,9 +882,6 @@ > public boolean visit(TryStatement tryStatement, BlockScope scope) { > return true; // do nothing by default, keep traversing > } >- public boolean visit(TryStatementWithResources tryStatementWithResources, BlockScope scope) { >- return true; // do nothing by default, keep traversing >- } > public boolean visit( > TypeDeclaration localTypeDeclaration, > BlockScope scope) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java,v >retrieving revision 1.116.2.4 >diff -u -r1.116.2.4 TryStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 9 Feb 2011 17:05:23 -0000 1.116.2.4 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 1 Mar 2011 13:19:25 -0000 >@@ -28,6 +28,9 @@ > static final char[] SECRET_ANY_HANDLER_NAME = " anyExceptionHandler".toCharArray(); //$NON-NLS-1$ > static final char[] SECRET_RETURN_VALUE_NAME = " returnValue".toCharArray(); //$NON-NLS-1$ > >+ private static LocalDeclaration [] NO_RESOURCES = new LocalDeclaration[0]; >+ public LocalDeclaration[] resources = NO_RESOURCES; >+ > public Block tryBlock; > public Block[] catchBlocks; > >@@ -100,6 +103,9 @@ > // only try blocks initialize that member - may consider creating a > // separate class if needed > >+ for (int i = 0, max = this.resources.length; i < max; i++) { >+ flowInfo = this.resources[i].analyseCode(currentScope, handlingContext, flowInfo.copy()); >+ } > FlowInfo tryInfo; > if (this.tryBlock.isEmptyBlock()) { > tryInfo = flowInfo; >@@ -209,6 +215,9 @@ > // only try blocks initialize that member - may consider creating a > // separate class if needed > >+ for (int i = 0, max = this.resources.length; i < max; i++) { >+ flowInfo = this.resources[i].analyseCode(currentScope, handlingContext, flowInfo.copy()); >+ } > FlowInfo tryInfo; > if (this.tryBlock.isEmptyBlock()) { > tryInfo = flowInfo; >@@ -738,7 +747,18 @@ > } > > public StringBuffer printStatement(int indent, StringBuffer output) { >- printIndent(indent, output).append("try\n"); //$NON-NLS-1$ >+ int length = this.resources.length; >+ printIndent(indent, output).append("try" + (length == 0 ? "\n" : " (")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ for (int i = 0; i < length; i++) { >+ this.resources[i].printAsExpression(0, output); >+ if (i != length - 1) { >+ output.append(";\n"); //$NON-NLS-1$ >+ printIndent(indent + 2, output); >+ } >+ } >+ if (length > 0) { >+ output.append(")\n"); //$NON-NLS-1$ >+ } > this.tryBlock.printStatement(indent + 1, output); > > //catches >@@ -762,9 +782,29 @@ > // special scope for secret locals optimization. > this.scope = new BlockScope(upperScope); > >- BlockScope tryScope = new BlockScope(this.scope); > BlockScope finallyScope = null; > >+ // resolve all resources and inject them into separate scopes >+ BlockScope localScope = new BlockScope(this.scope); >+ for (int i = 0, max = this.resources.length; i < max; i++) { >+ this.resources[i].resolve(localScope); >+ LocalVariableBinding localVariableBinding = this.resources[i].binding; >+ if (localVariableBinding != null && localVariableBinding.isValidBinding()) { >+ localVariableBinding.modifiers |= ClassFileConstants.AccFinal; >+ localVariableBinding.tagBits |= TagBits.IsResource; >+ TypeBinding resourceType = localVariableBinding.type; >+ if (resourceType.isClass() || resourceType.isInterface()) { >+ if (resourceType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangAutoCloseable, false /*AutoCloseable is not a class*/) == null && resourceType.isValidBinding()) { >+ upperScope.problemReporter().resourceHasToBeAutoCloseable(resourceType, this.resources[i].type); >+ } >+ } else { >+ upperScope.problemReporter().resourceHasToBeAutoCloseable(resourceType, this.resources[i].type); >+ } >+ } >+ localScope = new BlockScope(localScope, 1); >+ } >+ BlockScope tryScope = localScope; >+ > if (this.finallyBlock != null) { > if (this.finallyBlock.isEmptyBlock()) { > if ((this.finallyBlock.bits & ASTNode.UndocumentedEmptyBlock) != 0) { >@@ -809,8 +849,16 @@ > } > this.finallyBlock.resolveUsing(finallyScope); > // force the finally scope to have variable positions shifted after its try scope and catch ones >- finallyScope.shiftScopes = new BlockScope[this.catchArguments == null ? 1 : this.catchArguments.length+1]; >- finallyScope.shiftScopes[0] = tryScope; >+ int shiftScopesLength = this.catchArguments == null ? 1 : this.catchArguments.length + 1; >+ shiftScopesLength += this.resources.length; >+ finallyScope.shiftScopes = new BlockScope[shiftScopesLength]; >+ for (int i = 0, max = this.resources.length; i < max; i++) { >+ LocalVariableBinding localVariableBinding = this.resources[i].binding; >+ if (localVariableBinding != null && localVariableBinding.isValidBinding()) { >+ finallyScope.shiftScopes[i] = localVariableBinding.declaringScope; >+ } >+ } >+ finallyScope.shiftScopes[this.resources.length] = tryScope; > } > } > this.tryBlock.resolveUsing(tryScope); >@@ -854,6 +902,10 @@ > } > public void traverse(ASTVisitor visitor, BlockScope blockScope) { > if (visitor.visit(this, blockScope)) { >+ LocalDeclaration[] localDeclarations = this.resources; >+ for (int i = 0, max = localDeclarations.length; i < max; i++) { >+ localDeclarations[i].traverse(visitor, this.scope); >+ } > this.tryBlock.traverse(visitor, this.scope); > if (this.catchArguments != null) { > for (int i = 0, max = this.catchBlocks.length; i < max; i++) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/TryStatementWithResources.java >=================================================================== >RCS file: compiler/org/eclipse/jdt/internal/compiler/ast/TryStatementWithResources.java >diff -N compiler/org/eclipse/jdt/internal/compiler/ast/TryStatementWithResources.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/TryStatementWithResources.java 1 Mar 2011 05:58:47 -0000 1.1.2.8 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,201 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2011 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 >- * >- * This is an implementation of an early-draft specification developed under the Java >- * Community Process (JCP) and is made available for testing and evaluation purposes >- * only. The code is not compatible with any specification of the JCP. >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jdt.internal.compiler.ast; >- >-import org.eclipse.jdt.internal.compiler.ASTVisitor; >-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; >-import org.eclipse.jdt.internal.compiler.codegen.BranchLabel; >-import org.eclipse.jdt.internal.compiler.impl.Constant; >-import org.eclipse.jdt.internal.compiler.lookup.BlockScope; >-import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; >-import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; >-import org.eclipse.jdt.internal.compiler.lookup.MethodScope; >-import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; >-import org.eclipse.jdt.internal.compiler.lookup.TagBits; >-import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; >-import org.eclipse.jdt.internal.compiler.lookup.TypeIds; >- >-public class TryStatementWithResources extends TryStatement { >- >- private static LocalDeclaration [] NO_RESOURCES = new LocalDeclaration[0]; >- public LocalDeclaration[] resources = NO_RESOURCES; >- >- public StringBuffer printStatement(int indent, StringBuffer output) { >- printIndent(indent, output).append("try ("); //$NON-NLS-1$ >- int length = this.resources.length; >- for (int i = 0; i < length; i++) { >- this.resources[i].printAsExpression(0, output); >- if (i != length - 1) { >- output.append(";\n"); //$NON-NLS-1$ >- printIndent(indent + 2, output); >- } >- } >- output.append(")\n"); //$NON-NLS-1$ >- this.tryBlock.printStatement(indent + 1, output); >- >- // catches >- if (this.catchBlocks != null) >- for (int i = 0; i < this.catchBlocks.length; i++) { >- output.append('\n'); >- printIndent(indent, output).append("catch ("); //$NON-NLS-1$ >- this.catchArguments[i].print(0, output).append(")\n"); //$NON-NLS-1$ >- this.catchBlocks[i].printStatement(indent + 1, output); >- } >- // finally >- if (this.finallyBlock != null) { >- output.append('\n'); >- printIndent(indent, output).append("finally\n"); //$NON-NLS-1$ >- this.finallyBlock.printStatement(indent + 1, output); >- } >- return output; >- } >- >- public void resolve(BlockScope upperScope) { >- // special scope for secret locals optimization. >- this.scope = new BlockScope(upperScope); >- >- BlockScope finallyScope = null; >- >- // resolve all resources and inject them into separate scopes >- BlockScope localScope = new BlockScope(this.scope); >- for (int i = 0, max = this.resources.length; i < max; i++) { >- this.resources[i].resolve(localScope); >- LocalVariableBinding localVariableBinding = this.resources[i].binding; >- if (localVariableBinding != null && localVariableBinding.isValidBinding()) { >- localVariableBinding.modifiers |= ClassFileConstants.AccFinal; >- localVariableBinding.tagBits |= TagBits.IsResource; >- TypeBinding resourceType = localVariableBinding.type; >- if (resourceType.isClass() || resourceType.isInterface()) { >- if (resourceType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangAutoCloseable, false /*AutoCloseable is not a class*/) == null && resourceType.isValidBinding()) { >- upperScope.problemReporter().resourceHasToBeAutoCloseable(resourceType, this.resources[i].type); >- } >- } else { >- upperScope.problemReporter().resourceHasToBeAutoCloseable(resourceType, this.resources[i].type); >- } >- } >- localScope = new BlockScope(localScope, 1); >- } >- >- BlockScope tryScope = new BlockScope(localScope); >- >- if (this.finallyBlock != null) { >- if (this.finallyBlock.isEmptyBlock()) { >- if ((this.finallyBlock.bits & ASTNode.UndocumentedEmptyBlock) != 0) { >- this.scope.problemReporter().undocumentedEmptyBlock(this.finallyBlock.sourceStart, >- this.finallyBlock.sourceEnd); >- } >- } else { >- finallyScope = new BlockScope(this.scope, false); // don't add it yet to parent scope >- >- // provision for returning and forcing the finally block to run >- MethodScope methodScope = this.scope.methodScope(); >- >- // the type does not matter as long as it is not a base type >- if (!upperScope.compilerOptions().inlineJsrBytecode) { >- this.returnAddressVariable = new LocalVariableBinding(TryStatement.SECRET_RETURN_ADDRESS_NAME, >- upperScope.getJavaLangObject(), ClassFileConstants.AccDefault, false); >- finallyScope.addLocalVariable(this.returnAddressVariable); >- this.returnAddressVariable.setConstant(Constant.NotAConstant); // not inlinable >- } >- this.subRoutineStartLabel = new BranchLabel(); >- >- this.anyExceptionVariable = new LocalVariableBinding(TryStatement.SECRET_ANY_HANDLER_NAME, >- this.scope.getJavaLangThrowable(), ClassFileConstants.AccDefault, false); >- finallyScope.addLocalVariable(this.anyExceptionVariable); >- this.anyExceptionVariable.setConstant(Constant.NotAConstant); // not inlinable >- >- if (!methodScope.isInsideInitializer()) { >- MethodBinding methodBinding = ((AbstractMethodDeclaration) methodScope.referenceContext).binding; >- if (methodBinding != null) { >- TypeBinding methodReturnType = methodBinding.returnType; >- if (methodReturnType.id != TypeIds.T_void) { >- this.secretReturnValue = new LocalVariableBinding(TryStatement.SECRET_RETURN_VALUE_NAME, >- methodReturnType, ClassFileConstants.AccDefault, false); >- finallyScope.addLocalVariable(this.secretReturnValue); >- this.secretReturnValue.setConstant(Constant.NotAConstant); // not inlinable >- } >- } >- } >- this.finallyBlock.resolveUsing(finallyScope); >- // force the finally scope to have variable positions shifted after its try scope and catch ones >- int shiftScopesLength = this.catchArguments == null ? 1 : this.catchArguments.length + 1; >- shiftScopesLength += this.resources.length; >- finallyScope.shiftScopes = new BlockScope[shiftScopesLength]; >- for (int i = 0, max = this.resources.length; i < max; i++) { >- LocalVariableBinding localVariableBinding = this.resources[i].binding; >- if (localVariableBinding != null && localVariableBinding.isValidBinding()) { >- finallyScope.shiftScopes[i] = localVariableBinding.declaringScope; >- } >- } >- finallyScope.shiftScopes[this.resources.length] = tryScope; >- } >- } >- >- this.tryBlock.resolveUsing(tryScope); >- >- // arguments type are checked against JavaLangThrowable in resolveForCatch(..) >- if (this.catchBlocks != null) { >- int length = this.catchArguments.length; >- TypeBinding[] argumentTypes = new TypeBinding[length]; >- boolean containsDisjunctiveTypes = false; >- boolean catchHasError = false; >- for (int i = 0; i < length; i++) { >- BlockScope catchScope = new BlockScope(this.scope); >- if (finallyScope != null) { >- finallyScope.shiftScopes[i + 1] = catchScope; >- } >- // side effect on catchScope in resolveForCatch(..) >- Argument catchArgument = this.catchArguments[i]; >- containsDisjunctiveTypes |= (catchArgument.type.bits & ASTNode.IsDisjuntive) != 0; >- if ((argumentTypes[i] = catchArgument.resolveForCatch(catchScope)) == null) { >- catchHasError = true; >- } >- this.catchBlocks[i].resolveUsing(catchScope); >- } >- if (catchHasError) { >- return; >- } >- this.caughtExceptionTypes = new ReferenceBinding[length]; >- verifyDuplicationAndOrder(length, argumentTypes, containsDisjunctiveTypes); >- } else { >- this.caughtExceptionTypes = new ReferenceBinding[0]; >- } >- >- if (finallyScope != null) { >- // add finallyScope as last subscope, so it can be shifted behind try/catch subscopes. >- // the shifting is necessary to achieve no overlay in between the finally scope and its >- // sibling in term of local variable positions. >- this.scope.addSubscope(finallyScope); >- } >- } >- public void traverse(ASTVisitor visitor, BlockScope blockScope) { >- if (visitor.visit(this, blockScope)) { >- LocalDeclaration[] localDeclarations = this.resources; >- for (int i = 0, max = localDeclarations.length; i < max; i++) { >- localDeclarations[i].traverse(visitor, this.scope); >- } >- this.tryBlock.traverse(visitor, this.scope); >- if (this.catchArguments != null) { >- for (int i = 0, max = this.catchBlocks.length; i < max; i++) { >- this.catchArguments[i].traverse(visitor, this.scope); >- this.catchBlocks[i].traverse(visitor, this.scope); >- } >- } >- if (this.finallyBlock != null) >- this.finallyBlock.traverse(visitor, this.scope); >- } >- visitor.endVisit(this, blockScope); >- } >-} >Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v >retrieving revision 1.422.2.11 >diff -u -r1.422.2.11 Parser.java >--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 1 Mar 2011 05:58:47 -0000 1.422.2.11 >+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 1 Mar 2011 13:19:34 -0000 >@@ -7420,7 +7420,7 @@ > // TryStatementWithResources ::= 'try' ResourceSpecification TryBlock Catchesopt > // TryStatementWithResources ::= 'try' ResourceSpecification TryBlock Catchesopt Finally > int length; >- TryStatementWithResources tryStmt = new TryStatementWithResources(); >+ TryStatement tryStmt = new TryStatement(); > //finally > if (withFinally) { > this.astLengthPtr--; >Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v >retrieving revision 1.273.2.3 >diff -u -r1.273.2.3 ASTConverter.java >--- dom/org/eclipse/jdt/core/dom/ASTConverter.java 28 Feb 2011 18:45:41 -0000 1.273.2.3 >+++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 1 Mar 2011 13:19:39 -0000 >@@ -2479,11 +2479,13 @@ > if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ThrowStatement) { > return convert((org.eclipse.jdt.internal.compiler.ast.ThrowStatement) statement); > } >- if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TryStatementWithResources) { >- return convert((org.eclipse.jdt.internal.compiler.ast.TryStatementWithResources) statement); >- } > if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TryStatement) { >- return convert((org.eclipse.jdt.internal.compiler.ast.TryStatement) statement); >+ org.eclipse.jdt.internal.compiler.ast.TryStatement stmt = (org.eclipse.jdt.internal.compiler.ast.TryStatement) statement; >+ if (stmt.resources.length > 0) { >+ return convert(stmt, true); >+ } else { >+ return convert(stmt); >+ } > } > if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { > ASTNode result = convert((org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) statement); >@@ -2654,7 +2656,7 @@ > return tryStatement; > } > >- public TryStatementWithResources convert(org.eclipse.jdt.internal.compiler.ast.TryStatementWithResources statement) { >+ public TryStatementWithResources convert(org.eclipse.jdt.internal.compiler.ast.TryStatement statement, boolean hasResources /* unused */) { > final TryStatementWithResources tryStatementWithResources = new TryStatementWithResources(this.ast); > tryStatementWithResources.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1); > LocalDeclaration[] localDeclarations = statement.resources; >Index: formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java,v >retrieving revision 1.239.2.3 >diff -u -r1.239.2.3 CodeFormatterVisitor.java >--- formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 31 Jan 2011 19:15:47 -0000 1.239.2.3 >+++ formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java 1 Mar 2011 13:19:47 -0000 >@@ -105,7 +105,6 @@ > import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; > import org.eclipse.jdt.internal.compiler.ast.TrueLiteral; > import org.eclipse.jdt.internal.compiler.ast.TryStatement; >-import org.eclipse.jdt.internal.compiler.ast.TryStatementWithResources; > import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; > import org.eclipse.jdt.internal.compiler.ast.TypeParameter; > import org.eclipse.jdt.internal.compiler.ast.TypeReference; >@@ -5424,47 +5423,11 @@ > public boolean visit(TryStatement tryStatement, BlockScope scope) { > > this.scribe.printNextToken(TerminalTokens.TokenNametry); >- tryStatement.tryBlock.traverse(this, scope); >- if (tryStatement.catchArguments != null) { >- for (int i = 0, max = tryStatement.catchBlocks.length; i < max; i++) { >- if (this.preferences.insert_new_line_before_catch_in_try_statement) { >- this.scribe.printNewLine(); >- } >- this.scribe.printNextToken(TerminalTokens.TokenNamecatch, this.preferences.insert_space_after_closing_brace_in_block); >- final int line = this.scribe.line; >- this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_opening_paren_in_catch); >- >- if (this.preferences.insert_space_after_opening_paren_in_catch) { >- this.scribe.space(); >- } >- >- tryStatement.catchArguments[i].traverse(this, scope); >- >- this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_catch); >- >- formatLeftCurlyBrace(line, this.preferences.brace_position_for_block); >- tryStatement.catchBlocks[i].traverse(this, scope); >- } >- } >- if (tryStatement.finallyBlock != null) { >- if (this.preferences.insert_new_line_before_finally_in_try_statement) { >- this.scribe.printNewLine(); >- } >- this.scribe.printNextToken(TerminalTokens.TokenNamefinally, this.preferences.insert_space_after_closing_brace_in_block); >- tryStatement.finallyBlock.traverse(this, scope); >- } >- return false; >- } >- >- /** >- * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.TryStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope) >- */ >- public boolean visit(TryStatementWithResources tryStatementWithResources, BlockScope scope) { >- >- this.scribe.printNextToken(TerminalTokens.TokenNametry); >- this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, true); >- LocalDeclaration[] resources = tryStatementWithResources.resources; >+ LocalDeclaration[] resources = tryStatement.resources; > int length = resources.length; >+ if (length > 0) { >+ this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, true); >+ } > for (int i = 0; i < length; i++) { > if (i != 0) { > this.scribe.printNewLine(); >@@ -5480,10 +5443,12 @@ > this.scribe.unIndent(); > this.scribe.unIndent(); > } >- this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN); >- tryStatementWithResources.tryBlock.traverse(this, scope); >- if (tryStatementWithResources.catchArguments != null) { >- for (int i = 0, max = tryStatementWithResources.catchBlocks.length; i < max; i++) { >+ if (length > 0) { >+ this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN); >+ } >+ tryStatement.tryBlock.traverse(this, scope); >+ if (tryStatement.catchArguments != null) { >+ for (int i = 0, max = tryStatement.catchBlocks.length; i < max; i++) { > if (this.preferences.insert_new_line_before_catch_in_try_statement) { > this.scribe.printNewLine(); > } >@@ -5495,20 +5460,20 @@ > this.scribe.space(); > } > >- tryStatementWithResources.catchArguments[i].traverse(this, scope); >+ tryStatement.catchArguments[i].traverse(this, scope); > > this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_before_closing_paren_in_catch); > > formatLeftCurlyBrace(line, this.preferences.brace_position_for_block); >- tryStatementWithResources.catchBlocks[i].traverse(this, scope); >+ tryStatement.catchBlocks[i].traverse(this, scope); > } > } >- if (tryStatementWithResources.finallyBlock != null) { >+ if (tryStatement.finallyBlock != null) { > if (this.preferences.insert_new_line_before_finally_in_try_statement) { > this.scribe.printNewLine(); > } > this.scribe.printNextToken(TerminalTokens.TokenNamefinally, this.preferences.insert_space_after_closing_brace_in_block); >- tryStatementWithResources.finallyBlock.traverse(this, scope); >+ tryStatement.finallyBlock.traverse(this, scope); > } > return false; > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Attic/TryWithResourcesStatementTest.java,v >retrieving revision 1.1.2.7 >diff -u -r1.1.2.7 TryWithResourcesStatementTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 1 Mar 2011 05:58:30 -0000 1.1.2.7 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 1 Mar 2011 13:19:55 -0000 >@@ -376,13 +376,15 @@ > "y cannot be resolved to a variable\n" + > "----------\n"); > } >-public void _test014() { >+public void test014() { > this.runNegativeTest( > new String[] { > "X.java", > "public class X {\n" + > " public static void main(String [] args) { \n" + > " try (Y y = new Y();) {\n" + >+ " if (y == null) {}\n" + >+ " Y why = new Y();\n" + > " System.out.println(\"Try block\");\n" + > " } finally {\n" + > " System.out.println(\"Finally block\");\n" + >@@ -402,18 +404,175 @@ > "class WeirdException extends Throwable {}\n", > }, > "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " try (Y y = new Y();) {\n" + >+ " ^^^^^^^\n" + >+ "Unhandled exception type WeirdException\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 4)\n" + >+ " if (y == null) {}\n" + >+ " ^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 5)\n" + >+ " Y why = new Y();\n" + >+ " ^^^^^^^\n" + >+ "Unhandled exception type WeirdException\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 22)\n" + >+ " class WeirdException extends Throwable {}\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n"); >+} >+public void test015() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String [] args) { \n" + >+ " try (Y y = new Y();) {\n" + >+ " if (y == null)\n {}\n" + >+ " }\n" + >+ " }\n" + >+ "} \n" + >+ "\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public void close() {\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + > "1. WARNING in X.java (at line 5)\n" + >- " public void foo(int p) {\n" + >- " ^\n" + >- "The parameter p is hiding another local variable defined in an enclosing type scope\n" + >+ " {}\n" + >+ " ^^\n" + >+ "Dead code\n" + >+ "----------\n"); >+} >+public void test016() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String [] args) { \n" + >+ " try (Y y = new Y();) {\n" + >+ " if (y == null) {}\n" + >+ " Y why = new Y();\n" + >+ " System.out.println(\"Try block\");\n" + >+ " }\n" + >+ " }\n" + >+ "} \n" + >+ "\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public Y() throws WeirdException {\n" + >+ " throw new WeirdException();\n" + >+ " }\n" + >+ " public void close() {\n" + >+ " System.out.println(\"Closing resource\");\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "class WeirdException extends Throwable {}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " try (Y y = new Y();) {\n" + >+ " ^^^^^^^\n" + >+ "Unhandled exception type WeirdException\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 4)\n" + >+ " if (y == null) {}\n" + >+ " ^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 5)\n" + >+ " Y why = new Y();\n" + >+ " ^^^^^^^\n" + >+ "Unhandled exception type WeirdException\n" + > "----------\n" + >- "2. WARNING in X.java (at line 8)\n" + >- " } catch (Exception y) {\n" + >+ "4. WARNING in X.java (at line 20)\n" + >+ " class WeirdException extends Throwable {}\n" + >+ " ^^^^^^^^^^^^^^\n" + >+ "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n"); >+} >+public void test017() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String [] args) { \n" + >+ " try (Y y = new Y();) {\n" + >+ " if (y == null)\n {}\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "} \n" + >+ "\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public void close() {\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " {}\n" + >+ " ^^\n" + >+ "Dead code\n" + >+ "----------\n"); >+} >+public void test018() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String [] args) { \n" + >+ " try () {\n" + >+ " } finally {\n" + >+ " }\n" + >+ " }\n" + >+ "} \n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " try () {\n" + >+ " ^\n" + >+ "Syntax error on token \"(\", Resources expected after this token\n" + >+ "----------\n"); >+} >+public void test019() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String [] args) {\n" + >+ " try (Y y = null) {\n" + >+ " } catch (Exception e) {\n" + >+ " System.out.println(y); \n" + >+ " } finally {\n" + >+ " System.out.println(y); \n" + >+ " }\n" + >+ " System.out.println(y); \n" + >+ " }\n" + >+ "}\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public void close() {\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " System.out.println(y); \n" + > " ^\n" + >- "The parameter y is hiding another local variable defined in an enclosing type scope\n" + >+ "y cannot be resolved to a variable\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " System.out.println(y); \n" + >+ " ^\n" + >+ "y cannot be resolved to a variable\n" + > "----------\n" + >- "3. ERROR in X.java (at line 13)\n" + >- " System.out.println(y);\n" + >+ "3. ERROR in X.java (at line 9)\n" + >+ " System.out.println(y); \n" + > " ^\n" + > "y cannot be resolved to a variable\n" + > "----------\n"); >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java,v >retrieving revision 1.263.2.4 >diff -u -r1.263.2.4 FormatterRegressionTests.java >--- src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 14 Feb 2011 17:53:17 -0000 1.263.2.4 >+++ src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java 1 Mar 2011 13:20:27 -0000 >@@ -66,7 +66,7 @@ > Map formatterOptions; > > static { >- TESTS_NUMBERS = new int[] { 746, 747 }; >+// TESTS_NUMBERS = new int[] { 746, 747 }; > } > public static Test suite() { > return buildModelTestSuite(FormatterRegressionTests.class);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338402
:
190016
| 190034 |
190131
|
190659
|
190744
|
190751