Search in sources :

Example 1 with LineNumberGen

use of org.apache.bcel.generic.LineNumberGen in project jop by jop-devel.

the class MethodCode method copyLineNumbers.

private void copyLineNumbers(MethodInfo sourceInfo, InstructionHandle to, InstructionHandle from) {
    // TODO should we make this public?
    MethodCode srcCode = sourceInfo != null ? sourceInfo.getCode() : this;
    if (srcCode == null) {
        throw new AppInfoError("Invalid operation: cannot copy line numbers from method without code");
    }
    String source = (String) from.getAttribute(KEY_SOURCECLASS);
    if (source != null) {
        int line = (Integer) from.getAttribute(KEY_LINENUMBER);
        if (source.equals(getClassInfo().getClassName())) {
            setLineNumber(to, line);
        } else {
            to.addAttribute(KEY_SOURCECLASS, source);
            to.addAttribute(KEY_LINENUMBER, line);
        }
        return;
    }
    LineNumberGen entry = srcCode.getLineNumberEntry(from, false);
    if (entry != null) {
        int line = entry.getSourceLine();
        source = srcCode.getClassInfo().getClassName();
        if (source.equals(getClassInfo().getClassName())) {
            setLineNumber(to, line);
        } else {
            to.addAttribute(KEY_SOURCECLASS, source);
            to.addAttribute(KEY_LINENUMBER, line);
        }
    }
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen) HashedString(com.jopdesign.common.misc.HashedString) CallString(com.jopdesign.common.code.CallString) AppInfoError(com.jopdesign.common.misc.AppInfoError)

Example 2 with LineNumberGen

use of org.apache.bcel.generic.LineNumberGen in project jop by jop-devel.

the class MethodCode method clearLineNumber.

/**
     * Removes all line number entries from this instruction. This has the effect that the instruction
     * gets the same line number as the previous instruction.
     *
     * @param ih the instruction to clear.
     */
public void clearLineNumber(InstructionHandle ih) {
    ih.removeAttribute(KEY_SOURCECLASS);
    ih.removeAttribute(KEY_LINENUMBER);
    LineNumberGen entry = getLineNumberEntry(ih, false);
    if (entry != null) {
        removeLineNumber(entry);
    }
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen)

Example 3 with LineNumberGen

use of org.apache.bcel.generic.LineNumberGen in project jop by jop-devel.

the class MethodCode method getLineNumber.

/**
     * Get the line number of the instruction. This may refer to a line number in another file.
     * To get the correct source file for this instruction, use {@link #getSourceFileName(InstructionHandle)}.
     *
     * @see #getSourceFileName(InstructionHandle)
     * @param ih the instruction to check.
     * @return the line number of the instruction, or -1 if unknown.
     */
public int getLineNumber(InstructionHandle ih) {
    InstructionHandle handle = findLineNumberHandle(ih);
    if (handle == null)
        return -1;
    Integer line = (Integer) handle.getAttribute(KEY_LINENUMBER);
    if (line != null) {
        return line;
    }
    LineNumberGen entry = getLineNumberEntry(handle, false);
    return entry != null ? entry.getSourceLine() : -1;
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 4 with LineNumberGen

use of org.apache.bcel.generic.LineNumberGen in project jop by jop-devel.

the class MethodCode method setLineNumber.

/**
     * @param ih the *first* instruction which should be assigned to this source line.
     *        Use {@link #clearLineNumber(InstructionHandle)} for all following instructions which have the same line.
     * @param classInfo the classinfo containing the original source code, or null to use the class of this method
     * @param line the line number to set
     */
public void setLineNumber(InstructionHandle ih, ClassInfo classInfo, int line) {
    LineNumberGen lg = getLineNumberEntry(ih, false);
    if (classInfo == null || classInfo.equals(methodInfo.getClassInfo())) {
        ih.removeAttribute(KEY_SOURCECLASS);
        ih.removeAttribute(KEY_LINENUMBER);
        if (lg != null) {
            lg.setSourceLine(line);
        } else {
            methodGen.addLineNumber(ih, line);
        }
    } else {
        // or should we attach the ClassInfo directly?
        ih.addAttribute(KEY_SOURCECLASS, classInfo.getClassName());
        ih.addAttribute(KEY_LINENUMBER, line);
        if (lg != null) {
            removeLineNumber(lg);
        }
    }
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen)

Example 5 with LineNumberGen

use of org.apache.bcel.generic.LineNumberGen in project jop by jop-devel.

the class MethodCode method getLineString.

public String getLineString(InstructionHandle ih) {
    InstructionHandle handle = findLineNumberHandle(ih);
    if (handle == null) {
        return "<none>";
    }
    String className = getSourceClassAttribute(handle);
    if (className != null) {
        return className + ":" + getLineNumber(handle);
    }
    LineNumberGen lg = getLineNumberEntry(handle, false);
    return String.valueOf(lg.getSourceLine());
}
Also used : LineNumberGen(org.apache.bcel.generic.LineNumberGen) HashedString(com.jopdesign.common.misc.HashedString) CallString(com.jopdesign.common.code.CallString) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

LineNumberGen (org.apache.bcel.generic.LineNumberGen)6 CallString (com.jopdesign.common.code.CallString)2 HashedString (com.jopdesign.common.misc.HashedString)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 MethodCode (com.jopdesign.common.MethodCode)1 AppInfoError (com.jopdesign.common.misc.AppInfoError)1 CodeExceptionGen (org.apache.bcel.generic.CodeExceptionGen)1 LocalVariableGen (org.apache.bcel.generic.LocalVariableGen)1