/** * Get JDT PrimitiveType for the given type name. * * @param ast * JDT AST tree * @param typeName * input type name * @return JDT PrimitiveType */ public PrimitiveType getAstPrimitiveType(AST ast, String typeName) { Code typeCode = dataTypeUtils.getPrimitiveTypeCodes().get( typeName.toLowerCase()); PrimitiveType primitiveType = ast.newPrimitiveType(typeCode); return primitiveType; }
/** * Returns the type in this type literal expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the paramter type. * * @return the parameter type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this cast expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this cast expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this cast expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this cast expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this cast expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the paramter type. * * @return the parameter type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
/** * Returns the type in this type literal expression. * * @return the type */ public Type getType() { if (this.type == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.type == null) { preLazyInit(); this.type = this.ast.newPrimitiveType(PrimitiveType.INT); postLazyInit(this.type, TYPE_PROPERTY); } } } return this.type; }
private Type simpleType(final String name) { final Code primitiveTypeCode = PrimitiveType.toCode(name); if (primitiveTypeCode != null) { return ast.newPrimitiveType(primitiveTypeCode); } return ast.newSimpleType(ast.newSimpleName(name)); }
@Override protected TypeLiteral convertObject(String string, AST ast) { org.eclipse.jdt.core.dom.Type type = ast.newPrimitiveType(PrimitiveType.toCode(string)); TypeLiteral typeLiteral = ast.newTypeLiteral(); typeLiteral.setType(type); return typeLiteral; }
/** * Returns the array type in this array creation expression. * * @return the array type */ public ArrayType getType() { if (this.arrayType == null) { // lazy init must be thread-safe for readers synchronized (this) { if (this.arrayType == null) { preLazyInit(); this.arrayType = this.ast.newArrayType( this.ast.newPrimitiveType(PrimitiveType.INT)); postLazyInit(this.arrayType, TYPE_PROPERTY); } } } return this.arrayType; }
/** * @return a statement in form of <code>final int maxLen = 10;</code> */ protected VariableDeclarationStatement createMaxLenDeclaration() { VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fMaxLenVariableName)); fragment.setInitializer(fAst.newNumberLiteral(String.valueOf(fContext.getLimitItemsValue()))); VariableDeclarationStatement declExpression= fAst.newVariableDeclarationStatement(fragment); declExpression.setType(fAst.newPrimitiveType(PrimitiveType.INT)); declExpression.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD)); return declExpression; }
/** * @return a statement in form of <code>final int maxLen = 10;</code> */ protected VariableDeclarationStatement createMaxLenDeclaration() { VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment(); fragment.setName(fAst.newSimpleName(fMaxLenVariableName)); fragment.setInitializer(fAst.newNumberLiteral(String.valueOf(fContext.getLimitItemsValue()))); VariableDeclarationStatement declExpression= fAst.newVariableDeclarationStatement(fragment); declExpression.setType(fAst.newPrimitiveType(PrimitiveType.INT)); declExpression.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD)); return declExpression; }
private void addNewConstructorToSubclass(AbstractTypeDeclaration subclass, CompilationUnitRewrite cuRewrite) { AST ast= subclass.getAST(); MethodDeclaration newConstructor= ast.newMethodDeclaration(); newConstructor.setName(ast.newSimpleName(subclass.getName().getIdentifier())); newConstructor.setConstructor(true); newConstructor.setJavadoc(null); newConstructor.modifiers().addAll(ASTNodeFactory.newModifiers(ast, getAccessModifier(subclass))); newConstructor.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); Block body= ast.newBlock(); newConstructor.setBody(body); SuperConstructorInvocation superCall= ast.newSuperConstructorInvocation(); addArgumentsToNewSuperConstructorCall(superCall, cuRewrite); body.statements().add(superCall); String msg= RefactoringCoreMessages.ChangeSignatureRefactoring_add_constructor; TextEditGroup description= cuRewrite.createGroupDescription(msg); cuRewrite.getASTRewrite().getListRewrite(subclass, subclass.getBodyDeclarationsProperty()).insertFirst(newConstructor, description); // TODO use AbstractTypeDeclaration }
private Type copyType(final Type type) { switch (type.getNodeType()) { case ARRAY_TYPE: final ArrayType arrayType = (ArrayType) type; return ast.newArrayType( copyType(arrayType.getElementType()), arrayType.getDimensions()); case PRIMITIVE_TYPE: final Code code = ((PrimitiveType) type).getPrimitiveTypeCode(); return ast.newPrimitiveType(code); case QUALIFIED_TYPE: return type(type.resolveBinding().getQualifiedName()); case SIMPLE_TYPE: final SimpleType sType = (SimpleType) type; return ast.newSimpleType(copy(sType.getName())); } throw new NotImplementedException(null, "Unknown type for type " + type); }
private Expression createShiftAssignment(Expression shift1, Expression shift2) { // (int)(element ^ (element >>> 32)); // see implementation in Arrays.hashCode(), Double.hashCode() and // Long.hashCode() CastExpression ce= fAst.newCastExpression(); ce.setType(fAst.newPrimitiveType(PrimitiveType.INT)); InfixExpression unsignedShiftRight= fAst.newInfixExpression(); unsignedShiftRight.setLeftOperand(shift1); unsignedShiftRight.setRightOperand(fAst.newNumberLiteral("32")); //$NON-NLS-1$ unsignedShiftRight.setOperator(Operator.RIGHT_SHIFT_UNSIGNED); InfixExpression xor= fAst.newInfixExpression(); xor.setLeftOperand(shift2); xor.setRightOperand(parenthesize(unsignedShiftRight)); xor.setOperator(InfixExpression.Operator.XOR); ce.setExpression(parenthesize(xor)); return ce; }
private Expression createShiftAssignment(Expression shift1, Expression shift2) { // (int)(element ^ (element >>> 32)); // see implementation in Arrays.hashCode(), Double.hashCode() and // Long.hashCode() CastExpression ce= fAst.newCastExpression(); ce.setType(fAst.newPrimitiveType(PrimitiveType.INT)); InfixExpression unsignedShiftRight= fAst.newInfixExpression(); unsignedShiftRight.setLeftOperand(shift1); unsignedShiftRight.setRightOperand(fAst.newNumberLiteral("32")); //$NON-NLS-1$ unsignedShiftRight.setOperator(Operator.RIGHT_SHIFT_UNSIGNED); InfixExpression xor= fAst.newInfixExpression(); xor.setLeftOperand(shift2); xor.setRightOperand(parenthesize(unsignedShiftRight)); xor.setOperator(InfixExpression.Operator.XOR); ce.setExpression(parenthesize(xor)); return ce; }
private Expression createShiftAssignment(Expression shift1, Expression shift2) { // (int)(element ^ (element >>> 32)); // see implementation in Arrays.hashCode(), Double.hashCode() and // Long.hashCode() CastExpression ce= fAst.newCastExpression(); ce.setType(fAst.newPrimitiveType(PrimitiveType.INT)); InfixExpression unsignedShiftRight= fAst.newInfixExpression(); unsignedShiftRight.setLeftOperand(shift1); unsignedShiftRight.setRightOperand(fAst.newNumberLiteral("32")); //$NON-NLS-1$ unsignedShiftRight.setOperator(Operator.RIGHT_SHIFT_UNSIGNED); InfixExpression xor= fAst.newInfixExpression(); xor.setLeftOperand(shift2); xor.setRightOperand(parenthesize(unsignedShiftRight)); xor.setOperator(InfixExpression.Operator.XOR); ce.setExpression(parenthesize(xor)); return ce; }