List of usage examples for org.eclipse.jdt.core.dom NumberLiteral setToken
public void setToken(String token)
From source file:de.crowdcode.kissmda.cartridges.simplejava.EnumGenerator.java
License:Apache License
@SuppressWarnings("unchecked") void chooseLiteralTypeAndAddToEnumConstantArguments(AST ast, EnumConstantDeclaration ec, Slot slot, Type type) { EList<ValueSpecification> valueSpecifications = slot.getValues(); for (ValueSpecification valueSpecification : valueSpecifications) { if (type.getName().equalsIgnoreCase("Integer")) { NumberLiteral numberLiteral = ast.newNumberLiteral(); numberLiteral.setToken(String.valueOf(valueSpecification.integerValue())); ec.arguments().add(numberLiteral); } else if (type.getName().equalsIgnoreCase("Long")) { NumberLiteral numberLiteral = ast.newNumberLiteral(); numberLiteral.setToken(String.valueOf(valueSpecification.integerValue()).concat("L")); ec.arguments().add(numberLiteral); } else if (type.getName().equalsIgnoreCase("Boolean")) { BooleanLiteral booleanLiteral = ast.newBooleanLiteral(valueSpecification.booleanValue()); ec.arguments().add(booleanLiteral); } else if (type.getName().equalsIgnoreCase("String")) { StringLiteral stringLiteral = ast.newStringLiteral(); stringLiteral.setLiteralValue(valueSpecification.stringValue()); ec.arguments().add(stringLiteral); }/*from w w w. j a v a2 s . c o m*/ } }
From source file:de.crowdcode.kissmda.cartridges.simplejava.ExceptionGenerator.java
License:Apache License
/** * Generate the serial version UID for the Exception class. * //from ww w. ja va 2 s.c o m * @param clazz * UML class * @param ast * JDT AST tree * @param td * JDT type declaration (Class) */ @SuppressWarnings("unchecked") public void generateSerialVersionUID(Classifier clazz, AST ast, TypeDeclaration td) { VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); SimpleName variableName = ast.newSimpleName("serialVersionUID"); fragment.setName(variableName); NumberLiteral initializer = ast.newNumberLiteral(); initializer.setToken("1L"); fragment.setInitializer(initializer); FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(fragment); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD)); fieldDeclaration.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD)); fieldDeclaration.setType(ast.newPrimitiveType(PrimitiveType.LONG)); td.bodyDeclarations().add(fieldDeclaration); }
From source file:net.sf.eclipsecs.ui.quickfixes.misc.UpperEllQuickfix.java
License:Open Source License
/** * {@inheritDoc}/*from w ww .j av a 2 s. c om*/ */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { public boolean visit(NumberLiteral node) { if (containsPosition(node, markerStartOffset)) { String token = node.getToken(); if (token.endsWith("l")) { //$NON-NLS-1$ token = token.replace('l', 'L'); node.setToken(token); } } return true; } }; }
From source file:org.autorefactor.refactoring.rules.CapitalizeLongLiteralRefactoring.java
License:Open Source License
private void replaceLong(final NumberLiteral node, final String token) { final ASTBuilder b = this.ctx.getASTBuilder(); final NumberLiteral replacement = b.numberLiteral(); final String newToken = token.substring(0, token.length() - 1) + "L"; replacement.setToken(newToken); ctx.getRefactorings().replace(node, replacement); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation1(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);/* w w w. java2 s.c om*/ annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation2(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);/*from w w w .j a v a2s . c o m*/ annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation3(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);// w ww . j ava 2 s. com annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation4(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);//from www. j av a 2 s .com annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation5(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);//www . j a v a 2 s .co m annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }
From source file:org.eclipse.jpt.common.core.tests.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapterTests.java
License:Open Source License
void editNewSingleMemberAnnotation6(ModifiedDeclaration declaration) { DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); assertNull(annotation);/* w ww . jav a 2 s .c o m*/ annotation = daa.newSingleMemberAnnotation(declaration); NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); numberLiteral.setToken("88"); annotation.setValue(numberLiteral); }