List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration extraDimensions
ASTNode.NodeList extraDimensions
To view the source code for org.eclipse.jdt.core.dom MethodDeclaration extraDimensions.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(MethodDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*from ww w . j a v a 2s . c o m*/ if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); if (!node.typeParameters().isEmpty()) { this.fBuffer.append("<");//$NON-NLS-1$ for (Iterator<TypeParameter> it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append("> ");//$NON-NLS-1$ } } if (!node.isConstructor()) { if (node.getReturnType2() != null) { node.getReturnType2().accept(this); } else { // methods really ought to have a return type this.fBuffer.append("void");//$NON-NLS-1$ } this.fBuffer.append(" ");//$NON-NLS-1$ } node.getName().accept(this); this.fBuffer.append("(");//$NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS8) { Type receiverType = node.getReceiverType(); if (receiverType != null) { receiverType.accept(this); this.fBuffer.append(' '); SimpleName qualifier = node.getReceiverQualifier(); if (qualifier != null) { qualifier.accept(this); this.fBuffer.append('.'); } this.fBuffer.append("this"); //$NON-NLS-1$ if (node.parameters().size() > 0) { this.fBuffer.append(','); } } } for (Iterator<SingleVariableDeclaration> it = node.parameters().iterator(); it.hasNext();) { SingleVariableDeclaration v = it.next(); v.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(")");//$NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS8) { List<Dimension> dimensions = node.extraDimensions(); for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext();) { Dimension e = it.next(); e.accept(this); } } else { for (int i = 0; i < node.getExtraDimensions(); i++) { this.fBuffer.append("[]"); //$NON-NLS-1$ } } List<? extends ASTNode> thrownExceptions = node.getAST().apiLevel() >= AST.JLS8 ? node.thrownExceptionTypes() : getThrownExceptions(node); if (!thrownExceptions.isEmpty()) { this.fBuffer.append(" throws ");//$NON-NLS-1$ for (Iterator<? extends ASTNode> it = thrownExceptions.iterator(); it.hasNext();) { ASTNode n = it.next(); n.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ } if (node.getBody() == null) { this.fBuffer.append(";");//$NON-NLS-1$ } else { node.getBody().accept(this); } return false; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link MethodDeclaration}s. */ @Override/*from w w w .j a v a2s . co m*/ public boolean visit(MethodDeclaration node) { sync(node); visitAndBreakModifiers(node.modifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); builder.open(plusFour); { BreakTag breakBeforeName = genSym(); BreakTag breakBeforeType = genSym(); builder.open(ZERO); { boolean first = true; if (!node.typeParameters().isEmpty()) { visitTypeParameters(node.typeParameters(), ZERO, BreakOrNot.NO); first = false; } boolean openedNameAndTypeScope = false; // constructor-like declarations that don't match the name of the enclosing class are // parsed as method declarations with a null return type if (!node.isConstructor() && node.getReturnType2() != null) { if (!first) { builder.breakOp(Doc.FillMode.INDEPENDENT, " ", ZERO, Optional.of(breakBeforeType)); } else { first = false; } if (!openedNameAndTypeScope) { builder.open(Indent.If.make(breakBeforeType, plusFour, ZERO)); openedNameAndTypeScope = true; } node.getReturnType2().accept(this); } if (!first) { builder.breakOp(Doc.FillMode.INDEPENDENT, " ", ZERO, Optional.of(breakBeforeName)); } else { first = false; } if (!openedNameAndTypeScope) { builder.open(ZERO); openedNameAndTypeScope = true; } visit(node.getName()); token("("); // end of name and type scope builder.close(); } builder.close(); builder.open(Indent.If.make(breakBeforeName, plusFour, ZERO)); builder.open(Indent.If.make(breakBeforeType, plusFour, ZERO)); builder.open(ZERO); { if (!node.parameters().isEmpty() || node.getReceiverType() != null) { // Break before args. builder.breakToFill(""); visitFormals(node, Optional.fromNullable(node.getReceiverType()), node.getReceiverQualifier(), node.parameters()); } token(")"); extraDimensions(plusFour, node.extraDimensions()); if (!node.thrownExceptionTypes().isEmpty()) { builder.breakToFill(" "); builder.open(plusFour); { visitThrowsClause(node.thrownExceptionTypes()); } builder.close(); } } builder.close(); builder.close(); builder.close(); } builder.close(); if (node.getBody() == null) { token(";"); } else { builder.space(); visitBlock(node.getBody(), CollapseEmptyOrNot.YES, AllowLeadingBlankLine.YES, AllowTrailingBlankLine.NO); } builder.guessToken(";"); return false; }
From source file:org.codemucker.jmutate.ast.JAstFlattener.java
License:Open Source License
public boolean visit(MethodDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }/*w w w. j a v a 2s .c om*/ printIndent(); if (node.getAST().apiLevel() == JLS2) { printModifiers(node.getModifiers()); } if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); if (!node.typeParameters().isEmpty()) { this.buffer.append("<");//$NON-NLS-1$ for (Iterator it = node.typeParameters().iterator(); it.hasNext();) { TypeParameter t = (TypeParameter) it.next(); t.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(">");//$NON-NLS-1$ } } if (!node.isConstructor()) { if (node.getAST().apiLevel() == JLS2) { getReturnType(node).accept(this); } else { if (node.getReturnType2() != null) { node.getReturnType2().accept(this); } else { // methods really ought to have a return type this.buffer.append("void");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } node.getName().accept(this); this.buffer.append("(");//$NON-NLS-1$ if (node.getAST().apiLevel() >= AST.JLS8) { Type receiverType = node.getReceiverType(); if (receiverType != null) { receiverType.accept(this); this.buffer.append(' '); SimpleName qualifier = node.getReceiverQualifier(); if (qualifier != null) { qualifier.accept(this); this.buffer.append('.'); } this.buffer.append("this"); //$NON-NLS-1$ if (node.parameters().size() > 0) { this.buffer.append(','); } } } for (Iterator it = node.parameters().iterator(); it.hasNext();) { SingleVariableDeclaration v = (SingleVariableDeclaration) it.next(); v.accept(this); if (it.hasNext()) { this.buffer.append(",");//$NON-NLS-1$ } } this.buffer.append(")");//$NON-NLS-1$ int size = node.getExtraDimensions(); if (node.getAST().apiLevel() >= AST.JLS8) { List dimensions = node.extraDimensions(); for (int i = 0; i < size; i++) { visit((Dimension) dimensions.get(i)); } } else { for (int i = 0; i < size; i++) { this.buffer.append("[]"); //$NON-NLS-1$ } } if (node.getAST().apiLevel() < AST.JLS8) { if (!thrownExceptions(node).isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator it = thrownExceptions(node).iterator(); it.hasNext();) { Name n = (Name) it.next(); n.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } } else { if (!node.thrownExceptionTypes().isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator it = node.thrownExceptionTypes().iterator(); it.hasNext();) { Type n = (Type) it.next(); n.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ } } if (node.getBody() == null) { this.buffer.append(";\n");//$NON-NLS-1$ } else { node.getBody().accept(this); } return false; }