Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.BlockScope#removeTrackingVar()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.BlockScope#removeTrackingVar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static void cleanUpAfterAssignment(BlockScope currentScope, int lhsBits, Expression expression) { // remove all remaining track vars with no original binding // unwrap uninteresting nodes: while (true) { if (expression instanceof Assignment) expression = ((Assignment)expression).expression; else if (expression instanceof CastExpression) expression = ((CastExpression) expression).expression; else break; } if (expression instanceof AllocationExpression) { FakedTrackingVariable tracker = ((AllocationExpression) expression).closeTracker; if (tracker != null && tracker.originalBinding == null) { currentScope.removeTrackingVar(tracker); ((AllocationExpression) expression).closeTracker = null; } } else { // assignment passing a local into a field? LocalVariableBinding local = expression.localVariableBinding(); if (local != null && local.closeTracker != null && ((lhsBits & Binding.FIELD) != 0)) currentScope.removeTrackingVar(local.closeTracker); // TODO: may want to use local.closeTracker.markPassedToOutside(..,true) } }
Example 2
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Compute/assign a tracking variable for a freshly allocated closeable value, using information from our white lists. * See Bug 358903 - Filter practically unimportant resource leak warnings */ public static void analyseCloseableAllocation(BlockScope scope, FlowInfo flowInfo, AllocationExpression allocation) { // client has checked that the resolvedType is an AutoCloseable, hence the following cast is safe: if (((ReferenceBinding)allocation.resolvedType).hasTypeBit(TypeIds.BitResourceFreeCloseable)) { // remove unnecessary attempts (closeable is not relevant) if (allocation.closeTracker != null) { scope.removeTrackingVar(allocation.closeTracker); allocation.closeTracker = null; } } else if (((ReferenceBinding)allocation.resolvedType).hasTypeBit(TypeIds.BitWrapperCloseable)) { boolean isWrapper = true; if (allocation.arguments != null && allocation.arguments.length > 0) { // find the wrapped resource represented by its tracking var: FakedTrackingVariable innerTracker = findCloseTracker(scope, flowInfo, allocation.arguments[0]); if (innerTracker != null) { FakedTrackingVariable currentInner = innerTracker; do { if (currentInner == allocation.closeTracker) return; // self wrap (res = new Res(res)) -> neither change (here) nor remove (below) // also check for indirect cycles, see https://bugs.eclipse.org/368709 currentInner = currentInner.innerTracker; } while (currentInner != null); int newStatus = FlowInfo.NULL; if (allocation.closeTracker == null) { allocation.closeTracker = new FakedTrackingVariable(scope, allocation, flowInfo, FlowInfo.UNKNOWN); // no local available, closeable is unassigned } else { if (scope.finallyInfo != null) { // inject results from analysing a finally block onto the newly connected wrapper int finallyStatus = scope.finallyInfo.nullStatus(allocation.closeTracker.binding); if (finallyStatus != FlowInfo.UNKNOWN) newStatus = finallyStatus; } } if (allocation.closeTracker.innerTracker != null) { innerTracker = pickMoreUnsafe(allocation.closeTracker.innerTracker, innerTracker, scope, flowInfo); } allocation.closeTracker.innerTracker = innerTracker; innerTracker.outerTracker = allocation.closeTracker; flowInfo.markNullStatus(allocation.closeTracker.binding, newStatus); if (newStatus != FlowInfo.NULL) { // propagate results from a finally block also into nested resources: FakedTrackingVariable currentTracker = innerTracker; while (currentTracker != null) { flowInfo.markNullStatus(currentTracker.binding, newStatus); currentTracker.globalClosingState |= allocation.closeTracker.globalClosingState; currentTracker = currentTracker.innerTracker; } } return; // keep chaining wrapper (by avoiding to fall through to removeTrackingVar below) } else { if (!isAnyCloseable(allocation.arguments[0].resolvedType)) { isWrapper = false; // argument is not closeable } } } else { isWrapper = false; // no argument } // successful wrapper detection has exited above, let's see why that failed if (isWrapper) { // remove unnecessary attempts (wrapper has no relevant inner) if (allocation.closeTracker != null) { scope.removeTrackingVar(allocation.closeTracker); allocation.closeTracker = null; } } else { // allocation does not provide a resource as the first argument -> don't treat as a wrapper handleRegularResource(scope, flowInfo, allocation); } } else { // regular resource handleRegularResource(scope, flowInfo, allocation); } }
Example 3
Source File: FakedTrackingVariable.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static FakedTrackingVariable pick(FakedTrackingVariable tracker1, FakedTrackingVariable tracker2, BlockScope scope) { scope.removeTrackingVar(tracker2); return tracker1; }