org.eclipse.jdt.core.dom.EmptyStatement Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.EmptyStatement. 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: EmptyStatementQuickFix.java    From vscode-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ASTVisitor getCorrectingASTVisitor(IRegion lineInfo, int markerStartOffset) {
    return new ASTVisitor() {
        @Override
        public boolean visit(EmptyStatement node) {
            if (containsPosition(lineInfo, node.getStartPosition())) {

                // early exit if the statement is mandatory, e.g. only
                // statement in a for-statement without block
                final StructuralPropertyDescriptor p = node.getLocationInParent();
                if (p.isChildProperty() && ((ChildPropertyDescriptor) p).isMandatory()) {
                    return false;
                }

                node.delete();
            }
            return false;
        }
    };
}
 
Example #2
Source File: EmptyStatementQuickfix.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo,
        final int markerStartPosition) {

  return new ASTVisitor() {
    @Override
    public boolean visit(EmptyStatement node) {
      if (containsPosition(lineInfo, node.getStartPosition())) {

        // early exit if the statement is mandatory, e.g. only
        // statement in a for-statement without block
        StructuralPropertyDescriptor p = node.getLocationInParent();
        if (p.isChildProperty() && ((ChildPropertyDescriptor) p).isMandatory()) {
          return false;
        }

        node.delete();
      }
      return false;
    }
  };
}
 
Example #3
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(EmptyStatement stmnt){
	/*
	 * EmptyStatement: ;
	 */
	appendSemicolon();
	return false;
}
 
Example #4
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
private EmptyStmt visit(EmptyStatement node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	EmptyStmt emptyStmt = new EmptyStmt(startLine, endLine, node);
	return emptyStmt;
}
 
Example #5
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(EmptyStatement node) {
	// Empty statements aren't of any interest.
	return false;
}
 
Example #6
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void endVisit(EmptyStatement node) {
	// Leaf node.
}
 
Example #7
Source File: LocalCorrectionsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private static void addRemoveIncludingConditionProposal(IInvocationContext context, ASTNode toRemove, ASTNode replacement, Collection<ChangeCorrectionProposal> proposals) {
	String label = CorrectionMessages.LocalCorrectionsSubProcessor_removeunreachablecode_including_condition_description;
	AST ast = toRemove.getAST();
	ASTRewrite rewrite = ASTRewrite.create(ast);
	ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_UNREACHABLE_CODE_INCLUDING_CONDITION);

	if (replacement == null || replacement instanceof EmptyStatement || replacement instanceof Block && ((Block) replacement).statements().size() == 0) {
		if (ASTNodes.isControlStatementBody(toRemove.getLocationInParent())) {
			rewrite.replace(toRemove, toRemove.getAST().newBlock(), null);
		} else {
			rewrite.remove(toRemove, null);
		}

	} else if (toRemove instanceof Expression && replacement instanceof Expression) {
		Expression moved = (Expression) rewrite.createMoveTarget(replacement);
		Expression toRemoveExpression = (Expression) toRemove;
		Expression replacementExpression = (Expression) replacement;
		ITypeBinding explicitCast = ASTNodes.getExplicitCast(replacementExpression, toRemoveExpression);
		if (explicitCast != null) {
			CastExpression cast = ast.newCastExpression();
			if (NecessaryParenthesesChecker.needsParentheses(replacementExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
				ParenthesizedExpression parenthesized = ast.newParenthesizedExpression();
				parenthesized.setExpression(moved);
				moved = parenthesized;
			}
			cast.setExpression(moved);
			ImportRewrite imports = proposal.createImportRewrite(context.getASTRoot());
			ImportRewriteContext importRewriteContext = new ContextSensitiveImportRewriteContext(toRemove, imports);
			cast.setType(imports.addImport(explicitCast, ast, importRewriteContext, TypeLocation.CAST));
			moved = cast;
		}
		rewrite.replace(toRemove, moved, null);

	} else {
		ASTNode parent = toRemove.getParent();
		ASTNode moveTarget;
		if ((parent instanceof Block || parent instanceof SwitchStatement) && replacement instanceof Block) {
			ListRewrite listRewrite = rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY);
			List<Statement> list = ((Block) replacement).statements();
			int lastIndex = list.size() - 1;
			moveTarget = listRewrite.createMoveTarget(list.get(0), list.get(lastIndex));
		} else {
			moveTarget = rewrite.createMoveTarget(replacement);
		}

		rewrite.replace(toRemove, moveTarget, null);
	}

	proposals.add(proposal);
}
 
Example #8
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(final EmptyStatement node) {
  this.appendToBuffer(";");
  return false;
}
 
Example #9
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(EmptyStatement node) {
	// Empty statements aren't of any interest.
	return false;
}
 
Example #10
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(EmptyStatement node) {
	// Leaf node.
}
 
Example #11
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(EmptyStatement node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #12
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(EmptyStatement node) {
	add(fCreator.create(node));
	return true;
}
 
Example #13
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(EmptyStatement node) {
	endVisitNode(node);
}
 
Example #14
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(EmptyStatement node) {
	return visitNode(node);
}
 
Example #15
Source File: LocalCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static void addRemoveIncludingConditionProposal(IInvocationContext context, ASTNode toRemove, ASTNode replacement, Collection<ICommandAccess> proposals) {
	Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE);
	String label= CorrectionMessages.LocalCorrectionsSubProcessor_removeunreachablecode_including_condition_description;
	AST ast= toRemove.getAST();
	ASTRewrite rewrite= ASTRewrite.create(ast);
	ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_UNREACHABLE_CODE_INCLUDING_CONDITION, image);
	
	if (replacement == null
			|| replacement instanceof EmptyStatement
			|| replacement instanceof Block && ((Block)replacement).statements().size() == 0) {
		if (ASTNodes.isControlStatementBody(toRemove.getLocationInParent())) {
			rewrite.replace(toRemove, toRemove.getAST().newBlock(), null);
		} else {
			rewrite.remove(toRemove, null);
		}
		
	} else if (toRemove instanceof Expression && replacement instanceof Expression) {
		Expression moved= (Expression) rewrite.createMoveTarget(replacement);
		Expression toRemoveExpression= (Expression) toRemove;
		Expression replacementExpression= (Expression) replacement;
		ITypeBinding explicitCast= ASTNodes.getExplicitCast(replacementExpression, toRemoveExpression);
		if (explicitCast != null) {
			CastExpression cast= ast.newCastExpression();
			if (NecessaryParenthesesChecker.needsParentheses(replacementExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
				ParenthesizedExpression parenthesized= ast.newParenthesizedExpression();
				parenthesized.setExpression(moved);
				moved= parenthesized;
			}
			cast.setExpression(moved);
			ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
			ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(toRemove, imports);
			cast.setType(imports.addImport(explicitCast, ast, importRewriteContext));
			moved= cast;
		}
		rewrite.replace(toRemove, moved, null);
		
	} else {
		ASTNode parent= toRemove.getParent();
		ASTNode moveTarget;
		if ((parent instanceof Block || parent instanceof SwitchStatement) && replacement instanceof Block) {
			ListRewrite listRewrite= rewrite.getListRewrite(replacement, Block.STATEMENTS_PROPERTY);
			List<Statement> list= ((Block)replacement).statements();
			int lastIndex= list.size() - 1;
			moveTarget= listRewrite.createMoveTarget(list.get(0), list.get(lastIndex));
		} else {
			moveTarget= rewrite.createMoveTarget(replacement);
		}

		rewrite.replace(toRemove, moveTarget, null);
	}
	
	proposals.add(proposal);
}
 
Example #16
Source File: StatementCollector.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(EmptyStatement node) {
	statementList.add(node);
	return false;
}
 
Example #17
Source File: ExtractStatementsVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(EmptyStatement node) {
	statementsList.add(node);
	
	return false;
}
 
Example #18
Source File: CodeSearch.java    From SimFix with GNU General Public License v2.0 4 votes vote down vote up
public boolean visit(EmptyStatement node) {
	return true;
}
 
Example #19
Source File: ConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @param node the AST node
 * @return array of type constraints, may be empty
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.EmptyStatement)
 */
public ITypeConstraint[] create(EmptyStatement node) {
	return EMPTY_ARRAY;
}