List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration setVarargs
public void setVarargs(boolean variableArity)
From source file:ch.acanda.eclipse.pmd.java.resolution.design.UseVarargsQuickFix.java
License:Open Source License
@Override protected boolean apply(final SingleVariableDeclaration node) { node.setType(copy(((ArrayType) node.getType()).getComponentType())); node.setVarargs(true); return true;/*from w ww .j a v a 2s .c om*/ // final SingleVariableDeclaration varargsDeclaration = copy(node); // varargsDeclaration.setVarargs(true); // final Type type = copy(((ArrayType) node.getType()).getComponentType()); // varargsDeclaration.setType(type); // return replace(node, varargsDeclaration); }
From source file:java5totext.input.JDTVisitor.java
License:Open Source License
@Override public void endVisit(org.eclipse.jdt.core.dom.SingleVariableDeclaration node) { SingleVariableDeclaration element = (SingleVariableDeclaration) this.binding.get(node); this.initializeNode(element, node); element.setExtraArrayDimensions(node.getExtraDimensions()); element.setVarargs(node.isVarargs()); if (this.binding.get(node.getInitializer()) != null) { element.setInitializer((Expression) this.binding.get(node.getInitializer())); }/*from w w w. j a v a 2 s. co m*/ if (this.binding.get(node.getType()) != null) { element.setType((NamedElementRef) this.binding.get(node.getType())); } element.setName(node.getName().getIdentifier()); // visibility modifiers for (Object modifierNode : node.modifiers()) { if ((((IExtendedModifier) modifierNode).isModifier()) && (this.binding.get(modifierNode) != null)) { element.getModifiers().add((Modifier) this.binding.get(modifierNode)); } } JDTVisitorUtils.manageBindingDeclaration(element, node.getName(), this); }
From source file:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java
License:Open Source License
/** * Creates and adds the necessary argument declarations to the given factory method.<br> * An argument is needed for each original constructor argument for which the * evaluation of the actual arguments across all calls was not able to be * pushed inside the factory method (e.g. arguments with side-effects, references * to fields if the factory method is to be static or reside in a factory class, * or arguments that varied across the set of constructor calls).<br> * <code>fArgTypes</code> identifies such arguments by a <code>null</code> value. * @param ast utility object used to create AST nodes * @param newMethod the <code>MethodDeclaration</code> for the factory method *///from ww w . j a v a2s . c o m private void createFactoryMethodSignature(AST ast, MethodDeclaration newMethod) { List<SingleVariableDeclaration> argDecls = newMethod.parameters(); for (int i = 0; i < fArgTypes.length; i++) { SingleVariableDeclaration argDecl = ast.newSingleVariableDeclaration(); Type argType; if (i == (fArgTypes.length - 1) && fCtorIsVarArgs) { // The trailing varargs arg has an extra array dimension, compared to // what we need to pass to setType()... argType = typeNodeForTypeBinding(fArgTypes[i].getElementType(), fArgTypes[i].getDimensions() - 1, ast); argDecl.setVarargs(true); } else argType = typeNodeForTypeBinding(fArgTypes[i], 0, ast); argDecl.setName(ast.newSimpleName(fFormalArgNames[i])); argDecl.setType(argType); argDecls.add(argDecl); } ITypeBinding[] ctorExcepts = fCtorBinding.getExceptionTypes(); List<Name> exceptions = newMethod.thrownExceptions(); for (int i = 0; i < ctorExcepts.length; i++) { String excName = fImportRewriter.addImport(ctorExcepts[i]); exceptions.add(ASTNodeFactory.newName(ast, excName)); } copyTypeParameters(ast, newMethod); }
From source file:org.decojer.cavaj.utils.Expressions.java
License:Open Source License
/** * New single variable declaration./*from ww w . j a v a2 s . com*/ * * @param m * method declaration * @param paramTs * parameter types * @param paramAss * parameter annotations * @param i * index * @param contextT * type declaration (context) * @return single variable declaration */ @SuppressWarnings("deprecation") public static SingleVariableDeclaration newSingleVariableDeclaration(final M m, final T[] paramTs, final A[][] paramAss, final int i, final T contextT) { final AST ast = contextT.getCu().getAst(); final SingleVariableDeclaration singleVariableDeclaration = ast.newSingleVariableDeclaration(); if (paramAss != null && i < paramAss.length) { final List<IExtendedModifier> modifiers = singleVariableDeclaration.modifiers(); assert modifiers != null; Annotations.decompileAnnotations(paramAss[i], modifiers, contextT); } final T paramT = paramTs[i]; assert paramT != null; final Type methodParameterType = newType(paramT, contextT); // decompile varargs (flag set, ArrayType and last method param) if (i == paramTs.length - 1 && m.isVarargs()) { if (methodParameterType instanceof ArrayType) { singleVariableDeclaration.setVarargs(true); // must copy because we cannot delete mandatory ArrayType.componentType if (ast.apiLevel() <= AST.JLS4) { singleVariableDeclaration.setType( (Type) ASTNode.copySubtree(ast, ((ArrayType) methodParameterType).getComponentType())); } else { singleVariableDeclaration.setType( (Type) ASTNode.copySubtree(ast, ((ArrayType) methodParameterType).getElementType())); } } else { log.warn("Last method parameter is no ArrayType, but method '" + m.getName() + "' has vararg attribute!"); // try handling as normal type singleVariableDeclaration.setType(methodParameterType); } } else { singleVariableDeclaration.setType(methodParameterType); } singleVariableDeclaration.setName(newSimpleName(m.getParamName(i), ast)); return singleVariableDeclaration; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public SingleVariableDeclaration convert(org.eclipse.jdt.internal.compiler.ast.Argument argument) { SingleVariableDeclaration variableDecl = new SingleVariableDeclaration(this.ast); setModifiers(variableDecl, argument); final SimpleName name = new SimpleName(this.ast); name.internalSetIdentifier(new String(argument.name)); int start = argument.sourceStart; int nameEnd = argument.sourceEnd; name.setSourceRange(start, nameEnd - start + 1); variableDecl.setName(name);//from w w w.j a v a 2 s .c o m final int typeSourceEnd = argument.type.sourceEnd; final int extraDimensions = retrieveExtraDimension(nameEnd + 1, typeSourceEnd); variableDecl.setExtraDimensions(extraDimensions); final boolean isVarArgs = argument.isVarArgs(); // GROOVY start // Do not try to change source ends for var args. Groovy assumes that // all methods that have an array as the last param are varargs /* old { if (isVarArgs && extraDimensions == 0) { } new */ if (argument.binding != null && scannerAvailable(argument.binding.declaringScope) && isVarArgs && extraDimensions == 0) { // GROOVY end // remove the ellipsis from the type source end argument.type.sourceEnd = retrieveEllipsisStartPosition(argument.type.sourceStart, typeSourceEnd); } Type type = convertType(argument.type); int typeEnd = type.getStartPosition() + type.getLength() - 1; int rightEnd = Math.max(typeEnd, argument.declarationSourceEnd); /* * There is extra work to do to set the proper type positions * See PR http://bugs.eclipse.org/bugs/show_bug.cgi?id=23284 */ if (isVarArgs) { setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions + 1); if (extraDimensions != 0) { variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED); } } else { setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions); } variableDecl.setSourceRange(argument.declarationSourceStart, rightEnd - argument.declarationSourceStart + 1); if (isVarArgs) { switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED); break; default: variableDecl.setVarargs(true); } } if (this.resolveBindings) { recordNodes(name, argument); recordNodes(variableDecl, argument); variableDecl.resolveBinding(); } return variableDecl; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.SingleVariableDeclaration node) { SingleVariableDeclaration element = (SingleVariableDeclaration) this.binding.get(node); initializeNode(element, node);//from ww w . j a v a 2s . c o m element.setExtraArrayDimensions(node.getExtraDimensions()); element.setVarargs(node.isVarargs()); if (this.binding.get(node.getInitializer()) != null) { element.setInitializer( JDTVisitorUtils.completeExpression(this.binding.get(node.getInitializer()), this)); } if (this.binding.get(node.getType()) != null) { if (this.isINCREMENTALDISCOVERING && element.getType() != null) { // To avoid to re-create an existing access types deepRemove(element.getType()); element.setType(null); } element.setType(JDTVisitorUtils.completeTypeAccess(this.binding.get(node.getType()), this)); } element.setName(node.getName().getIdentifier()); // visibility modifiers Modifier modiscoModifier = this.factory.createModifier(); element.setModifier(modiscoModifier); modiscoModifier.setSingleVariableDeclaration(element); for (Object modifierNode : node.modifiers()) { if (((IExtendedModifier) modifierNode).isModifier()) { manageModifier((org.eclipse.jdt.core.dom.Modifier) modifierNode, modiscoModifier); } } // annotation modifiers for (Object modifierNode : node.modifiers()) { if (((IExtendedModifier) modifierNode).isAnnotation()) { Annotation annotation = (Annotation) this.binding.get(modifierNode); if (annotation != null) { element.getAnnotations().add(annotation); } } } JDTVisitorUtils.manageBindingDeclaration(element, node.getName(), this); }