当前位置: 首页>>代码示例>>Java>>正文


Java LocalVariable.getName方法代码示例

本文整理汇总了Java中org.apache.bcel.classfile.LocalVariable.getName方法的典型用法代码示例。如果您正苦于以下问题:Java LocalVariable.getName方法的具体用法?Java LocalVariable.getName怎么用?Java LocalVariable.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bcel.classfile.LocalVariable的用法示例。


在下文中一共展示了LocalVariable.getName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getParamName

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
static String getParamName(Method m, int paramNr) {
LocalVariable[] lt = getLocalTable(m).getLocalVariableTable();

int minPos = Integer.MAX_VALUE;
String res = null;

for (int i = 0; i < lt.length; i++) {
    LocalVariable l = lt[i];
    if (l.getIndex() == paramNr) {
	int startPos = l.getStartPC();

	if (startPos < minPos) {
	    minPos = startPos;
	    res = l.getName();
	}
    }
}

if (res != null) {
    return res;
}

System.err.println("getParamName: could not find name of param "
	+ paramNr);
System.exit(1);

return null;
   }
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:29,代码来源:MethodTable.java

示例2: getLocalVariableAnnotation

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, int local, int position1, int position2) {

        LocalVariableTable localVariableTable = method.getLocalVariableTable();
        String localName = "?";
        if (localVariableTable != null) {
            LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1);
            if (lv1 == null) {
                lv1 = localVariableTable.getLocalVariable(local, position2);
                position1 = position2;
            }
            if (lv1 != null)
                localName = lv1.getName();
            else
                for (LocalVariable lv : localVariableTable.getLocalVariableTable()) {
                    if (lv.getIndex() == local) {
                        if (!localName.equals("?") && !localName.equals(lv.getName())) {
                            // not a single consistent name
                            localName = "?";
                            break;
                        }
                        localName = lv.getName();
                    }
                }
        }
        LineNumberTable lineNumbers = method.getLineNumberTable();
        if (lineNumbers == null)
            return new LocalVariableAnnotation(localName, local, position1);
        int line = lineNumbers.getSourceLine(position1);
        return new LocalVariableAnnotation(localName, local, position1, line);
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:31,代码来源:LocalVariableAnnotation.java

示例3: checkLocalVariableName

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
/**
 * Get the name of given local variable (if possible) and store it in the
 * HeuristicPropertySet.
 * 
 * @param lvt
 *            the LocalVariableTable
 * @param local
 *            index of the local
 * @param pc
 *            program counter value of the instruction
 */
private void checkLocalVariableName(LocalVariableTable lvt, int local, int pc,
        WarningPropertySet<DeadLocalStoreProperty> propertySet) {
    if (lvt != null) {
        LocalVariable lv = lvt.getLocalVariable(local, pc);
        if (lv != null) {
            String localName = lv.getName();
            propertySet.setProperty(DeadLocalStoreProperty.LOCAL_NAME, localName);
        }
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:23,代码来源:FindDeadLocalStores.java

示例4: visit

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
@Override
public void visit(Code obj) {

    if (!getMethod().isPublic() && !getMethod().isProtected())
        return;
    SignatureParser p = new SignatureParser(getMethodSig());
    LocalVariableTable t = obj.getLocalVariableTable();

    if (t == null)
        return;
    ParameterProperty property = new ParameterProperty();

    int index = getMethod().isStatic() ? 0 : 1;
    int parameterNumber = 0;
    for (Iterator<String> i = p.parameterSignatureIterator(); i.hasNext();) {
        String s = i.next();
        LocalVariable localVariable = t.getLocalVariable(index, 0);
        if (localVariable != null) {
            String name = localVariable.getName();
            if (s.equals("J") && (name.toLowerCase().indexOf("instant") >= 0 || name.startsWith("date"))) {

                // System.out.println(getFullyQualifiedMethodName() + " " + s + " " + index + " " + name);
                property.setParamWithProperty(parameterNumber, true);
            }
        }
        if (s.equals("J") || s.equals("D"))
            index += 2;
        else
            index += 1;
        parameterNumber++;
    }
    if (!property.isEmpty()) {
        // System.out.println(getFullyQualifiedMethodName() + " " + property);
        database.setProperty(getMethodDescriptor(), property);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:37,代码来源:TrainLongInstantfParams.java

示例5: visit

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
@Override
public void visit(LocalVariableTable obj) {
    if (ENABLE_LOCALS) {
        if (staticMethod)
            return;

        LocalVariable[] vars = obj.getLocalVariableTable();
        // System.out.println("Num params = " + numParms);
        for (LocalVariable var : vars) {
            if (var.getIndex() < numParms)
                continue;
            String varName = var.getName();
            if (varName.equals("serialVersionUID"))
                continue;
            Field f = classFields.get(varName);
            // System.out.println("Checking " + varName);
            // System.out.println(" got " + f);
            // TODO: we could distinguish between obscuring a field in the
            // same class
            // vs. obscuring a field in a superclass. Not sure how important
            // that is.
            if (f != null) {
                FieldAnnotation fa = FieldAnnotation.fromBCELField(getDottedClassName(), f);
                if (true || var.getStartPC() > 0)
                    bugReporter.reportBug(new BugInstance(this, "MF_METHOD_MASKS_FIELD", LOW_PRIORITY)
                            .addClassAndMethod(this).addField(fa).addSourceLine(this, var.getStartPC() - 1));
            }
        }
    }
    super.visit(obj);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:32,代码来源:FindMaskedFields.java

示例6: visit

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
@Override
public void visit(LocalVariable obj) {
    if (isReservedName(obj.getName())) {
        LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC());
        SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC());
        BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY)
                .addClassAndMethod(this).add(var).add(source);
        bugReporter.reportBug(bug);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:11,代码来源:DontUseEnum.java

示例7: checkLocalVariableName

import org.apache.bcel.classfile.LocalVariable; //导入方法依赖的package包/类
/**
 * Get the name of given local variable (if possible) and store it in the
 * HeuristicPropertySet.
 *
 * @param lvt
 *            the LocalVariableTable
 * @param local
 *            index of the local
 * @param pc
 *            program counter value of the instruction
 */
private void checkLocalVariableName(LocalVariableTable lvt, int local, int pc,
        WarningPropertySet<DeadLocalStoreProperty> propertySet) {
    if (lvt != null) {
        LocalVariable lv = lvt.getLocalVariable(local, pc);
        if (lv != null) {
            String localName = lv.getName();
            propertySet.setProperty(DeadLocalStoreProperty.LOCAL_NAME, localName);
        }
    }

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:23,代码来源:FindDeadLocalStores.java


注:本文中的org.apache.bcel.classfile.LocalVariable.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。