All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reextractor.util.AttributeUtils Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package org.reextractor.util;

import org.eclipse.jdt.core.dom.*;
import org.remapper.dto.DeclarationNodeTree;
import org.remapper.dto.EntityType;

public class AttributeUtils {

    public static String attribute2QualifiedString(DeclarationNodeTree attribute) {
        StringBuilder sb = new StringBuilder();
        if (attribute.getType() == EntityType.FIELD) {
            FieldDeclaration fieldDeclaration = (FieldDeclaration) attribute.getDeclaration();
            VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
            sb.append(fragment.getName().getIdentifier());
            sb.append(" : ");
            sb.append(fieldDeclaration.getType().toString());
        } else if (attribute.getType() == EntityType.ENUM_CONSTANT) {
            EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) attribute.getDeclaration();
            sb.append(enumConstantDeclaration.getName().getIdentifier());
            sb.append(" : ");
            sb.append(attribute.getParent().getName());
        }
        return sb.toString();
    }

    public static String attribute2String(DeclarationNodeTree attribute) {
        StringBuilder sb = new StringBuilder();
        if (attribute.getType() == EntityType.FIELD) {
            FieldDeclaration fieldDeclaration = (FieldDeclaration) attribute.getDeclaration();
            VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
            boolean isInterfaceMethod = false;
            if (fieldDeclaration.getParent() instanceof TypeDeclaration) {
                TypeDeclaration parent = (TypeDeclaration) fieldDeclaration.getParent();
                isInterfaceMethod = parent.isInterface();
            }
            int attributeModifiers = fieldDeclaration.getModifiers();
            if ((attributeModifiers & Modifier.PUBLIC) != 0)
                sb.append("public").append(" ");
            else if ((attributeModifiers & Modifier.PROTECTED) != 0)
                sb.append("protected").append(" ");
            else if ((attributeModifiers & Modifier.PRIVATE) != 0)
                sb.append("private").append(" ");
            else if (isInterfaceMethod)
                sb.append("public").append(" ");
            else
                sb.append("package").append(" ");
            if ((attributeModifiers & Modifier.ABSTRACT) != 0)
                sb.append("abstract").append(" ");
            sb.append(fragment.getName().getIdentifier());
            sb.append(" : ");
            sb.append(fieldDeclaration.getType().toString());
        } else if (attribute.getType() == EntityType.ENUM_CONSTANT) {
            EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) attribute.getDeclaration();
            sb.append(enumConstantDeclaration.getName().getIdentifier());
            sb.append(" : ");
            sb.append(attribute.getParent().getName());
        }
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy