Example usage for org.eclipse.jdt.internal.compiler.env ISourceField getTypeName

List of usage examples for org.eclipse.jdt.internal.compiler.env ISourceField getTypeName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.env ISourceField getTypeName.

Prototype

char[] getTypeName();

Source Link

Document

Answer the type name of the field.

Usage

From source file:org.limy.eclipse.code.accessor.AccessorCreater.java

License:Open Source License

/**
 * getter?\bh`?iJavadoc?j???B//  w  w w . j  a  va  2s  .com
 * @param field tB?[hIuWFNg
 * @param fieldComment tB?[hR?g
 * @param fieldAnnotation tB?[hAme?[Vqg
 * @param flagName ANZXq
 * @param method ?\bhIuWFNg
 * @return getter?\bh`
 * @throws JavaModelException
 */
public static String createGetterContents(IField field, String fieldComment, String fieldAnnotation,
        String flagName, IMethod method) throws JavaModelException {

    // tB?[h?
    ISourceField elementInfo = (ISourceField) ((JavaElement) field).getElementInfo();
    // tB?[h^
    String typeName = new String(elementInfo.getTypeName());
    // tB?[h
    String fieldName = field.getElementName();
    String getFieldName = GetterSetterUtil.getGetterName(field, null);

    String tmpFieldComment = fieldComment;
    if (fieldComment == null || fieldComment.length() == 0) {
        tmpFieldComment = fieldName;
    }

    StringBuilder buff = new StringBuilder(256);
    appendJavadocGetter(buff, tmpFieldComment);

    if (method != null && method.exists()) {
        appendMethodSourceAlready(method, buff, flagName);
    } else {
        if (fieldAnnotation != null && fieldAnnotation.length() > 0) {
            buff.append(INDENT_STR).append(fieldAnnotation).append(NL);
        }
        buff.append(INDENT_STR).append(flagName).append(" ").append(typeName);
        buff.append(' ').append(getFieldName).append("() {").append(NL);
        buff.append("        return ").append(fieldName).append(';').append(NL);
        buff.append(INDENT_STR).append(RIGHT_BRACKET).append(NL).append(NL);
    }
    return buff.toString();
}

From source file:org.limy.eclipse.code.accessor.AccessorCreater.java

License:Open Source License

/**
 * setter?\bh`?iJavadoc?j???B//from  ww w .  ja  v  a2s  .co  m
 * @param field tB?[hIuWFNg
 * @param fieldComment tB?[hR?g
 * @param flagName ANZXq
 * @param method ?\bhIuWFNg
 * @return setter?\bh`
 * @throws JavaModelException
 */
public static String createSetterContents(IField field, String fieldComment, String flagName, IMethod method)
        throws JavaModelException {

    ISourceField elementInfo = (ISourceField) ((JavaElement) field).getElementInfo(); // tB?[h?
    String typeName = new String(elementInfo.getTypeName()); // tB?[h^
    String fieldName = field.getElementName(); // tB?[h
    String myFieldName = fieldName;
    if (myFieldName.charAt(0) == '_') {
        myFieldName = myFieldName.substring(1);
    }
    if (method != null) {
        // ?\bhR?g???A?\bh?gp
        myFieldName = method.getParameterNames()[0];
    }

    String setFieldName = GetterSetterUtil.getSetterName(field, null);

    String tmpFieldComment = fieldComment;
    if (fieldComment == null || fieldComment.length() == 0) {
        tmpFieldComment = myFieldName;
    }

    StringBuilder buff = new StringBuilder(256);
    appendJavadocSetter(buff, tmpFieldComment, myFieldName);

    if (method != null && method.exists()) {
        appendMethodSourceAlready(method, buff, flagName);
    } else {
        buff.append(INDENT_STR).append(flagName).append(" void ");
        buff.append(setFieldName).append('(').append(typeName).append(' ');
        buff.append(myFieldName).append(") {").append(NL);
        buff.append("        this.").append(fieldName).append(" = ");
        buff.append(myFieldName).append(';').append(NL);
        buff.append(INDENT_STR).append(RIGHT_BRACKET).append(NL).append(NL);
    }

    return buff.toString();
}