List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration getExtraDimensions
public int getExtraDimensions()
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 w w w . j ava2 s.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:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(MethodDeclaration node) { List<boa.types.Ast.Method> list = methods.peek(); Method.Builder b = Method.newBuilder(); // b.setPosition(pos.build()); if (node.isConstructor()) b.setName("<init>"); else/* ww w . j a va2s. co m*/ b.setName(node.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); if (node.getReturnType2() != null) { String name = typeName(node.getReturnType2()); for (int i = 0; i < node.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } else { tb.setName(getIndex("void")); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } for (Object t : node.typeParameters()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = ((TypeParameter) t).getName().getFullyQualifiedName(); String bounds = ""; for (Object o : ((TypeParameter) t).typeBounds()) { if (bounds.length() > 0) bounds += " & "; bounds += typeName((org.eclipse.jdt.core.dom.Type) o); } if (bounds.length() > 0) name = name + " extends " + bounds; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tp.build()); } for (Object o : node.parameters()) { SingleVariableDeclaration ex = (SingleVariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; if (ex.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.addArguments(vb.build()); } for (Object o : node.thrownExceptions()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); tp.setName(getIndex(((Name) o).getFullyQualifiedName())); tp.setKind(boa.types.Ast.TypeKind.CLASS); b.addExceptionTypes(tp.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } list.add(b.build()); return false; }
From source file:boa.datagen.util.Java8Visitor.java
License:Apache License
@Override public boolean visit(MethodDeclaration node) { List<boa.types.Ast.Method> list = methods.peek(); Method.Builder b = Method.newBuilder(); // b.setPosition(pos.build()); if (node.isConstructor()) b.setName("<init>"); else/*from w w w. j av a 2 s .com*/ b.setName(node.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); if (node.getReturnType2() != null) { String name = typeName(node.getReturnType2()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < node.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } else { tb.setName(getIndex("void")); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } for (Object t : node.typeParameters()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = ((TypeParameter) t).getName().getFullyQualifiedName(); String bounds = ""; for (Object o : ((TypeParameter) t).typeBounds()) { if (bounds.length() > 0) bounds += " & "; bounds += typeName((org.eclipse.jdt.core.dom.Type) o); } if (bounds.length() > 0) name = name + " extends " + bounds; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tp.build()); } if (node.getReceiverType() != null) { Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName("this"); boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(node.getReceiverType()); if (node.getReceiverQualifier() != null) name = node.getReceiverQualifier().getFullyQualifiedName() + "." + name; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); // FIXME change to receiver? or something? vb.setVariableType(tp.build()); b.addArguments(vb.build()); } for (Object o : node.parameters()) { SingleVariableDeclaration ex = (SingleVariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; if (ex.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.addArguments(vb.build()); } for (Object o : node.thrownExceptionTypes()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) o))); tp.setKind(boa.types.Ast.TypeKind.CLASS); b.addExceptionTypes(tp.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } list.add(b.build()); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(MethodDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from w w w.ja v a 2s.c om printIndent(); hook_beforeVisitMethodDeclaration(node); if (node.getAST().apiLevel() >= AST.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.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$ 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$ for (int i = 0; i < node.getExtraDimensions(); i++) { this.buffer.append("[]"); //$NON-NLS-1$ } if (!node.thrownExceptions().isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator it = node.thrownExceptions().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$ } if (node.getBody() == null) { this.buffer.append(";\n");//$NON-NLS-1$ } else { node.getBody().accept(this); } return false; }
From source file:de.ovgu.cide.export.physical.ahead.FSTComposerJavaPrettyPrinter.java
License:Open Source License
public boolean visit(MethodDeclaration node) { currentMethod.push(node);/* w ww . j av a2 s . c om*/ if (!node.isConstructor() || currentRefinement.size() == 0 || !currentRefinement.peek().refinements().contains(node)) return super.visit(node); // only special treatment for constructor refinements! if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printIndent(); // buffer.append("refines "); node.getName().accept(this); this.buffer.append("(");//$NON-NLS-1$ 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$ for (int i = 0; i < node.getExtraDimensions(); i++) { this.buffer.append("[]"); //$NON-NLS-1$ } if (!node.thrownExceptions().isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator<?> it = node.thrownExceptions().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$ } if (node.getBody() == null) { this.buffer.append(";\n");//$NON-NLS-1$ } else { node.getBody().accept(this); } return false; }
From source file:de.ovgu.cide.export.physical.ahead.JakPrettyPrinter.java
License:Open Source License
public boolean visit(MethodDeclaration node) { currentMethod.push(node);//from w w w.j a va 2 s. co m if (!node.isConstructor() || currentRefinement.size() == 0 || !currentRefinement.peek().refinements().contains(node)) return super.visit(node); // only special treatment for constructor refinements! if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } printIndent(); buffer.append("refines "); node.getName().accept(this); this.buffer.append("(");//$NON-NLS-1$ 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$ for (int i = 0; i < node.getExtraDimensions(); i++) { this.buffer.append("[]"); //$NON-NLS-1$ } if (!node.thrownExceptions().isEmpty()) { this.buffer.append(" throws ");//$NON-NLS-1$ for (Iterator<?> it = node.thrownExceptions().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$ } if (node.getBody() == null) { this.buffer.append(";\n");//$NON-NLS-1$ } else { node.getBody().accept(this); } return false; }
From source file:edu.illinois.compositerefactorings.refactorings.copymembertosubtype.CopyMemberToSubtypeRefactoringProcessor.java
License:Open Source License
/** * {@link org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor#createNewMethodDeclarationNode(MemberActionInfo, TypeVariableMaplet[], CompilationUnitRewrite, MethodDeclaration)} *///www.j a va 2 s.c o m private MethodDeclaration createNewMethodDeclarationNode(MemberActionInfo info, TypeVariableMaplet[] mapping, CompilationUnitRewrite rewriter, MethodDeclaration oldMethod) throws JavaModelException { Assert.isTrue(!info.isFieldInfo()); IMethod method = (IMethod) info.getMember(); ASTRewrite rewrite = rewriter.getASTRewrite(); AST ast = rewrite.getAST(); MethodDeclaration newMethod = ast.newMethodDeclaration(); copyBodyOfPushedDownMethod(rewrite, method, oldMethod, newMethod, mapping); newMethod.setConstructor(oldMethod.isConstructor()); newMethod.setExtraDimensions(oldMethod.getExtraDimensions()); if (info.copyJavadocToCopiesInSubclasses()) copyJavadocNode(rewrite, oldMethod, newMethod); final IJavaProject project = rewriter.getCu().getJavaProject(); if (info.isNewMethodToBeDeclaredAbstract() && JavaModelUtil.is50OrHigher(project) && JavaPreferencesSettings.getCodeGenerationSettings(project).overrideAnnotation) { final MarkerAnnotation annotation = ast.newMarkerAnnotation(); annotation.setTypeName(ast.newSimpleName("Override")); //$NON-NLS-1$ newMethod.modifiers().add(annotation); } copyAnnotations(oldMethod, newMethod); newMethod.modifiers().addAll( ASTNodeFactory.newModifiers(ast, info.getNewModifiersForCopyInSubclass(oldMethod.getModifiers()))); newMethod.setName(ast.newSimpleName(oldMethod.getName().getIdentifier())); copyReturnType(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping); copyParameters(rewrite, method.getCompilationUnit(), oldMethod, newMethod, mapping); copyThrownExceptions(oldMethod, newMethod); copyTypeParameters(oldMethod, newMethod); return newMethod; }
From source file:java5totext.input.JDTVisitor.java
License:Open Source License
@Override public void endVisit(org.eclipse.jdt.core.dom.MethodDeclaration node) { MethodDeclaration element = (MethodDeclaration) this.binding.get(node); this.initializeNode(element, node); element.setExtraArrayDimensions(node.getExtraDimensions()); element.setConstructor(node.isConstructor()); element.setVarargs(false);/* ww w. j a v a 2 s . com*/ for (Iterator<?> i = node.parameters().iterator(); i.hasNext();) { SingleVariableDeclaration itElement = (SingleVariableDeclaration) this.binding.get(i.next()); if (itElement != null) element.getParameters().add(itElement); } if (this.binding.get(node.getBody()) != null) element.setBody((Block) this.binding.get(node.getBody())); for (Iterator<?> i = node.thrownExceptions().iterator(); i.hasNext();) { NamedElementRef itElement = (NamedElementRef) this.binding.get(i.next()); if (itElement != null) element.getThrownExceptions().add(itElement); } element.setName(node.getName().getIdentifier()); if (this.binding.get(node.getReturnType2()) != null) element.setReturnType((NamedElementRef) this.binding.get(node.getReturnType2())); for (Iterator<?> i = node.typeParameters().iterator(); i.hasNext();) { TypeParameter itElement = (TypeParameter) this.binding.get(i.next()); if (itElement != null) element.getTypeParameters().add(itElement); } endVisitBD(node, element); this.localBindings.resolveBindings(); // localBindings should be kept if method is declared in anonymous class declared in a method body if (!(node.getParent() instanceof org.eclipse.jdt.core.dom.AnonymousClassDeclaration || node.getParent().getParent() instanceof org.eclipse.jdt.core.dom.TypeDeclarationStatement)) this.localBindings = null; JDTVisitorUtils.manageBindingDeclaration(element, node.getName(), this); }
From source file:jmockit.assist.MockMethodCompletionProposal.java
License:Open Source License
@SuppressWarnings("unchecked") private void setReturnStatement(final MethodDeclaration stub, final IMethodBinding methodToOverride, final ITypeBinding declaringType, final AST ast, final ASTRewrite rewrite) throws JavaModelException, CoreException { Expression expression = ASTNodeFactory.newDefaultExpression(ast, stub.getReturnType2(), stub.getExtraDimensions()); if (expression != null) { ReturnStatement returnStatement = ast.newReturnStatement(); returnStatement.setExpression(expression); String delimiter = cunit.findRecommendedLineSeparator(); Map<String, String> options = fJavaProject.getOptions(true); String bodyStatement = ASTNodes.asFormattedString(returnStatement, 0, delimiter, options); String placeHolder = CodeGeneration.getMethodBodyContent(cunit, declaringType.getName(), methodToOverride.getName(), false, bodyStatement, delimiter); if (placeHolder != null) { ASTNode todoNode = rewrite.createStringPlaceholder(placeHolder, ASTNode.RETURN_STATEMENT); stub.getBody().statements().clear(); stub.getBody().statements().add(todoNode); }// w w w . ja v a 2 s . co m } }
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); }//from w w w .jav a 2s . co m 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; }