1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2019 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.checks.indentation;
21  
22  import com.puppycrawl.tools.checkstyle.api.DetailAST;
23  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
24  
25  /**
26   * Handler for operator new.
27   */
28  public class NewHandler extends AbstractExpressionHandler {
29  
30      /**
31       * Construct an instance of this handler with the given indentation check,
32       * abstract syntax tree, and parent handler.
33       *
34       * @param indentCheck   the indentation check
35       * @param ast           the abstract syntax tree
36       * @param parent        the parent handler
37       */
38      public NewHandler(IndentationCheck indentCheck,
39                        DetailAST ast,
40                        AbstractExpressionHandler parent) {
41          super(indentCheck, "operator new", ast, parent);
42      }
43  
44      @Override
45      public void checkIndentation() {
46          final DetailAST type = getMainAst().getFirstChild();
47          if (type != null) {
48              checkExpressionSubtree(type, getIndent(), false, false);
49          }
50  
51          final DetailAST lparen = getMainAst().findFirstToken(TokenTypes.LPAREN);
52          checkLeftParen(lparen);
53      }
54  
55      @Override
56      protected IndentLevel getIndentImpl() {
57          final IndentLevel result;
58          // if our expression isn't first on the line, just use the start
59          // of the line
60          if (getLineStart(getMainAst()) == getMainAst().getColumnNo()) {
61              result = super.getIndentImpl();
62          }
63          else {
64              result = new IndentLevel(getLineStart(getMainAst()));
65          }
66          return result;
67      }
68  
69      @Override
70      protected boolean shouldIncreaseIndent() {
71          return false;
72      }
73  
74  }