List of usage examples for org.eclipse.jdt.internal.compiler.ast Argument isVarArgs
public boolean isVarArgs()
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 2s . co 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:spoon.support.builder.JDTTreeBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean visit(Argument argument, BlockScope scope) { CtParameter<?> p = factory.Core().createParameter(); p.setSimpleName(new String(argument.name)); p.setVarArgs(argument.isVarArgs()); p.setModifiers(getModifier(argument.modifiers)); if (argument.type != null) p.setType(references.getTypeReference(argument.type.resolvedType)); context.enter(p, argument);/*from w w w . jav a 2 s .co m*/ if (argument.initialization != null) argument.initialization.traverse(this, scope); if (argument.annotations != null) for (Annotation a : argument.annotations) a.traverse(this, scope); return false; }
From source file:spoon.support.compiler.jdt.JDTTreeBuilder.java
License:Open Source License
@Override public boolean visit(Argument argument, BlockScope scope) { CtParameter<Object> p = factory.Core().createParameter(); p.setSimpleName(new String(argument.name)); p.setVarArgs(argument.isVarArgs()); p.setModifiers(getModifiers(argument.modifiers)); if (argument.type != null) { p.setType(references.getTypeReference(argument.type.resolvedType)); } else if (argument.binding != null && argument.binding.type != null) { context.isLambdaParameterImplicitlyTyped = false; if (argument.binding.type instanceof WildcardBinding) { p.setType(references.getTypeReference((((WildcardBinding) argument.binding.type).bound))); } else {/*from w w w . j a v a 2s.co m*/ p.setType(references.getTypeReference((argument.binding.type))); } context.isLambdaParameterImplicitlyTyped = true; } context.enter(p, argument); if (argument.initialization != null) { argument.initialization.traverse(this, scope); } if (argument.annotations != null) { for (Annotation a : argument.annotations) { // TODO Sorry for that but there is a bug in JDT : https://bugs.eclipse.org/bugs/show_bug.cgi?id=459528 if (isContainsInTypeAnnotation(argument.type.resolvedType, a)) { a.traverse(this, scope); } } } return false; }
From source file:spoon.support.compiler.jdt.JDTTreeBuilderHelper.java
License:Open Source License
/** * Creates a parameter. If the argument have a type == null, we get the type from its binding. A type == null is possible when * this type is implicit like in a lambda where you don't need to specify the type of parameters. * * @param argument// w w w .j a v a2s .com * Used to get the name of the parameter, the modifiers, know if it is a var args parameter. * @return a parameter. */ <T> CtParameter<T> createParameter(Argument argument) { CtParameter<T> p = jdtTreeBuilder.getFactory().Core().createParameter(); p.setSimpleName(CharOperation.charToString(argument.name)); p.setVarArgs(argument.isVarArgs()); p.setExtendedModifiers(getModifiers(argument.modifiers, false, false)); if (argument.binding != null && argument.binding.type != null && argument.type == null) { p.setType(jdtTreeBuilder.getReferencesBuilder().<T>getTypeReference(argument.binding.type)); p.getType().setImplicit(argument.type == null); if (p.getType() instanceof CtArrayTypeReference) { ((CtArrayTypeReference) p.getType()).getComponentType().setImplicit(argument.type == null); } } return p; }