List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration SingleVariableDeclaration
SingleVariableDeclaration(AST ast)
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 va2 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.jdt.core.dom.ASTConverter.java
License:Open Source License
protected SingleVariableDeclaration convertToSingleVariableDeclaration(LocalDeclaration localDeclaration) { final SingleVariableDeclaration variableDecl = new SingleVariableDeclaration(this.ast); setModifiers(variableDecl, localDeclaration); final SimpleName name = new SimpleName(this.ast); name.internalSetIdentifier(new String(localDeclaration.name)); int start = localDeclaration.sourceStart; int nameEnd = localDeclaration.sourceEnd; name.setSourceRange(start, nameEnd - start + 1); variableDecl.setName(name);/*from ww w . ja v a 2 s. c o m*/ final int extraDimensions = retrieveExtraDimension(nameEnd + 1, localDeclaration.type.sourceEnd); variableDecl.setExtraDimensions(extraDimensions); Type type = convertType(localDeclaration.type); int typeEnd = type.getStartPosition() + type.getLength() - 1; int rightEnd = Math.max(typeEnd, localDeclaration.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 */ setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions); variableDecl.setSourceRange(localDeclaration.declarationSourceStart, rightEnd - localDeclaration.declarationSourceStart + 1); if (this.resolveBindings) { recordNodes(name, localDeclaration); recordNodes(variableDecl, localDeclaration); variableDecl.resolveBinding(); } return variableDecl; }