List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration modifiers
public List modifiers()
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(FieldDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from ww w. ja va 2 s .co m if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); } node.getType().accept(this); this.fBuffer.append(" ");//$NON-NLS-1$ for (Iterator<VariableDeclarationFragment> it = node.fragments().iterator(); it.hasNext();) { VariableDeclarationFragment f = it.next(); f.accept(this); if (it.hasNext()) { this.fBuffer.append(", ");//$NON-NLS-1$ } } this.fBuffer.append(";");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(FieldDeclaration node) { List<boa.types.Ast.Variable> list = fields.peek(); for (Object o : node.fragments()) { VariableDeclarationFragment f = (VariableDeclarationFragment) o; Variable.Builder b = Variable.newBuilder(); // b.setPosition(pos.build()); // FIXME b.setName(f.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else/*from ww w .j a v a2 s . co m*/ ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = typeName(node.getType()); for (int i = 0; i < f.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setVariableType(tb.build()); if (f.getInitializer() != null) { f.getInitializer().accept(this); b.setInitializer(expressions.pop()); } list.add(b.build()); } return false; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from www . java2s . c om public boolean visit(FieldDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); } // @Inria pushNode(node, node.toString()); // visitListAsNode(EntityType.MODIFIERS, node.modifiers()); node.getType().accept(this); visitListAsNode(EntityType.FRAGMENTS, node.fragments()); return false; }
From source file:cn.ieclipse.adt.ext.jdt.SourceGenerator.java
License:Apache License
private static void merge(CompilationUnit unit, String pkgName, String typeName, String auth, String dbName, List<String> tableCreators) { unit.recordModifications();/*from www. ja v a 2s .co m*/ AST ast = unit.getAST(); TypeDeclaration type = (TypeDeclaration) unit.types().get(0); ImportDeclaration id = ast.newImportDeclaration(); id.setName(ast.newName("cn.ieclipse.aorm.Session")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.content.UriMatcher")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.database.sqlite.SQLiteDatabase")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.database.sqlite.SQLiteOpenHelper")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("java.net.Uri")); unit.imports().add(id); id = ast.newImportDeclaration(); id.setName(ast.newName("android.content.ContentValue")); unit.imports().add(id); VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("AUTH")); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(auth); vdf.setInitializer(sl); FieldDeclaration fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))); fd.setType(ast.newSimpleType(ast.newSimpleName("String"))); int i = 0; type.bodyDeclarations().add(i++, fd); // URI = Uri.parse("content://" + AUTH); vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("URI")); MethodInvocation mi = ast.newMethodInvocation(); mi.setExpression(ast.newSimpleName("Uri")); mi.setName(ast.newSimpleName("parse")); InfixExpression fix = ast.newInfixExpression(); fix.setOperator(InfixExpression.Operator.PLUS); sl = ast.newStringLiteral(); sl.setLiteralValue("content://"); fix.setLeftOperand(sl); fix.setRightOperand(ast.newSimpleName("AUTH")); mi.arguments().add(fix); vdf.setInitializer(mi); fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL))); fd.setType(ast.newSimpleType(ast.newSimpleName("Uri"))); type.bodyDeclarations().add(i++, fd); // private mOpenHelper; vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("mOpenHelper")); fd = ast.newFieldDeclaration(vdf); fd.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD)); fd.setType(ast.newSimpleType(ast.newName("SQLiteOpenHelper"))); type.bodyDeclarations().add(i++, fd); // private static session; vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("session")); fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers((Modifier.PRIVATE | Modifier.STATIC))); fd.setType(ast.newSimpleType(ast.newName("Session"))); type.bodyDeclarations().add(i++, fd); // public static Session getSession(){ // return session; // } MethodDeclaration md = ast.newMethodDeclaration(); md.modifiers().addAll(ast.newModifiers((Modifier.PUBLIC | Modifier.STATIC))); md.setReturnType2(ast.newSimpleType(ast.newName("Session"))); md.setName(ast.newSimpleName("getSession")); Block methodBlock = ast.newBlock(); ReturnStatement returnStmt = ast.newReturnStatement(); returnStmt.setExpression(ast.newSimpleName("session")); methodBlock.statements().add(returnStmt); md.setBody(methodBlock); type.bodyDeclarations().add(i, md); // modify onCreate rewriteOnCreate(unit, dbName, tableCreators); }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(FieldDeclaration node) { if (node.getJavadoc() != null) { node.getJavadoc().accept(this); }//from w w w. j ava 2 s . c om printIndent(); if (node.getAST().apiLevel() >= AST.JLS3) { printModifiers(node.modifiers()); } node.getType().accept(this); this.buffer.append(" ");//$NON-NLS-1$ for (Iterator it = node.fragments().iterator(); it.hasNext();) { VariableDeclarationFragment f = (VariableDeclarationFragment) it.next(); f.accept(this); if (it.hasNext()) { this.buffer.append(", ");//$NON-NLS-1$ } } this.buffer.append(";\n");//$NON-NLS-1$ return false; }
From source file:com.alex.example.fixlicense.actions.SampleAction.java
License:Open Source License
private FieldDeclaration createLiceseInLineField(AST ast) { VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment(); vdf.setName(ast.newSimpleName("COPYRIGHT")); StringLiteral sl = ast.newStringLiteral(); sl.setLiteralValue(license_inline);/*from w w w. ja va2s . c o m*/ vdf.setInitializer(sl); FieldDeclaration fd = ast.newFieldDeclaration(vdf); fd.modifiers().addAll(ast.newModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL)); fd.setType(ast.newSimpleType(ast.newSimpleName("String"))); return fd; }
From source file:com.google.devtools.j2cpp.translate.ClassConverter.java
License:Open Source License
protected FieldDeclaration createField(String name, ITypeBinding varType, ITypeBinding declaringClass, AST ast) {//from w w w . ja v a2 s . c o m VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment(); SimpleName fieldName = ast.newSimpleName(name); GeneratedVariableBinding fieldBinding = new GeneratedVariableBinding(fieldName.getIdentifier(), Modifier.PRIVATE | Modifier.FINAL, varType, true, false, declaringClass, null); Types.addBinding(fieldName, fieldBinding); fragment.setName(fieldName); Types.addBinding(fragment, fieldBinding); FieldDeclaration field = ast.newFieldDeclaration(fragment); field.setType(Types.makeType(varType)); @SuppressWarnings("unchecked") List<IExtendedModifier> mods = field.modifiers(); // safe by definition mods.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD)); mods.add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD)); return field; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** Visitor method for {@link FieldDeclaration}s. */ @Override/* w w w . ja v a 2 s. c o m*/ public boolean visit(FieldDeclaration node) { sync(node); markForPartialFormat(); addDeclaration(node, node.modifiers(), node.getType(), node.fragments(), fieldAnnotationDirection(node.modifiers())); return false; }
From source file:com.motorola.studio.android.generateviewbylayout.codegenerators.ClassAttributesCodeGenerator.java
License:Apache License
/** * Add attributes based on the GUI items declared on layout XML * <br>//w ww. j av a2 s .c om * GENERATED_CODE_FORMAT: * <br> * private $GUI_TYPE $GUI_ID; * @throws JavaModelException */ @SuppressWarnings("unchecked") private void addAttributes(IProgressMonitor monitor) throws JavaModelException { SubMonitor subMonitor = SubMonitor.convert(monitor); subMonitor.beginTask(CodeUtilsNLS.JavaViewBasedOnLayoutModifier_AddingAttributes, codeGeneratorData.getGuiItems().size()); /* * AST to be written * FieldDeclaration: * [Javadoc] { ExtendedModifier } Type VariableDeclarationFragment * { , VariableDeclarationFragment } ; */ for (LayoutNode node : codeGeneratorData.getGuiItems()) { if ((node.getNodeId() != null) && node.shouldInsertCode()) { boolean containFieldDeclared = getCodeGeneratorData().getJavaLayoutData().getVisitor() .checkIfAttributeAlreadyDeclared(node, false); if (!containFieldDeclared) { //avoid to declare attribute twice Modifier privateMod = typeDeclaration.getAST().newModifier(ModifierKeyword.PRIVATE_KEYWORD); SimpleName guiName; try { guiName = getNodeVariableTypeBasedOnLayoutNode(node); } catch (CoreException e) { throw new JavaModelException(e); } SimpleType guiType = typeDeclaration.getAST().newSimpleType(guiName); VariableDeclarationFragment variableFragment = typeDeclaration.getAST() .newVariableDeclarationFragment(); SimpleName varName = variableFragment.getAST().newSimpleName(node.getNodeId()); variableFragment.setName(varName); FieldDeclaration declaration = typeDeclaration.getAST().newFieldDeclaration(variableFragment); declaration.modifiers().add(privateMod); declaration.setType(guiType); typeDeclaration.bodyDeclarations().add(0, declaration); //add as the first item } } subMonitor.worked(1); } }
From source file:com.motorola.studio.android.generateviewbylayout.codegenerators.RadioButtonCodeGenerator.java
License:Apache License
/** * Creates field with an anonymous class declaration for radio buttons *//*from w w w.j ava 2 s . c om*/ @SuppressWarnings("unchecked") private IfStatement createOnClickListenerForRadioButtons(LayoutNode node) { IfStatement ifSt; Modifier privateMod = typeDeclaration.getAST().newModifier(ModifierKeyword.PRIVATE_KEYWORD); SimpleType listenerType = getListenerSimpleType(JavaViewBasedOnLayoutModifierConstants.VIEW_CLASS, JavaViewBasedOnLayoutModifierConstants.METHOD_ON_CLICK_LISTENER); VariableDeclarationFragment variableFragment = typeDeclaration.getAST().newVariableDeclarationFragment(); SimpleName varName = variableFragment.getAST() .newSimpleName(JavaViewBasedOnLayoutModifierConstants.HANDLER_ONCLICK_LISTENER); variableFragment.setName(varName); FieldDeclaration declaration = typeDeclaration.getAST().newFieldDeclaration(variableFragment); declaration.modifiers().add(privateMod); declaration.setType(listenerType); ClassInstanceCreation classInstanceCreation = typeDeclaration.getAST().newClassInstanceCreation(); SimpleType listenerType2 = getListenerSimpleType(JavaViewBasedOnLayoutModifierConstants.VIEW_CLASS, JavaViewBasedOnLayoutModifierConstants.METHOD_ON_CLICK_LISTENER); classInstanceCreation.setType(listenerType2); AnonymousClassDeclaration classDeclaration = typeDeclaration.getAST().newAnonymousClassDeclaration(); MethodDeclaration methodDeclaration = addMethodDeclaration(ModifierKeyword.PUBLIC_KEYWORD, JavaViewBasedOnLayoutModifierConstants.METHOD_NAME_ON_CLICK, PrimitiveType.VOID, JavaViewBasedOnLayoutModifierConstants.VIEW_CLASS, JavaViewBasedOnLayoutModifierConstants.VIEW_VARIABLE_NAME); Block block = typeDeclaration.getAST().newBlock(); ifSt = createElseIfForEachRadioButtonId(node); block.statements().add(ifSt); methodDeclaration.setBody(block); classDeclaration.bodyDeclarations().add(methodDeclaration); classInstanceCreation.setAnonymousClassDeclaration(classDeclaration); variableFragment.setInitializer(classInstanceCreation); typeDeclaration.bodyDeclarations().add(declaration); return ifSt; }