Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.FieldDeclaration


     * @return field builder
     */
    public FieldBuilder addField(String name, Type type) {
        VariableDeclarationFragment vfrag = getAST().newVariableDeclarationFragment();
        vfrag.setName(getAST().newSimpleName(name));
        FieldDeclaration fdecl = getAST().newFieldDeclaration(vfrag);
        fdecl.setType(type);
        m_fields.add(fdecl);
        return new FieldBuilder(this, fdecl);
    }
View Full Code Here


     * @return sorted pairs
     */
    public StringPair[] getSortedFields() {
        StringPair[] pairs = new StringPair[m_fields.size()];
        for (int i = 0; i < m_fields.size(); i++) {
            FieldDeclaration field = (FieldDeclaration)m_fields.get(i);
            String name = ((VariableDeclarationFragment)field.fragments().get(0)).getName().toString();
            pairs[i] = new StringPair(name, field.getType().toString());
        }
        Arrays.sort(pairs);
        return pairs;
    }
View Full Code Here

            // parse class text to get field declaration
            String text = "class gorph { private static final long serialVersionUID = " + m_serialVersion + "; }";
            m_parser.setSource(text.toCharArray());
            CompilationUnit unit = (CompilationUnit)m_parser.createAST(null);
            TypeDeclaration type = (TypeDeclaration)unit.types().get(0);
            FieldDeclaration field = (FieldDeclaration)type.bodyDeclarations().get(0);
            holder.addField(field);
           
        }
    }
View Full Code Here

          values.sourceLocation(loc, 0, 0)));
    }
   
    ASTNode parentASTNode = node.getParent();
    if (parentASTNode instanceof FieldDeclaration) {
      FieldDeclaration parent = (FieldDeclaration)parentASTNode;
      parent.getType().accept(this);
      visitListOfModifiers(parent.modifiers());
      if (parent.getJavadoc() != null) {
        parent.getJavadoc().accept(this);
      }
    }
    else if (parentASTNode instanceof VariableDeclarationExpression) {
      VariableDeclarationExpression parent = (VariableDeclarationExpression)parentASTNode;
      parent.getType().accept(this);
      visitListOfModifiers(parent.modifiers());
    }
    else {
      VariableDeclarationStatement parent = (VariableDeclarationStatement)parentASTNode;
      parent.getType().accept(this);
      visitListOfModifiers(parent.modifiers());
    }
    scopeManager.pop();
    return true;
  }
View Full Code Here

        assert rewrite != null;
        assert workingUnit != null;
        assert bug != null;

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        FieldDeclaration field = getFieldDeclaration(type, bug.getPrimaryField());

        Modifier finalModifier = workingUnit.getAST().newModifier(getModifierToAdd());

        ListRewrite modRewrite = rewrite.getListRewrite(field, FieldDeclaration.MODIFIERS2_PROPERTY);
        modRewrite.insertLast(finalModifier, null);
View Full Code Here

                    }
                    return preserveRelativeOrder(bodyDeclaration1,
                            bodyDeclaration2);

                case ASTNode.FIELD_DECLARATION:
                    FieldDeclaration field1 = (FieldDeclaration) bodyDeclaration1;
                    FieldDeclaration field2 = (FieldDeclaration) bodyDeclaration2;

                    String fieldName1 = ((VariableDeclarationFragment) field1
                            .fragments().get(0)).getName().getIdentifier();
                    String fieldName2 = ((VariableDeclarationFragment) field2
                            .fragments().get(0)).getName().getIdentifier();

                    return compareNames(bodyDeclaration1, bodyDeclaration2,
                            fieldName1, fieldName2);
View Full Code Here

        String typeName = getClassName(Checkpoint.class, state, root);
        checkpoint.setType(ast.newSimpleType(createName(ast, typeName)));
        checkpoint.arguments().add(ast.newThisExpression());
        fragment.setInitializer(checkpoint);

        FieldDeclaration checkpointField = ast.newFieldDeclaration(fragment);
        checkpointField.setType(createType(ast, typeName));

        checkpointField.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD));
        checkpointField.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD));

        if (parent != null) {
            addToLists(_nodeSubstitution, parent.getName(), new NodeReplace(
                    checkpointField, null));
View Full Code Here

        ClassInstanceCreation creation = ast.newClassInstanceCreation();
        String typeName = getClassName(CheckpointRecord.class, state, root);
        creation.setType(ast.newSimpleType(createName(ast, typeName)));
        fragment.setInitializer(creation);

        FieldDeclaration record = ast.newFieldDeclaration(fragment);
        record.setType(createType(ast, typeName));
        record.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD));
        record.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD));

        if (parent != null) {
            addToLists(_nodeSubstitution, parent.getName(), new NodeReplace(
                    record, null));
View Full Code Here

        initializer.arguments().add(
                ast.newNumberLiteral(Integer.toString(dimensions)));
        fragment.setInitializer(initializer);

        // The field declaration.
        FieldDeclaration field = ast.newFieldDeclaration(fragment);
        field.setType(createType(ast, typeName));

        // If the field is static, the record field is also static; the record
        // field is also private.
        List modifiers = field.modifiers();
        modifiers
                .add(ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD));
        modifiers
                .add(ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD));
        if (isStatic) {
View Full Code Here

            expressions.add(ast.newSimpleName(recordName));
        }

        fragment.setInitializer(initializer);

        FieldDeclaration array = ast.newFieldDeclaration(fragment);
        array.setType(ast.newArrayType(createType(ast, typeName)));

        array.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD));
        array.modifiers().add(
                ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD));
        return array;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.FieldDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.