org.apache.bcel.generic.Type Java Examples
The following examples show how to use
org.apache.bcel.generic.Type.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pass3aVerifier.java From commons-bcel with Apache License 2.0 | 6 votes |
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitNEW(final NEW o) { indexValid(o, o.getIndex()); final Constant c = constantPoolGen.getConstant(o.getIndex()); if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } else{ final ConstantUtf8 cutf8 = (ConstantUtf8) (constantPoolGen.getConstant( ((ConstantClass) c).getNameIndex() )); final Type t = Type.getType("L"+cutf8.getBytes()+";"); if (t instanceof ArrayType) { constraintViolated(o, "NEW must not be used to create an array."); } } }
Example #2
Source File: JavaBuilder.java From luaj with MIT License | 6 votes |
private String createLuaStringField(LuaString value) { String name = PREFIX_CONSTANT+constants.size(); FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, TYPE_LUAVALUE, name, cp); cg.addField(fg.getField()); LuaString ls = value.checkstring(); if ( ls.isValidUtf8() ) { init.append(new PUSH(cp, value.tojstring())); init.append(factory.createInvoke(STR_LUASTRING, "valueOf", TYPE_LUASTRING, ARG_TYPES_STRING, Constants.INVOKESTATIC)); } else { char[] c = new char[ls.m_length]; for ( int j=0; j<ls.m_length; j++ ) c[j] = (char) (0xff & (int) (ls.m_bytes[ls.m_offset+j])); init.append(new PUSH(cp, new String(c))); init.append(factory.createInvoke(STR_STRING, "toCharArray", TYPE_CHARARRAY, Type.NO_ARGS, Constants.INVOKEVIRTUAL)); init.append(factory.createInvoke(STR_LUASTRING, "valueOf", TYPE_LUASTRING, ARG_TYPES_CHARARRAY, Constants.INVOKESTATIC)); } init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE)); return name; }
Example #3
Source File: GraphicalVerifier.java From commons-bcel with Apache License 2.0 | 6 votes |
/** Constructor. */ public GraphicalVerifier() { final VerifierAppFrame frame = new VerifierAppFrame(); //Frames �berpr�fen, die voreingestellte Gr��e haben //Frames packen, die nutzbare bevorzugte Gr��eninformationen enthalten, z.B. aus ihrem Layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Das Fenster zentrieren final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); frame.getClassNamesJList().setModel(new VerifierFactoryListModel()); VerifierFactory.getVerifier(Type.OBJECT.getClassName()); // Fill list with java.lang.Object frame.getClassNamesJList().setSelectedIndex(0); // default, will verify java.lang.Object }
Example #4
Source File: FindRefComparison.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected ReferenceType mergeReferenceTypes(ReferenceType aRef, ReferenceType bRef) throws DataflowAnalysisException { byte aType = aRef.getType(); byte bType = bRef.getType(); if (isExtendedStringType(aType) || isExtendedStringType(bType)) { // If both types are the same extended String type, // then the same type is returned. Otherwise, extended // types are downgraded to plain java.lang.String, // and a standard merge is applied. if (aType == bType) { return aRef; } if (isExtendedStringType(aType)) { aRef = Type.STRING; } if (isExtendedStringType(bType)) { bRef = Type.STRING; } } return super.mergeReferenceTypes(aRef, bRef); }
Example #5
Source File: LocalVariablesInfo.java From commons-bcel with Apache License 2.0 | 6 votes |
/** * Adds information about the local variable in slot 'slot'. Automatically * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE. * * @param name variable name * @param startPc Range in which the variable is valid. * @param length length of ... * @param type variable type * @throws LocalVariableInfoInconsistentException if the new information conflicts * with already gathered information. */ public void add(final int slot, final String name, final int startPc, final int length, final Type type) throws LocalVariableInfoInconsistentException{ // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here. if (slot < 0 || slot >= localVariableInfos.length) { throw new AssertionViolatedException("Slot number for local variable information out of range."); } localVariableInfos[slot].add(name, startPc, length, type); if (type == Type.LONG) { localVariableInfos[slot+1].add(name, startPc, length, LONG_Upper.theInstance()); } if (type == Type.DOUBLE) { localVariableInfos[slot+1].add(name, startPc, length, DOUBLE_Upper.theInstance()); } }
Example #6
Source File: ObligationAnalysis.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
private Type nullCheck(short opcode, Edge edge, InstructionHandle last, BasicBlock sourceBlock) throws DataflowAnalysisException { if (DEBUG_NULL_CHECK) { System.out.println("checking for nullcheck on edge " + edge); } Type type = null; if ((opcode == Const.IFNULL && edge.getType() == EdgeTypes.IFCMP_EDGE) || (opcode == Const.IFNONNULL && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) { Location location = new Location(last, sourceBlock); TypeFrame typeFrame = typeDataflow.getFactAtLocation(location); if (typeFrame.isValid()) { type = typeFrame.getTopValue(); if (DEBUG_NULL_CHECK) { System.out.println("ifnull comparison of " + type + " to null at " + last); } } } return type; }
Example #7
Source File: JavaClassDefinition.java From contribution with GNU Lesser General Public License v2.1 | 6 votes |
/** * Finds the narrowest method that is compatible with a method. * An invocation of the given method can be resolved as an invocation * of the narrowest method. * @param aClassName the class for the method. * @param aMethodName the name of the method. * @param aArgTypes the types for the method. * @return the narrowest compatible method. */ public MethodDefinition findNarrowestMethod( String aClassName, String aMethodName, Type[] aArgTypes) { MethodDefinition result = null; final String javaClassName = mJavaClass.getClassName(); if (Repository.instanceOf(aClassName, javaClassName)) { // check all for (int i = 0; i < mMethodDefs.length; i++) { // TODO: check access privileges if (mMethodDefs[i].isCompatible(aMethodName, aArgTypes)) { if (result == null) { result = mMethodDefs[i]; } //else if (mMethodDefs[i].isAsNarrow(result)) { else if (result.isCompatible(mMethodDefs[i])) { result = mMethodDefs[i]; } } } } return result; }
Example #8
Source File: BCELifier.java From commons-bcel with Apache License 2.0 | 6 votes |
static String printType( final String signature ) { final Type type = Type.getType(signature); final byte t = type.getType(); if (t <= Const.T_VOID) { return "Type." + Const.getTypeName(t).toUpperCase(Locale.ENGLISH); } else if (type.toString().equals("java.lang.String")) { return "Type.STRING"; } else if (type.toString().equals("java.lang.Object")) { return "Type.OBJECT"; } else if (type.toString().equals("java.lang.StringBuffer")) { return "Type.STRINGBUFFER"; } else if (type instanceof ArrayType) { final ArrayType at = (ArrayType) type; return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions() + ")"; } else { return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")"; } }
Example #9
Source File: TransitiveHull.java From commons-bcel with Apache License 2.0 | 6 votes |
private void visitRef(final ConstantCP ccp, final boolean method) { final String class_name = ccp.getClass(cp); add(class_name); final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(ccp.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType); final String signature = cnat.getSignature(cp); if (method) { final Type type = Type.getReturnType(signature); checkType(type); for (final Type type1 : Type.getArgumentTypes(signature)) { checkType(type1); } } else { checkType(Type.getType(signature)); } }
Example #10
Source File: LocalVariableInfo.java From commons-bcel with Apache License 2.0 | 6 votes |
/** * Adds information about name and type for a given offset. * * @throws LocalVariableInfoInconsistentException if the new information conflicts * with already gathered information. */ private void add(final int offset, final String name, final Type t) throws LocalVariableInfoInconsistentException { if (getName(offset) != null) { if (!getName(offset).equals(name)) { throw new LocalVariableInfoInconsistentException("At bytecode offset '" + offset + "' a local variable has two different names: '" + getName(offset) + "' and '" + name + "'."); } } if (getType(offset) != null) { if (!getType(offset).equals(t)) { throw new LocalVariableInfoInconsistentException("At bytecode offset '" + offset + "' a local variable has two different types: '" + getType(offset) + "' and '" + t + "'."); } } setName(offset, name); setType(offset, t); }
Example #11
Source File: LocalVariables.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Creates a new LocalVariables object. * * @param localVariableCount local variable count. */ public LocalVariables(final int localVariableCount) { locals = new Type[localVariableCount]; for (int i=0; i<localVariableCount; i++) { locals[i] = Type.UNKNOWN; } }
Example #12
Source File: LocalVariableInfo.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * Adds information about name and type for a given offset. * @throws LocalVariableInfoInconsistentException if the new information conflicts * with already gathered information. */ private void add(int offset, String name, Type t) throws LocalVariableInfoInconsistentException{ if (getName(offset) != null){ if (! getName(offset).equals(name)){ throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different names: '"+getName(offset)+"' and '"+name+"'."); } } if (getType(offset) != null){ if (! getType(offset).equals(t)){ throw new LocalVariableInfoInconsistentException("At bytecode offset '"+offset+"' a local variable has two different types: '"+getType(offset)+"' and '"+t+"'."); } } setName(offset, name); setType(offset, t); }
Example #13
Source File: LocalVariables.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * Creates a new LocalVariables object. */ public LocalVariables(int maxLocals){ locals = new Type[maxLocals]; for (int i=0; i<maxLocals; i++){ locals[i] = Type.UNKNOWN; } }
Example #14
Source File: LocalVariables.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * Sets a new Type for the given local variable slot. */ public void set(int i, Type type){ if (type == Type.BYTE || type == Type.SHORT || type == Type.BOOLEAN || type == Type.CHAR){ throw new AssertionViolatedException("LocalVariables do not know about '"+type+"'. Use Type.INT instead."); } locals[i] = type; }
Example #15
Source File: IncompatibleTypes.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static IncompatibleTypes getPriorityForAssumingCompatibleWithArray(Type rhsType) { if (rhsType.equals(Type.OBJECT)) { return ARRAY_AND_OBJECT; } String sig = rhsType.getSignature(); if ("Ljava/io/Serializable;".equals(sig) || "Ljava/lang/Cloneable;".equals(sig)) { return SEEMS_OK; } return ARRAY_AND_NON_ARRAY; }
Example #16
Source File: ExceptionSet.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Get the least (lowest in the lattice) common supertype of the exceptions * in the set. Returns the special TOP type if the set is empty. */ public Type getCommonSupertype() throws ClassNotFoundException { if (commonSupertype != null) { return commonSupertype; } if (isEmpty()) { // This probably means that we're looking at an // infeasible exception path. return TypeFrame.getTopType(); } // Compute first common superclass ThrownExceptionIterator i = iterator(); ReferenceType result = i.next(); while (i.hasNext()) { if (Subtypes2.ENABLE_SUBTYPES2_FOR_COMMON_SUPERCLASS_QUERIES) { result = AnalysisContext.currentAnalysisContext().getSubtypes2().getFirstCommonSuperclass(result, i.next()); } else { result = result.getFirstCommonSuperclass(i.next()); } if (result == null) { // This should only happen if the class hierarchy // is incomplete. We'll just be conservative. result = Type.THROWABLE; break; } } // Cache and return the result commonSupertype = result; return result; }
Example #17
Source File: PLSETestCase.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * BCEL-208: A couple of methods in MethodGen.java need to test for * an empty instruction list. */ public void testB208() throws ClassNotFoundException { final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.PLSETestClass"); final ClassGen gen = new ClassGen(clazz); final ConstantPoolGen pool = gen.getConstantPool(); final Method m = gen.getMethodAt(1); final MethodGen mg = new MethodGen(m, gen.getClassName(), pool); mg.setInstructionList(null); mg.addLocalVariable("local2", Type.INT, null, null); // currently, this will cause null pointer exception mg.getLocalVariableTable(pool); }
Example #18
Source File: BuildUnconditionalParamDerefDatabase.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private void considerMethod(ClassContext classContext, Method method) { boolean hasReferenceParameters = false; for (Type argument : method.getArgumentTypes()) { if (argument instanceof ReferenceType) { hasReferenceParameters = true; } } if (hasReferenceParameters && classContext.getMethodGen(method) != null) { if (VERBOSE_DEBUG) { System.out.println("Check " + method); } analyzeMethod(classContext, method); } }
Example #19
Source File: JavaClassDefinition.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Determines whether there is reference to a given Method in this JavaClass * definition or a definition in a superclass. * @param aMethodDef the Method to check. * @param aReferenceDAO reference DAO. * @return true if there is a reference to the method of aMethodDef in * this JavaClass or a superclass. */ public boolean hasReference( MethodDefinition aMethodDef, ReferenceDAO aReferenceDAO) { final String methodName = aMethodDef.getName(); final Type[] argTypes = aMethodDef.getArgumentTypes(); // search the inheritance hierarchy JavaClass currentJavaClass = getJavaClass(); while (currentJavaClass != null) { final JavaClassDefinition javaClassDef = aReferenceDAO.findJavaClassDef(currentJavaClass); if (javaClassDef != null) { final MethodDefinition methodDef = javaClassDef.findNarrowestMethod( getJavaClass().getClassName(), methodName, argTypes); if ((methodDef != null) && (methodDef.hasReference(getJavaClass()))) { return true; } } currentJavaClass = currentJavaClass.getSuperClass(); } return false; }
Example #20
Source File: JavaBuilder.java From luaj with MIT License | 5 votes |
public void closureInitUpvalueFromLocal(String protoname, int newup, int pc, int srcslot) { boolean isrw = pi.isReadWriteUpvalue( pi.vars[srcslot][pc].upvalue ); Type uptype = isrw? (Type) TYPE_LOCALUPVALUE: (Type) TYPE_LUAVALUE; String destname = upvalueName(newup); int index = findSlotIndex( srcslot, isrw ); append(new ALOAD(index)); append(factory.createFieldAccess(protoname, destname, uptype, Constants.PUTFIELD)); }
Example #21
Source File: Pass2Verifier.java From commons-bcel with Apache License 2.0 | 5 votes |
@Override public void visitConstantFieldref(final ConstantFieldref obj) { if (obj.getTag() != Const.CONSTANT_Fieldref) { throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); } final int name_and_type_index = obj.getNameAndTypeIndex(); final ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); final String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name if (!validFieldName(name)) { throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'."); } final int class_index = obj.getClassIndex(); final ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); final String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form if (! validClassName(className)) { throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'."); } final String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method sig.(=descriptor) try{ Type.getType(sig); /* Don't need the return value */ } catch (final ClassFormatException cfe) { throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.", cfe); } }
Example #22
Source File: UselessSubclassMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private Method findSuperclassMethod(@DottedClassName String superclassName, Method subclassMethod) throws ClassNotFoundException { String methodName = subclassMethod.getName(); Type[] subArgs = null; JavaClass superClass = Repository.lookupClass(superclassName); Method[] methods = superClass.getMethods(); outer: for (Method m : methods) { if (m.getName().equals(methodName)) { if (subArgs == null) { subArgs = Type.getArgumentTypes(subclassMethod.getSignature()); } Type[] superArgs = Type.getArgumentTypes(m.getSignature()); if (subArgs.length == superArgs.length) { for (int j = 0; j < subArgs.length; j++) { if (!superArgs[j].equals(subArgs[j])) { continue outer; } } return m; } } } if (!"Object".equals(superclassName)) { @DottedClassName String superSuperClassName = superClass.getSuperclassName(); if (superSuperClassName.equals(superclassName)) { throw new ClassNotFoundException("superclass of " + superclassName + " is itself"); } return findSuperclassMethod(superSuperClassName, subclassMethod); } return null; }
Example #23
Source File: FindRefComparison.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void initEntryFact(TypeFrame result) { super.initEntryFact(result); for (int i = 0; i < methodGen.getMaxLocals(); i++) { Type t = result.getValue(i); if (t.equals(Type.STRING)) { result.setValue(i, parameterStringTypeInstance); } } }
Example #24
Source File: TypeAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public TypeAnnotation(Type objectType, String roleDescription) { this(objectType.getSignature(), roleDescription); if (objectType instanceof GenericObjectType) { GenericObjectType genericObjectType = (GenericObjectType) objectType; if (genericObjectType.getTypeCategory() == GenericUtilities.TypeCategory.PARAMETERIZED) { typeParameters = genericObjectType.getGenericParametersAsString(); } } }
Example #25
Source File: ASTLetExpr.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Fifth pass, produce Java byte code. */ @Override public void byte_code(final InstructionList il, final MethodGen method, final ConstantPoolGen cp) { final int size = idents.length; final LocalVariableGen[] l = new LocalVariableGen[size]; for(int i=0; i < size; i++) { final String ident = idents[i].getName(); final Variable entry = (Variable)env.get(ident); final Type t = BasicType.getType((byte)idents[i].getType()); final LocalVariableGen lg = method.addLocalVariable(ident, t, null, null); final int slot = lg.getIndex(); entry.setLocalVariable(lg); InstructionHandle start = il.getEnd(); exprs[i].byte_code(il, method, cp); start = (start == null)? il.getStart() : start.getNext(); lg.setStart(start); il.append(new ISTORE(slot)); ASTFunDecl.pop(); l[i] = lg; } body.byte_code(il, method, cp); final InstructionHandle end = il.getEnd(); for(int i=0; i < size; i++) { l[i].setEnd(end); } }
Example #26
Source File: FindRefComparison.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitGETSTATIC(GETSTATIC obj) { Type type = obj.getType(getCPG()); XField xf = XFactory.createXField(obj, cpg); if (xf.isFinal()) { FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary(); Item summary = fieldSummary.getSummary(xf); if (summary.isNull()) { pushValue(TypeFrame.getNullType()); return; } String slashedClassName = ClassName.fromFieldSignature(type.getSignature()); if (slashedClassName != null) { String dottedClassName = ClassName.toDottedClassName(slashedClassName); if (DEFAULT_SUSPICIOUS_SET.contains(dottedClassName)) { type = new FinalConstant(dottedClassName, xf); consumeStack(obj); pushValue(type); return; } } } if (STRING_SIGNATURE.equals(type.getSignature())) { handleLoad(obj); } else { super.visitGETSTATIC(obj); } }
Example #27
Source File: FindRefComparison.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visitGETFIELD(GETFIELD obj) { Type type = obj.getType(getCPG()); if (STRING_SIGNATURE.equals(type.getSignature())) { handleLoad(obj); } else { XField xf = XFactory.createXField(obj, cpg); if (xf.isFinal()) { FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary(); Item summary = fieldSummary.getSummary(xf); if (summary.isNull()) { consumeStack(obj); pushValue(TypeFrame.getNullType()); return; } String slashedClassName = ClassName.fromFieldSignature(type.getSignature()); if (slashedClassName != null) { String dottedClassName = ClassName.toDottedClassName(slashedClassName); if (DEFAULT_SUSPICIOUS_SET.contains(dottedClassName)) { type = new FinalConstant(dottedClassName, xf); consumeStack(obj); pushValue(type); return; } } } super.visitGETFIELD(obj); } }
Example #28
Source File: OperandStack.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Pushes a Type object onto the stack. */ public void push(final Type type) { if (type == null) { throw new AssertionViolatedException("Cannot push NULL onto OperandStack."); } if (type == Type.BOOLEAN || type == Type.CHAR || type == Type.BYTE || type == Type.SHORT) { throw new AssertionViolatedException("The OperandStack does not know about '"+type+"'; use Type.INT instead."); } if (slotsUsed() >= maxStack) { throw new AssertionViolatedException( "OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this); } stack.add(type); }
Example #29
Source File: JavaClass.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * @return A {@link Method} corresponding to * java.lang.reflect.Method if any */ public Method getMethod( final java.lang.reflect.Method m ) { for (final Method method : methods) { if (m.getName().equals(method.getName()) && (m.getModifiers() == method.getModifiers()) && Type.getSignature(m).equals(method.getSignature())) { return method; } } return null; }
Example #30
Source File: FindNoSideEffectMethods.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
/** * @param methodDescriptor */ private void sawNoSideEffectCall(MethodDescriptor methodDescriptor) { if (uselessVoidCandidate && Type.getReturnType(methodDescriptor.getSignature()) == Type.VOID && !methodDescriptor.getName().equals(Const.CONSTRUCTOR_NAME)) { /* To reduce false-positives we do not mark method as useless void if it calls * another useless void method. If that another method also in the scope of our project * then we will report it instead. If there's a cycle of no-side-effect calls, then * it's probably some delegation pattern and methods can be extended in future/derived * projects to do something useful. */ uselessVoidCandidate = false; } }