private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) { if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) { // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ... return false; } if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.MESSAGE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == SwitchStatement.EXPRESSION_PROPERTY || locationInParent == SwitchCase.EXPRESSION_PROPERTY || locationInParent == ArrayAccess.INDEX_PROPERTY || locationInParent == ThrowStatement.EXPRESSION_PROPERTY || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) { return false; } return true; }
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) { if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) { // e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation // ... return false; } if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY || locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == AssertStatement.MESSAGE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY || locationInParent == SwitchStatement.EXPRESSION_PROPERTY || locationInParent == SwitchCase.EXPRESSION_PROPERTY || locationInParent == ArrayAccess.INDEX_PROPERTY || locationInParent == ThrowStatement.EXPRESSION_PROPERTY || locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY || locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) { return false; } return true; }
/** {@inheritDoc} */ @Override public void endVisit(ClassInstanceCreation instanceCreation) { if (instanceCreation.getParent() instanceof ThrowStatement) { logger.warn("Ignoring throw statements!"); return; } List<?> paramTypes = Arrays.asList(instanceCreation.resolveConstructorBinding().getParameterTypes()); List<?> paramValues = instanceCreation.arguments(); Constructor<?> constructor = retrieveConstructor(instanceCreation.getType(), paramTypes, paramValues); List<VariableReference> params = convertParams(instanceCreation.arguments(), paramTypes); VariableReference retVal = retrieveVariableReference(instanceCreation, null); retVal.setOriginalCode(instanceCreation.toString()); ConstructorStatement statement = new ValidConstructorStatement( testCase.getReference(), constructor, retVal, params); testCase.addStatement(statement); }
@Override public void endVisit(ThrowStatement node) { if (skipNode(node)) { return; } ThrowFlowInfo info = createThrow(); setFlowInfo(node, info); Expression expression = node.getExpression(); info.merge(getFlowInfo(expression), fFlowContext); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception = node.getExpression().resolveTypeBinding(); if (exception == null) { return true; } addException(exception, node.getAST()); return true; }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception = node.getExpression().resolveTypeBinding(); if (!isSelected(node) || exception == null || Bindings.isRuntimeException(exception)) { return true; } addException(exception, node.getAST()); return true; }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception = node.getExpression().resolveTypeBinding(); if (exception == null) // Safety net for null bindings when compiling fails. return true; addException(exception, node.getAST()); return true; }
@Override public ITypeConstraint[] create(ThrowStatement node) { ConstraintVariable nameVariable = fConstraintVariableFactory.makeExpressionOrTypeVariable(node.getExpression(), getContext()); ITypeBinding throwable = node.getAST().resolveWellKnownType("java.lang.Throwable"); // $NON-NLS-1$ return fTypeConstraintFactory.createSubtypeConstraint( nameVariable, fConstraintVariableFactory.makeRawBindingVariable(throwable)); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception = node.getExpression().resolveTypeBinding(); if (!isSelected(node) || exception == null || Bindings.isRuntimeException( exception)) // Safety net for null bindings when compiling fails. return true; addException(exception, node.getAST()); return true; }
@Override public boolean visit(ThrowStatement node) { ITypeBinding thrownExceptionType = node.getExpression().resolveTypeBinding(); try { handleException(node, thrownExceptionType); } catch (JavaModelException e) { throw new RuntimeException(e); } return super.visit(node); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding binding = node.getExpression().resolveTypeBinding(); if (binding != null) { ThrownException thrownException = new ThrownException(); Type thrownType = importer.ensureTypeFromTypeBinding(binding); thrownException.setExceptionClass((com.feenk.jdt2famix.model.famix.Class) thrownType); thrownException.setDefiningMethod((Method) importer.topOfContainerStack()); importer.repository().add(thrownException); } return true; }
@Override public void endVisit(ThrowStatement node) { if (skipNode(node)) return; ThrowFlowInfo info= createThrow(); setFlowInfo(node, info); Expression expression= node.getExpression(); info.merge(getFlowInfo(expression), fFlowContext); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception= node.getExpression().resolveTypeBinding(); if (exception == null) // Safety net for null bindings when compiling fails. return true; addException(exception, node.getAST()); return true; }
@Override public ITypeConstraint[] create(ThrowStatement node) { ConstraintVariable nameVariable= fConstraintVariableFactory.makeExpressionOrTypeVariable(node.getExpression(), getContext()); ITypeBinding throwable= node.getAST().resolveWellKnownType("java.lang.Throwable"); //$NON-NLS-1$ return fTypeConstraintFactory.createSubtypeConstraint( nameVariable, fConstraintVariableFactory.makeRawBindingVariable(throwable)); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception= node.getExpression().resolveTypeBinding(); if (!isSelected(node) || exception == null || Bindings.isRuntimeException(exception)) // Safety net for null bindings when compiling fails. return true; addException(exception, node.getAST()); return true; }
@Override public boolean visit(ThrowStatement node) { if (matches(node.getExpression().resolveTypeBinding())) { // mark 'throw' fResult.add(new OccurrenceLocation(node.getStartPosition(), 5, 0, fDescription)); } return super.visit(node); }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception= node.getExpression().resolveTypeBinding(); if (isExitPoint(exception)) { // mark 'throw' fResult.add(new OccurrenceLocation(node.getStartPosition(), 5, 0, fExitDescription)); } return true; }
public boolean visit(ThrowStatement node){ ////////////////////////////THROWS NULL-POINTER-EXCEPTION///////////////////////////////////////////// if(node.getExpression().toString().contains("NullPointerException")){ //ParichayanaActivator.logInfo("THROW CLAUSE : " + node.getExpression()); ParichayanaActivator.logInfo("_________________________________________________________________________________"); ParichayanaActivator.logInfo("FILE NAME : " + getName(unit) + "\n"); ParichayanaActivator.logInfo("THROW CLAUSE : " + node); ParichayanaActivator.logInfo(Constants.ANTI_PATTERN_TNPE_MESSAGE); ParichayanaActivator.logInfo("_________________________________________________________________________________"); try { createMarker(unit, Constants.ANTI_PATTERN_TNPE_MESSAGE, IMarker.SEVERITY_WARNING, Constants.TNPE_MARKER_ID, node.getStartPosition(), node.getLength()); } catch (CoreException ex) { ParichayanaActivator.log(ex); } //writer.println("_________________________________________________________________________________"); writer.println(linenumber + " FILE NAME : " + getName(unit) + "\n"); linenumber++; writer.println(linenumber + " THROW CLAUSE : " + node); linenumber++; writer.println(linenumber + Constants.ANTI_PATTERN_TNPE_MESSAGE); linenumber++; writer.println("_________________________________________________________________________________"); numtnpe++; } return true; /////////////////////////////////////////////////////////////////////////////////////////////////////////// }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception= node.getExpression().resolveTypeBinding(); if (exception == null) // Safety net for null bindings when compiling fails. return true; addException(exception); return true; }
@Override public boolean visit(ThrowStatement node) { ITypeBinding exception= node.getExpression().resolveTypeBinding(); if (!isSelected(node) || exception == null || Bindings.isRuntimeException(exception)) // Safety net for null bindings when compiling fails. return true; addException(exception); return true; }
@Override public boolean visit(ThrowStatement node) { this.fBuffer.append("throw ");//$NON-NLS-1$ node.getExpression().accept(this); this.fBuffer.append(";");//$NON-NLS-1$ return false; }
public boolean visit(ThrowStatement node) { printIndent(); this.buffer.append("throw ");//$NON-NLS-1$ node.getExpression().accept(this); this.buffer.append(";\n");//$NON-NLS-1$ return false; }
/** * An exception throw does not introduce a control or a data dependence. Perhaps there's something * that can be done here to improve processing at run-time. * * 'throw' Expression ';' */ @Override public boolean visit(final ThrowStatement node) { // do not visit children return false; }
@Override public boolean visit(ThrowStatement node) { //System.out.println("Found: " + node.getClass()); print("throw "); node.getExpression().accept(this); println(";"); return false; }
@Override public abstract boolean visit(ThrowStatement node);
private static boolean satisfiesPrecondition( Statement controlStatement, ChildPropertyDescriptor childDescriptor, boolean onlyReturnAndThrows, boolean cleanUpCheck) { Object child = controlStatement.getStructuralProperty(childDescriptor); if (!(child instanceof Block)) return false; Block block = (Block) child; List<Statement> list = block.statements(); if (list.size() != 1) return false; ASTNode singleStatement = list.get(0); if (onlyReturnAndThrows) if (!(singleStatement instanceof ReturnStatement) && !(singleStatement instanceof ThrowStatement)) return false; if (controlStatement instanceof IfStatement) { // if (true) { // while (true) // if (false) // ; // } else // ; if (((IfStatement) controlStatement).getThenStatement() != child) return true; // can always remove blocks in else part IfStatement ifStatement = (IfStatement) controlStatement; if (ifStatement.getElseStatement() == null) return true; // can always remove if no else part return !hasUnblockedIf((Statement) singleStatement, onlyReturnAndThrows, cleanUpCheck); } else { // if (true) // while (true) { // if (false) // ; // } // else // ; if (!hasUnblockedIf((Statement) singleStatement, onlyReturnAndThrows, cleanUpCheck)) return true; ASTNode currentChild = controlStatement; ASTNode parent = currentChild.getParent(); while (true) { Statement body = null; if (parent instanceof IfStatement) { body = ((IfStatement) parent).getThenStatement(); if (body == currentChild && ((IfStatement) parent).getElseStatement() != null) // ->currentChild is an unblocked then part return false; } else if (parent instanceof WhileStatement) { body = ((WhileStatement) parent).getBody(); } else if (parent instanceof DoStatement) { body = ((DoStatement) parent).getBody(); } else if (parent instanceof ForStatement) { body = ((ForStatement) parent).getBody(); } else if (parent instanceof EnhancedForStatement) { body = ((EnhancedForStatement) parent).getBody(); } else { return true; } if (body != currentChild) // ->parents child is a block return true; currentChild = parent; parent = currentChild.getParent(); } } }
/** {@inheritDoc} */ @Override public void endVisit(ThrowStatement node) { logger.warn("Method endVisitThrowStatement for " + node + " for " + node + " not implemented!"); super.endVisit(node); }
/** {@inheritDoc} */ @Override public boolean visit(ThrowStatement node) { logger.warn("Method visitThrowStatement for " + node + " not implemented!"); return super.visit(node); }
@Override public boolean visit(final ThrowStatement node) { return this.found(); }
@Override public boolean visit(final ThrowStatement node) { return false; }
@Override public boolean visit(final ThrowStatement node) { return this.visitInstrumentable(node); }
@Override public boolean visit(ThrowStatement node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
@Override public boolean visit(ThrowStatement node) { add(fCreator.create(node)); return true; }