當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalVariableNode類代碼示例

本文整理匯總了Java中org.objectweb.asm.tree.LocalVariableNode的典型用法代碼示例。如果您正苦於以下問題:Java LocalVariableNode類的具體用法?Java LocalVariableNode怎麽用?Java LocalVariableNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalVariableNode類屬於org.objectweb.asm.tree包,在下文中一共展示了LocalVariableNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: emitCode

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
/**
 * Creates the new instructions, inlining each instantiation of each
 * subroutine until the code is fully elaborated.
 */
private void emitCode() {
    LinkedList<Instantiation> worklist = new LinkedList<Instantiation>();
    // Create an instantiation of the "root" subroutine, which is just the
    // main routine
    worklist.add(new Instantiation(null, mainSubroutine));

    // Emit instantiations of each subroutine we encounter, including the
    // main subroutine
    InsnList newInstructions = new InsnList();
    List<TryCatchBlockNode> newTryCatchBlocks = new ArrayList<TryCatchBlockNode>();
    List<LocalVariableNode> newLocalVariables = new ArrayList<LocalVariableNode>();
    while (!worklist.isEmpty()) {
        Instantiation inst = worklist.removeFirst();
        emitSubroutine(inst, worklist, newInstructions, newTryCatchBlocks,
                newLocalVariables);
    }
    instructions = newInstructions;
    tryCatchBlocks = newTryCatchBlocks;
    localVariables = newLocalVariables;
}
 
開發者ID:ItzSomebody,項目名稱:DirectLeaks-AntiReleak-Remover,代碼行數:25,代碼來源:JSRInlinerAdapter.java

示例2: analyzeMethod

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@SuppressWarnings(UNCHECKED)
Set<LocalVariableNode> analyzeMethod() {
	// si seulement 1 variable locale ("this") ou si seulement des "variables locales" pour les paramètres et pour "this",
	// alors on passe à la méthode suivante
	if (localVariables.isEmpty()) {
		return Collections.emptySet();
	}
	for (final Iterator<AbstractInsnNode> it = methodNode.instructions.iterator(); it
			.hasNext();) {
		analyzeInstruction(it.next());
		if (localVariables.isEmpty()) {
			// si toutes les variables ont été utilisées, inutile de continuer à lire les instructions
			return Collections.emptySet();
		}
	}
	return localVariables;
}
 
開發者ID:evernat,項目名稱:dead-code-detector,代碼行數:18,代碼來源:LocalVariablesAnalyzer.java

示例3: extractLocalVariables

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@SuppressWarnings(UNCHECKED)
private Set<LocalVariableNode> extractLocalVariables() {
	if ((methodNode.access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC)) != 0) {
		return Collections.emptySet();
	}
	final int oneIfThisExists = (methodNode.access & Opcodes.ACC_STATIC) != 0 ? 0 : 1;
	if (methodNode.localVariables.size() <= oneIfThisExists || methodNode.localVariables
			.size() <= Type.getArgumentTypes(methodNode.desc).length + oneIfThisExists) {
		return Collections.emptySet();
	}
	final Set<LocalVariableNode> variables = new LinkedHashSet<>(methodNode.localVariables);
	// on ignore les variables locales "this" et celles des paramètres
	// (attention les variables ne sont pas forcément dans l'ordre des index, en eclipse 3.1 ou 3.2 ?)
	final int nbParameters = Type.getArgumentTypes(methodNode.desc).length + oneIfThisExists;
	for (final Iterator<LocalVariableNode> it = variables.iterator(); it.hasNext();) {
		final int index = it.next().index;
		if (index < nbParameters) {
			it.remove();
		}
	}
	return variables;
}
 
開發者ID:evernat,項目名稱:dead-code-detector,代碼行數:23,代碼來源:LocalVariablesAnalyzer.java

示例4: filterCatchVariables

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@SuppressWarnings(UNCHECKED)
private void filterCatchVariables() {
	// on supprime les variables des blocs catchs (comme eclipse, etc...),
	// avant de supprimer les doublons car les blocs catchs provoquent parfois des variables de même index
	for (final TryCatchBlockNode tryCatchBlock : (List<TryCatchBlockNode>) methodNode.tryCatchBlocks) {
		// TODO est-ce qu'il y a un meilleur moyen d'identifier la variable de l'exception autrement que par son type ?
		final String type = tryCatchBlock.type;
		// type est null si finally
		if (type != null) {
			for (final Iterator<LocalVariableNode> it = localVariables.iterator(); it
					.hasNext();) {
				final LocalVariableNode localVariable = it.next();
				final Type typeLocalVariable = Type.getType(localVariable.desc);
				if (typeLocalVariable.getSort() == Type.OBJECT
						&& type.equals(typeLocalVariable.getInternalName())) {
					it.remove();
					break;
				}
			}
		}
	}
}
 
開發者ID:evernat,項目名稱:dead-code-detector,代碼行數:23,代碼來源:LocalVariablesAnalyzer.java

示例5: filterDuplicates

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private void filterDuplicates() {
	// et on supprime les doublons,
	// qui arrivent avec le code suivant : final String s; if (b) s = "t"; else s = "f";,
	// Rq: du coup on peut avoir des faux négatifs avec le code suivant, mais tant pis :
	// if (b) { Object o = new Object(); test(o); } else { Object o = new Object(); }
	// (attention les variables ne sont pas forcément dans l'ordre des index, en eclipse 3.1 ou 3.2 ?)
	for (final Iterator<LocalVariableNode> it = localVariables.iterator(); it.hasNext();) {
		final LocalVariableNode localVariable = it.next();
		for (final LocalVariableNode localVariable2 : localVariables) {
			if (localVariable.index == localVariable2.index
					&& !localVariable.equals(localVariable2)) {
				it.remove();
				break;
			}
		}
	}
}
 
開發者ID:evernat,項目名稱:dead-code-detector,代碼行數:18,代碼來源:LocalVariablesAnalyzer.java

示例6: transform

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
	AbstractInsnNode[] match = Iterators.getOnlyElement(matcher.match("BIPUSH ISTORE", m -> {
		IntInsnNode push = (IntInsnNode) m[0];
		if (push.operand != 50) {
			return false;
		}

		VarInsnNode store = (VarInsnNode) m[1];
		LocalVariableNode node = AsmUtils.getLocalVariable(method, store.var, store);
		return node != null && node.name.equals("resource") && node.desc.equals("I");
	}));

	method.instructions.remove(match[0]);
	method.instructions.remove(match[1]);
}
 
開發者ID:jonathanedgecombe,項目名稱:anvil,代碼行數:17,代碼來源:VeinCapTransformer.java

示例7: getLocal

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private Local getLocal(int idx) {
	if (idx >= maxLocals)
		throw new IllegalArgumentException("Invalid local index: " + idx);
	Integer i = idx;
	Local l = locals.get(i);
	if (l == null) {
		String name;
		if (localVars != null) {
			name = null;
			for (LocalVariableNode lvn : localVars) {
				if (lvn.index == idx) {
					name = lvn.name;
					break;
				}
			}
			/* normally for try-catch blocks */
			if (name == null)
				name = "l" + idx;
		} else {
			name = "l" + idx;
		}
		l = Jimple.v().newLocal(name, UnknownType.v());
		locals.put(i, l);
	}
	return l;
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:27,代碼來源:AsmMethodSource.java

示例8: run

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@Override
public void run() {
	if (mn.localVariables == null)
		return;
	for(int i = 0; i < mn.localVariables.size(); i++) {
		LocalVariableNode lvn = (LocalVariableNode) mn.localVariables.get(i);

		mn.localVariables.set (
			i,
			new LocalVariableNode (
				Main.getInstance().nameGen.get(i),
				lvn.desc,
				null,
				lvn.start,
				lvn.end,
				i
			)
		);
		hm.put(lvn.desc, Boolean.TRUE);
	}
}
 
開發者ID:MoofMonkey,項目名稱:NeonObf,代碼行數:22,代碼來源:LocalVariableNameObfuscator.java

示例9: getNamesByAsm

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private List<String> getNamesByAsm( Method method, ClassNode classNode ) {

        List<String> names      = new ArrayList<>();
        MethodNode   methodNode = getMethodNode( method, classNode );

        if( methodNode == null ) {
            return getNamesByReflection( method );
        }

        for( LocalVariableNode variableNode : (List<LocalVariableNode>) methodNode.localVariables ) {
            // if methodNode is not static, first local variable always be "this".
            if( "this".equals(variableNode.name) ) continue;
            names.add( variableNode.name );
        }

        return names;

    }
 
開發者ID:NyBatis,項目名稱:NyBatisCore,代碼行數:19,代碼來源:ParameterNameReader.java

示例10: getLocalVariableNode

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private LocalVariableNode getLocalVariableNode(int varIdx, AbstractInsnNode insnNode, MethodNode methodNode) {
	int instrIdx = getInstructionIndex(insnNode);
	List<?> localVariables = methodNode.localVariables;
	for (int idx = 0; idx < localVariables.size(); idx++) {
		LocalVariableNode localVariableNode = (LocalVariableNode) localVariables.get(idx);
		if (localVariableNode.index == varIdx) {
			int scopeEndInstrIdx = getInstructionIndex(localVariableNode.end);
			if (scopeEndInstrIdx >= instrIdx) {
				// still valid for current line
				return localVariableNode;
			}
		}
	}
	throw new RuntimeException("Variable with index " + varIdx + " and end >= " + currentLine
			+ " not found for method " + fullyQualifiedTargetClass + "#" + methodNode.name + "!");
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:17,代碼來源:TestRuntimeValuesDeterminer.java

示例11: localVarValue

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private InsnList localVarValue(AbstractInsnNode insnNode, int opositeOpcode, String param) {
	int varIdx = -1;
	if (insnNode instanceof VarInsnNode) {
		varIdx = ((VarInsnNode) insnNode).var;
	} else if (insnNode instanceof IincInsnNode) {
		varIdx = ((IincInsnNode) insnNode).var;
	} else {
		throw new RuntimeException("Not implemented for type " + insnNode.getClass());
	}
	InsnList instrumentation = new InsnList();
	MethodNode methodNode = (MethodNode) mv;
	if (methodNode.localVariables.size() <= varIdx) {
		throw new RuntimeException("varInsnNode is pointing outside of local variables!");
	}
	LocalVariableNode localVariableNode = getLocalVariableNode(varIdx, insnNode, methodNode);
	instrumentation.add(new VarInsnNode(opositeOpcode, varIdx));
	instrumentation.add(new LdcInsnNode(localVariableNode.name));
	instrumentation.add(new LdcInsnNode(currentLine));
	instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
			"org/evosuite/junit/TestRuntimeValuesDeterminer", "localVarValueChanged", "(" + param
					+ "Ljava/lang/String;I)V"));
	logger.debug("Adding localVarValueChanged for var {} in line {}.", localVariableNode.name, currentLine);
	return instrumentation;
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:25,代碼來源:TestRuntimeValuesDeterminer.java

示例12: getNextIndex

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
/**
 * <p>getNextIndex</p>
 *
 * @param mn a {@link org.objectweb.asm.tree.MethodNode} object.
 * @return a int.
 */
@SuppressWarnings("rawtypes")
public static int getNextIndex(MethodNode mn) {
	Iterator it = mn.localVariables.iterator();
	int max = 0;
	int next = 0;
	while (it.hasNext()) {
		LocalVariableNode var = (LocalVariableNode) it.next();
		int index = var.index;
		if (index >= max) {
			max = index;
			next = max + Type.getType(var.desc).getSize();
		}
	}
	if (next == 0)
		next = getNextIndexFromLoad(mn);
	return next;
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:24,代碼來源:ReplaceArithmeticOperator.java

示例13: getLocal

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private LocalVariableNode getLocal(MethodNode mn, AbstractInsnNode node, int index)
        throws VariableNotFoundException {
	int currentId = mn.instructions.indexOf(node);
	for (Object v : mn.localVariables) {
		LocalVariableNode localVar = (LocalVariableNode) v;
		int startId = mn.instructions.indexOf(localVar.start);
		int endId = mn.instructions.indexOf(localVar.end);
		logger.info("Checking " + localVar.index + " in scope " + startId + " - "
		        + endId);
		if (currentId >= startId && currentId <= endId && localVar.index == index)
			return localVar;
	}

	throw new VariableNotFoundException("Could not find local variable " + index
	        + " at position " + currentId + ", have variables: "
	        + mn.localVariables.size());
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:18,代碼來源:ReplaceVariable.java

示例14: guessName

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
private String guessName(final MethodNode method, final SwitchEntry se, final int local)
{
    if (se != null)
    {
        for (LocalVariableNode node : method.localVariables)
        {
            if (node.index == local
                    && method.instructions.indexOf(node.start) <= se.index
                    && method.instructions.indexOf(node.end) >= se.index)
            {
                return node.name;
            }
        }
    }
    return "_local$" + local;
}
 
開發者ID:electronicarts,項目名稱:ea-async,代碼行數:17,代碼來源:Transformer.java

示例15: mustFindLocalVariableNodeForInstruction

import org.objectweb.asm.tree.LocalVariableNode; //導入依賴的package包/類
@Test
public void mustFindLocalVariableNodeForInstruction() {
    MethodNode methodNode = findMethodsWithName(classNode.methods, "localVariablesTest").get(0);
    List<AbstractInsnNode> insns = findInvocationsOf(methodNode.instructions,
            MethodUtils.getAccessibleMethod(PrintStream.class, "println", String.class));
    
    AbstractInsnNode insnNode = insns.get(0);
    
    LocalVariableNode lvn0 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 0);
    LocalVariableNode lvn1 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 1);
    LocalVariableNode lvn2 = findLocalVariableNodeForInstruction(methodNode.localVariables, methodNode.instructions, insnNode, 2);
    
    assertEquals(lvn0.name, "this");
    assertEquals(lvn1.name, "val1");
    assertEquals(lvn2.name, "val2");
}
 
開發者ID:offbynull,項目名稱:coroutines,代碼行數:17,代碼來源:SearchUtilsTest.java


注:本文中的org.objectweb.asm.tree.LocalVariableNode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。