• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TypeReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.strobel.assembler.metadata.TypeReference的典型用法代码示例。如果您正苦于以下问题:Java TypeReference类的具体用法?Java TypeReference怎么用?Java TypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeReference类属于com.strobel.assembler.metadata包,在下文中一共展示了TypeReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getMostOuterTypeRefBySlowLookuping

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
private TypeReference getMostOuterTypeRefBySlowLookuping(TypeReference typeRef) {
	String name = typeRef.getName();
	if (name == null)
		return typeRef;
	String packageName = typeRef.getPackageName();
	if (packageName == null)
		return typeRef;
	String[] nameParts = name.split("\\$");
	String newName = "";
	String sep = "";
	for (int i = 0; i < nameParts.length - 1; i++) {
		newName = newName + sep + nameParts[i];
		sep = "$";
		String newInternalName = packageName.replaceAll("\\.", "/") + "/" + newName;
		TypeReference newTypeRef = metadataSystem.lookupType(newInternalName);
		if (newTypeRef != null) {
			TypeDefinition newTypeDef = newTypeRef.resolve();
			if (newTypeDef != null) {
				return newTypeRef;
			}
		}
	}
	return typeRef;
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:25,代码来源:DecompilerLinkProvider.java


示例2: isComparison

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
private static boolean isComparison(Expression expr) {
    switch(expr.getCode()) {
    case CmpEq:
    case CmpNe:
        return true;
    case InvokeVirtual:
        return Methods.isEqualsMethod((MethodReference) expr.getOperand());
    case InvokeStatic: {
        MethodReference mr = (MethodReference) expr.getOperand();
        TypeReference tr = mr.getDeclaringType();
        return (mr.getName().equals("equals") || mr.getName().equals("deepEquals")) &&
                (Types.is(tr, Arrays.class) || Types.is(tr, Objects.class));
    }
    default:
        return false;
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:18,代码来源:EqualsContract.java


示例3: allImplementationsDerivedFromSubclass

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
private boolean allImplementationsDerivedFromSubclass(Hierarchy h, TypeReference superClass,
        TypeReference subClass) {
    TypeDefinition td = superClass.resolve();
    if(td == null || (!td.isInterface() && !Flags.testAny(td.getFlags(), Flags.ABSTRACT)) )
        return false;
    for(TypeHierarchy th : h.get(td).getSubClasses()) {
        if(subClass.getInternalName().equals(th.getInternalName()))
            continue;
        if(th.hasFlag(Flags.INTERFACE) || th.hasFlag(Flags.ABSTRACT))
            continue;
        TypeReference subType = td.getResolver().lookupType(th.getInternalName());
        if(subType == null || Types.isInstance(subType, subClass))
            continue;
        return false;
    }
    return true;
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:18,代码来源:CovariantArrays.java


示例4: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes = AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc) {
    if (expr.getCode() != AstCode.InvokeVirtual)
        return;
    MethodReference mr = (MethodReference) expr.getOperand();
    String name = mr.getName();
    if (!Types.isObject(mr.getDeclaringType()) || (!name.equals("wait") && !name.startsWith("notify")))
        return;
    TypeReference type = ValuesFlow.reduceType(expr.getArguments().get(0));
    if (type == null || !type.getInternalName().startsWith("java/util/concurrent/"))
        return;
    TypeDefinition target = type.resolve();
    if (target == null || !target.isPublic())
        return;
    MethodDefinition replacement = findReplacement(name, target);
    if(replacement != null) {
        mc.report("IncorrectConcurrentMethod", 0, expr, TARGET.create(target), Roles.REPLACEMENT_METHOD.create(replacement));
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:20,代码来源:LockProblems.java


示例5: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visit(Expression expr, NodeChain nc, MethodContext mc) {
    if(nc.getNode() instanceof Expression)
        return;
    if(expr.getCode() == AstCode.InvokeVirtual || expr.getCode() == AstCode.InvokeInterface) {
        MethodReference mr = (MethodReference) expr.getOperand();
        boolean skipMethod = mr.getName().equals("skip") && mr.getSignature().equals("(J)J") ||
                mr.getName().equals("skipBytes") && mr.getSignature().equals("(I)I");
        boolean readMethod = mr.getName().equals("read") && (mr.getSignature().equals("([B)I") ||
                mr.getSignature().equals("([BII)I") || mr.getSignature().equals("([C)I") ||
                mr.getSignature().equals("([CII)I"));
        if(skipMethod || readMethod) {
            TypeReference type = ValuesFlow.reduceType(expr.getArguments().get(0));
            if(type == null)
                type = mr.getDeclaringType();
            if(!isInputStream(type))
                return;
            if(skipMethod && Types.isInstance(type, "javax/imageio/stream/ImageInputStream"))
                return;
            int priority = 0;
            if(!Types.isInstance(type, "java/io/BufferedInputStream"))
                priority += 15;
            mc.report(skipMethod ? "ReturnValueOfSkip" : "ReturnValueOfRead", priority, expr);
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:27,代码来源:CheckReturnValue.java


示例6: visitClass

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@ClassVisitor
public void visitClass(TypeDefinition td, ClassContext cc) {
    isSerializable = Types.isInstance(td, "java/io/Serializable");
    if(Types.isInstance(td, "java/util/Comparator") && !td.isAnonymous() && !td.isLocalClass()
            && !isSerializable) {
        int priority = 0;
        for(FieldDefinition fd : td.getDeclaredFields()) {
            TypeReference fieldType = fd.getFieldType();
            while(fieldType.isArray())
                fieldType = fieldType.getElementType();
            if(fieldType.isPrimitive())
                continue;
            if(Types.isInstance(fieldType, "java/io/Serializable")) {
                priority+=10;
                if(priority > 20)
                    break;
            }
        }
        cc.report("ComparatorIsNotSerializable", priority, SHOULD_IMPLEMENT.create("java/io/Serializable"));
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:22,代码来源:SerializationIdiom.java


示例7: visitClass

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@ClassVisitor
public void visitClass(TypeDefinition td, ClassContext cc) {
    if (td.isAnonymous() || td.isSynthetic())
        return;
    String name = td.getSimpleName();
    if (Character.isLetter(name.charAt(0)) && !Character.isUpperCase(name.charAt(0)) && name.indexOf('_') == -1) {
        cc.report("BadNameOfClass", td.isPublic() ? 0 : 15);
    }
    if (name.endsWith("Exception") && !Types.isInstance(td, "java/lang/Throwable")) {
        cc.report("BadNameOfClassException", td.isPublic() ? 0 : 15);
    }
    TypeReference superClass = td.getBaseType();
    if (superClass != null && superClass.getSimpleName().equals(name)) {
        cc.report("BadNameOfClassSameAsSuperclass", td.isPublic() ? 0 : 15, Roles.SUPERCLASS.create(superClass));
    }
    for (TypeReference iface : td.getExplicitInterfaces()) {
        if (iface.getSimpleName().equals(name)) {
            cc.report("BadNameOfClassSameAsInterface", td.isPublic() ? 0 : 15, Roles.INTERFACE.create(iface));
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:22,代码来源:Naming.java


示例8: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes = AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc, DeclaredAnnotations da) {
    if (expr.getCode() == AstCode.InvokeVirtual && expr.getArguments().size() == 2) {
        MethodReference mr = (MethodReference) expr.getOperand();
        if ((mr.getDeclaringType().getInternalName().startsWith("java/lang/reflect/") || mr.getDeclaringType()
                .getInternalName().equals("java/lang/Class")) && mr.getName().contains("Annotation")) {
            Object constant = Nodes.getConstant(expr.getArguments().get(1));
            if (constant instanceof TypeReference) {
                TypeReference tr = (TypeReference) constant;
                DeclaredAnnotation annot = da.get(tr);
                if (annot != null && annot.getPolicy() != RetentionPolicy.RUNTIME) {
                    mc.report("AnnotationNoRuntimeRetention", 0, expr, ANNOTATION.create(tr));
                }
            }
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:18,代码来源:NoRuntimeRetention.java


示例9: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes = AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc) {
    if (expr.getCode() != AstCode.CheckCast)
        return;
    TypeReference targetType = (TypeReference) expr.getOperand();
    if (!targetType.isArray() || Types.isObject(targetType.getElementType()))
        return;
    Expression arg = Exprs.getChild(expr, 0);
    if (arg.getCode() != AstCode.InvokeVirtual && arg.getCode() != AstCode.InvokeInterface)
        return;
    MethodReference mr = (MethodReference) arg.getOperand();
    if (!mr.getName().equals("toArray") || !mr.getSignature().equals("()[Ljava/lang/Object;"))
        return;
    Expression target = Exprs.getChild(arg, 0);
    if (!Types.isInstance(target.getInferredType(), "java/util/Collection"))
        return;
    mc.report("ImpossibleToArrayDowncast", 0, target, Roles.TARGET_TYPE.create(targetType),
        TARGET_ELEMENT_TYPE.create(targetType.getElementType()));
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:20,代码来源:ToArrayDowncast.java


示例10: getIntegralType

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
private JvmType getIntegralType(Expression expression) {
    TypeReference type = expression.getInferredType();
    if (type == null)
        return null;
    JvmType jvmType = type.getSimpleType();
    if (!jvmType.isIntegral())
        return null;
    if (jvmType == JvmType.Integer || jvmType == JvmType.Long)
        return jvmType;
    // Fix procyon type inference
    switch (expression.getCode()) {
    case Add:
    case Sub:
    case Div:
    case Rem:
    case Mul:
    case Shr:
    case Shl:
    case UShr:
    case Neg:
        return JvmType.Integer;
    default:
        return jvmType;
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:26,代码来源:NumericComparison.java


示例11: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS, methodName="<clinit>")
public void visit(Expression expr, NodeChain nc, MethodContext mc, TypeDefinition td) {
    if(expr.getOperand() instanceof MemberReference) {
        MemberReference mr = (MemberReference) expr.getOperand();
        TypeReference tr = mr.getDeclaringType();
        TypeDefinition subType = tr == null ? null : tr.resolve();
        if (subType != null && (subType.isAnonymous() || subType.isLocalClass())) {
            subType = subType.getBaseType().resolve();
        }
        if (subType != null && !td.isEquivalentTo(subType) && Types.isInstance(subType, td) && nc
                .getLambdaMethod() == null) {
            mc.report("InitializerRefersSubclass", td.isNonPublic() || subType.isNonPublic() ? 5 : 0, expr,
                Roles.SUBCLASS.create(subType));
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:17,代码来源:InitializerRefersSubclass.java


示例12: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc) {
    if(expr.getOperand() instanceof MethodReference) {
        MethodReference mr = (MethodReference) expr.getOperand();
        if(mr.getErasedSignature().contains("[Ljava/lang/Object;)")) {
            Expression lastArg = expr.getArguments().get(expr.getArguments().size()-1);
            if(lastArg.getCode() == AstCode.InitArray && lastArg.getArguments().size() == 1) {
                TypeReference nested = lastArg.getArguments().get(0).getInferredType();
                if(nested != null && nested.isArray() && nested.getElementType().isPrimitive()) {
                    int priority = 0;
                    if(!highPriority(mr)) {
                        priority = 10;
                        MethodDefinition md = mr.resolve();
                        if(md == null) {
                            priority = 20;
                        } else if(!md.isVarArgs())
                            return;
                    }
                    mc.report("PrimitiveArrayPassedAsVarArg", priority, lastArg, Roles.CALLED_METHOD.create(mr),
                        Roles.ARRAY_TYPE.create(nested));
                }
            }
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:26,代码来源:IncorrectVarArg.java


示例13: report

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
private void report(MethodContext mc, TypeReference typeRef, Expression expr, Expression cond, EdgeType deadEdge,
        EType eType, String wType) {
    int priority = 0;
    List<WarningAnnotation<?>> anno = new ArrayList<>(Arrays.asList(Roles.TARGET_TYPE.create(typeRef), ETYPE.create(
        eType.toString()), Roles.EXPRESSION.create(expr)));
    if (deadEdge != null) {
        CodeBlock deadCode = mc.findDeadCode(cond, deadEdge);
        if (deadCode != null) {
            priority = deadCode.isExceptional ? 40 : 0;
            anno.add(Roles.DEAD_CODE_LOCATION.create(mc, deadCode.startExpr));
        } else {
            priority = 20;
        }
    }
    mc.report(wType, priority, expr, anno);
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:17,代码来源:UnnecessaryInstanceOf.java


示例14: visit

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc) {
    if(expr.getCode() == AstCode.MonitorEnter) {
        Expression arg = expr.getArguments().get(0);
        if(arg.getCode() == AstCode.Load && ((Variable)arg.getOperand()).isGenerated())
            arg = ValuesFlow.getSource(arg);
        TypeReference type = arg.getInferredType();
        if(type != null && Types.isBoxed(type)) {
            String warningType;
            if(arg.getCode() == AstCode.InitObject) {
                warningType = "SynchronizationOnUnsharedBoxed";
            } else if(type.getInternalName().equals("java/lang/Boolean")) {
                warningType = "SynchronizationOnBoolean";
            } else {
                warningType = "SynchronizationOnBoxedNumber";
            }
            mc.report(warningType, 0, arg, MONITOR_TYPE.create(type), Roles.EXPRESSION.create(arg));
        }
    }
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:21,代码来源:BadMonitorObject.java


示例15: addExceptional

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@Override
public void addExceptional(BasicBlock block, TypeReference exception) {
    for (Entry<CatchBlock, BasicBlock> entry : catches.entrySet()) {
        for (TypeReference tr : types(entry.getKey())) {
            if (Types.isInstance(exception, tr)) {
                // Exact match: catch and return
                block.addTarget(EdgeType.FAIL, entry.getValue());
                return;
            } else if (Types.isInstance(tr, exception) || !Types.hasCompleteHierarchy(tr.resolve())) {
                // Inexact match: probably caught here or by another catch block
                block.addTarget(EdgeType.FAIL, entry.getValue());
            }
        }
    }
    super.addExceptional(block, exception);
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:17,代码来源:CFG.java


示例16: of

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
static EType of(TypeReference tr, What what) {
    if (tr == null || tr.isPrimitive() || (what == What.SUBTYPE && Types.isObject(tr)))
        return UNKNOWN;
    TypeDefinition td = tr.resolve();
    if (td == null)
        return UNKNOWN;
    if (td.isFinal() || td.isPrimitive()) {
        if (what == What.SUBTYPE)
            what = What.EXACT;
        if (what == What.NOT)
            what = What.NOT_SUBTYPE;
    }
    TypeReference newTr = td;
    while (tr.isArray()) {
        tr = tr.getElementType();
        newTr = newTr.makeArrayType();
    }
    boolean complete = Types.hasCompleteHierarchy(td);
    return new SingleType(newTr, what, complete);
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:21,代码来源:SingleType.java


示例17: is

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@Override
public YesNoMaybe is(TypeReference tr, boolean exact) {
    boolean hasYes = false, hasNo = false;
    for (EType type : types) {
        switch (type.is(tr, exact)) {
        case YES:
            hasYes = true;
            break;
        case NO:
            hasNo = true;
            break;
        default:
        }
    }
    if (hasYes && hasNo)
        return YesNoMaybe.MAYBE;
    if (hasYes)
        return YesNoMaybe.YES;
    if (hasNo)
        return YesNoMaybe.NO;
    return YesNoMaybe.MAYBE;
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:23,代码来源:AndType.java


示例18: shrinkConstraint

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
@Override
public EType shrinkConstraint(TypeReference tr, boolean exact) {
    Set<SingleType> yes = new HashSet<>(), no = new HashSet<>();
    for (SingleType type : types) {
        switch (type.is(tr, exact)) {
        case YES:
            yes.add(type);
            break;
        case NO:
            no.add(type);
            break;
        default:
        }
    }
    if (!yes.isEmpty() && !no.isEmpty())
        return this;
    if (!yes.isEmpty())
        return of(yes);
    if (!no.isEmpty())
        return of(no);
    return this;
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:23,代码来源:AndType.java


示例19: isInTry

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
public boolean isInTry(String... wantedExceptions) {
    NodeChain nc = this;
    while(nc != null) {
        if(nc.getNode() instanceof Block && nc.getParent() != null && nc.getParent().getNode() instanceof TryCatchBlock) {
            TryCatchBlock tcb = (TryCatchBlock) nc.getParent().getNode();
            for(CatchBlock catchBlock : tcb.getCatchBlocks()) {
                TypeReference exType = catchBlock.getExceptionType();
                if(exType != null && Arrays.stream(wantedExceptions).anyMatch(exType.getInternalName()::equals))
                    return true;
                if(catchBlock.getCaughtTypes().stream().anyMatch(t -> 
                    Arrays.stream(wantedExceptions).anyMatch(t.getInternalName()::equals)))
                    return true;
            }
        }
        nc = nc.getParent();
    }
    return false;
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:19,代码来源:NodeChain.java


示例20: hasAnnotation

import com.strobel.assembler.metadata.TypeReference; //导入依赖的package包/类
public static boolean hasAnnotation(IAnnotationsProvider fd, boolean ignoreDeprecated) {
    for (CustomAnnotation ca : fd.getAnnotations()) {
        TypeReference annoType = ca.getAnnotationType();
        if (annoType.getPackageName().equals(INTERNAL_ANNOTATION_PACKAGE))
            continue;
        if (ignoreDeprecated && annoType.getInternalName().equals("java/lang/Deprecated"))
            continue;
        String simpleName = annoType.getSimpleName();
        if (simpleName.startsWith("Suppress") && simpleName.endsWith("Warning"))
            continue;
        if (simpleName.equalsIgnoreCase("nonnull") || simpleName.equalsIgnoreCase("notnull") || simpleName
                .equalsIgnoreCase("nullable") || simpleName.equalsIgnoreCase("checkfornull"))
            continue;
        return true;
    }
    return false;
}
 
开发者ID:amaembo,项目名称:huntbugs,代码行数:18,代码来源:Annotations.java



注:本文中的com.strobel.assembler.metadata.TypeReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Query类代码示例发布时间:2022-05-22
下一篇:
Java State类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap