public final AstNodeCollection<VariableInitializer> getVariables() { return getChildrenByRole(Roles.VARIABLE); }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof FieldDeclaration) { final FieldDeclaration otherDeclaration = (FieldDeclaration) other; return !otherDeclaration.isNull() && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getReturnType().matches(otherDeclaration.getReturnType(), match); } return false; } }
@Override public Set<Object> visitFieldDeclaration(final FieldDeclaration node, final String name) { if (_mode == NameResolveMode.EXPRESSION) { if (StringUtilities.equals(node.getName(), name)) { final FieldDefinition f = node.getUserData(Keys.FIELD_DEFINITION); if (f != null && (!_isStaticContext || f.isStatic())) { return Collections.<Object>singleton(f); } } } return Collections.emptySet(); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && AstBuilder.isMemberHidden(field, context)) { node.remove(); return null; } return super.visitFieldDeclaration(node, data); }
private FieldDeclaration createField(final FieldDefinition field) { final FieldDeclaration astField = new FieldDeclaration(); final VariableInitializer initializer = new VariableInitializer(field.getName()); astField.setName(field.getName()); astField.addChild(initializer, Roles.VARIABLE); astField.setReturnType(convertType(field.getFieldType())); astField.putUserData(Keys.FIELD_DEFINITION, field); astField.putUserData(Keys.MEMBER_REFERENCE, field); EntityDeclaration.setModifiers( astField, Flags.asModifierSet(scrubAccessModifiers(field.getFlags() & Flags.VarFlags)) ); if (field.hasConstantValue()) { initializer.setInitializer(new PrimitiveExpression(Expression.MYSTERY_OFFSET, field.getConstantValue())); initializer.putUserData(Keys.FIELD_DEFINITION, field); initializer.putUserData(Keys.MEMBER_REFERENCE, field); } for (final CustomAnnotation annotation : field.getAnnotations()) { astField.getAnnotations().add(createAnnotation(annotation)); } return astField; }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void ignored) { startNode(node); writeAnnotations(node.getAnnotations(), true); writeModifiers(node.getModifiers()); final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && field.isSynthetic()) { space(lastWritten != LastWritten.Whitespace); formatter.writeComment(CommentType.MultiLine, " synthetic "); space(); } node.getReturnType().acceptVisitor(this, ignored); space(); writeCommaSeparatedList(node.getVariables()); semicolon(); endNode(node); return null; }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof FieldDeclaration) { final FieldDeclaration otherDeclaration = (FieldDeclaration) other; return !otherDeclaration.isNull() && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getReturnType().matches(otherDeclaration.getReturnType(), match) && getMembers().matches(getMembers(), match); } return false; } }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { super.visitFieldDeclaration(node, data); final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && !_initializers.isEmpty() && node.getVariables().size() == 1 && node.getVariables().firstOrNullObject().getInitializer().isNull()) { final Expression initializer = _initializers.get(field.getFullName()); if (initializer != null) { node.getVariables().firstOrNullObject().setInitializer(initializer.clone()); } } return null; }
enumDeclaration.putUserData(Keys.FIELD_DEFINITION, field.getUserData(Keys.FIELD_DEFINITION)); enumDeclaration.putUserData(Keys.MEMBER_REFERENCE, field.getUserData(Keys.MEMBER_REFERENCE)); for (final Annotation annotation : field.getAnnotations()) { annotation.remove(); enumDeclaration.getAnnotations().add(annotation); field.replaceWith(enumDeclaration);
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final TypeReference leftType = getType(node.getReturnType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitFieldDeclaration(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void p) { final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null) { _fieldDeclarations.put(field.getFullName(), node); } return super.visitFieldDeclaration(node, p); } }
enumDeclaration.putUserData(Keys.FIELD_DEFINITION, field.getUserData(Keys.FIELD_DEFINITION)); enumDeclaration.putUserData(Keys.MEMBER_REFERENCE, field.getUserData(Keys.MEMBER_REFERENCE)); field.replaceWith(enumDeclaration);
private void inlineInitializers() { for (final String fieldName : _initializers.keySet()) { final FieldDeclaration declaration = _fieldDeclarations.get(fieldName); if (declaration != null && declaration.getVariables().firstOrNullObject().getInitializer().isNull()) { final AssignmentExpression assignment = _initializers.get(fieldName); final Expression value = assignment.getRight(); value.remove(); declaration.getVariables().firstOrNullObject().setInitializer(value); final AstNode parent = assignment.getParent(); if (parent instanceof ExpressionStatement) { parent.remove(); } else if (parent.getRole() == Roles.VARIABLE) { final Expression left = assignment.getLeft(); left.remove(); assignment.replaceWith(left); } else { final Expression left = assignment.getLeft(); left.remove(); parent.replaceWith(left); } } } }
private FieldDeclaration createField(final FieldDefinition field) { final FieldDeclaration astField = new FieldDeclaration(); final VariableInitializer initializer = new VariableInitializer(field.getName()); astField.setName(field.getName()); astField.addChild(initializer, Roles.VARIABLE); astField.setReturnType(convertType(field.getFieldType())); astField.putUserData(Keys.FIELD_DEFINITION, field); astField.putUserData(Keys.MEMBER_REFERENCE, field); EntityDeclaration.setModifiers( astField, Flags.asModifierSet(scrubAccessModifiers(field.getFlags() & Flags.VarFlags)) ); if (field.hasConstantValue()) { initializer.setInitializer(new PrimitiveExpression(Expression.MYSTERY_OFFSET, field.getConstantValue())); initializer.putUserData(Keys.FIELD_DEFINITION, field); initializer.putUserData(Keys.MEMBER_REFERENCE, field); } for (final CustomAnnotation annotation : field.getAnnotations()) { astField.getAnnotations().add(createAnnotation(annotation)); } return astField; }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void ignored) { startNode(node); writeAnnotations(node.getAnnotations(), true); writeModifiers(node.getModifiers()); final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && field.isSynthetic()) { space(lastWritten != LastWritten.Whitespace); formatter.writeComment(CommentType.MultiLine, " synthetic "); space(); } node.getReturnType().acceptVisitor(this, ignored); space(); writeCommaSeparatedList(node.getVariables()); semicolon(); endNode(node); return null; }
@Override public boolean matches(final INode other, final Match match) { if (other instanceof FieldDeclaration) { final FieldDeclaration otherDeclaration = (FieldDeclaration) other; return !otherDeclaration.isNull() && matchString(getName(), otherDeclaration.getName()) && matchAnnotationsAndModifiers(otherDeclaration, match) && getReturnType().matches(otherDeclaration.getReturnType(), match) && getMembers().matches(getMembers(), match); } return false; } }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { super.visitFieldDeclaration(node, data); final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && !_initializers.isEmpty() && node.getVariables().size() == 1 && node.getVariables().firstOrNullObject().getInitializer().isNull()) { final Expression initializer = _initializers.get(field.getFullName()); if (initializer != null) { node.getVariables().firstOrNullObject().setInitializer(initializer.clone()); } } return null; }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final TypeReference leftType = getType(node.getReturnType()); if (leftType != null) { for (final VariableInitializer initializer : node.getVariables()) { processPossibleTypeCast(initializer.getInitializer(), leftType); } } return super.visitFieldDeclaration(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void data) { final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null && AstBuilder.isMemberHidden(field, context)) { node.remove(); return null; } return super.visitFieldDeclaration(node, data); }
@Override public Void visitFieldDeclaration(final FieldDeclaration node, final Void _) { final FieldDefinition field = node.getUserData(Keys.FIELD_DEFINITION); if (field != null) { _fieldDeclarations.put(field.getFullName(), node); } return super.visitFieldDeclaration(node, _); } }.run(compilationUnit);