Java Aspectj Usage getFieldName(JoinPoint jp)

Here you can find the source of getFieldName(JoinPoint jp)

Description

get Field Name

License

Open Source License

Declaration

public static String getFieldName(JoinPoint jp) 

Method Source Code

//package com.java2s;
/*//from   ww w .jav  a2 s  . co  m
 *  Copyright (c) Ludger Solbach. All rights reserved.
 *  The use and distribution terms for this software are covered by the
 *  Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *  which can be found in the file license.txt at the root of this distribution.
 *  By using this software in any fashion, you are agreeing to be bound by
 *  the terms of this license.
 *  You must not remove this notice, or any other, from this software.
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.FieldSignature;
import org.aspectj.lang.reflect.MethodSignature;

public class Main {
    public static String getFieldName(JoinPoint jp) {
        Signature sig = jp.getSignature();
        if (sig instanceof MethodSignature) {
            MethodSignature mSig = (MethodSignature) sig;
            return getFieldNameFromMethodName(mSig.getName());
        } else if (sig instanceof FieldSignature) {
            FieldSignature fSig = (FieldSignature) sig;
            return fSig.getField().getName();
        }
        return "";
    }

    public static String getFieldNameFromMethodName(String methodName) {
        String name = "";
        if (methodName.startsWith("get") || methodName.startsWith("set")) {
            name = firstLower(methodName.substring(3));
        } else if (methodName.startsWith("is")) {
            name = firstLower(methodName.substring(2));
        }
        return name;
    }

    public static String firstLower(String name) {
        return name.substring(0, 1).toLowerCase() + name.substring(1);
    }
}

Related

  1. createConstant(InstructionFactory fact, int value)
  2. createInstanceof(InstructionFactory fact, ReferenceType t)
  3. genPointcutDetails(Pointcut pcd)
  4. genSignature(IProgramElement node)
  5. getArgsMap(JoinPoint pjp)
  6. getFilesInPackage(IProgramElement packageNode)
  7. getMethodArgByIndex(final JoinPoint joinPoint, final int index)
  8. getMethodName(ProceedingJoinPoint pjp)
  9. getPackagesHelper(IProgramElement node, IProgramElement.Kind kind, String prename, List matches)