本文整理汇总了Java中com.strobel.assembler.metadata.FieldReference类的典型用法代码示例。如果您正苦于以下问题:Java FieldReference类的具体用法?Java FieldReference怎么用?Java FieldReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldReference类属于com.strobel.assembler.metadata包,在下文中一共展示了FieldReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitEqualsExpression
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor(nodes = AstNodes.EXPRESSIONS, methodName = "equals", methodSignature = "(Ljava/lang/Object;)Z")
public void visitEqualsExpression(Expression expr, MethodContext mc) {
if(isComparison(expr)) {
Expression left = expr.getArguments().get(0);
Expression right = expr.getArguments().get(1);
if(left.getCode() == AstCode.GetField && right.getCode() == AstCode.GetField) {
FieldReference lfr = ((FieldReference) left.getOperand());
FieldReference rfr = ((FieldReference) right.getOperand());
if(!lfr.isEquivalentTo(rfr)) {
lfr = lfr.resolve();
rfr = rfr.resolve();
// TODO: do not warn about comparisons like if(a == o.a && b == o.b || a == o.b && b == o.a)
if(lfr != null && rfr != null && !lfr.isEquivalentTo(rfr)) {
if (Exprs.bothMatch(Exprs.getChild(left, 0), Exprs.getChild(right, 0), Exprs::isThis,
EqualsContract::isParameter)) {
mc.report("EqualsSuspiciousFieldComparison", 0, left, OTHER_FIELD.create(rfr));
}
}
}
}
if (expr.getCode() == AstCode.InvokeVirtual && Methods.isEqualsMethod((MethodReference) expr.getOperand())) {
checkGetName(expr, mc, left);
checkGetName(expr, mc, right);
}
}
}
示例2: checkRegexp
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private void checkRegexp(MethodContext mc, Expression regexExpr, int flags) {
if((flags & Pattern.LITERAL) == 0) {
if(regexExpr.getCode() == AstCode.GetStatic) {
FieldReference fr = (FieldReference) regexExpr.getOperand();
if(fr.getName().equals("separator") && fr.getDeclaringType().getInternalName().equals("java/io/File")) {
mc.report("RegexFileSeparator", 0, regexExpr);
}
} else if(regexExpr.getCode() == AstCode.InvokeVirtual) {
MethodReference mr = (MethodReference)regexExpr.getOperand();
if(mr.getName().equals("getSeparator") && mr.getDeclaringType().getInternalName().equals("java/nio/file/FileSystem")) {
mc.report("RegexFileSeparator", 0, regexExpr);
}
}
}
Object regexObj = Nodes.getConstant(regexExpr);
if(!(regexObj instanceof String)) {
return;
}
String regex = (String)regexObj;
try {
Pattern.compile(regex, flags);
} catch (PatternSyntaxException e) {
mc.report("RegexBadSyntax", 0, regexExpr, Roles.REGEXP.create(regex), ERROR_MESSAGE.create(e.getMessage()));
}
}
示例3: replaceField
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private Frame replaceField(FieldReference fr, Expression replacement) {
MemberInfo mi = new MemberInfo(fr);
if(fieldValues.isEmpty()) {
return new Frame(this, this.sources, Collections.singletonMap(mi, replacement));
}
Expression expression = fieldValues.get(mi);
if (expression != replacement) {
if(expression != null && fieldValues.size() == 1) {
return new Frame(this, this.sources, Collections.singletonMap(mi, replacement));
}
Map<MemberInfo, Expression> res = new HashMap<>(fieldValues);
res.put(mi, replacement);
return new Frame(this, this.sources, res);
}
return this;
}
示例4: link
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
void link(MethodDefinition src, FieldReference fr, boolean isStatic, boolean write, boolean hadNull) {
if(fieldRecords == null)
return;
int prevStatus = fieldRecords.getOrDefault(fr.getName(), 0);
int curStatus = prevStatus;
if(src.getDeclaringType().isEquivalentTo(fr.getDeclaringType())) {
if(write && (src.isConstructor() && !isStatic || src.isTypeInitializer() && isStatic)) {
curStatus |= WRITE_CONSTRUCTOR;
} else {
curStatus |= write ? WRITE_CLASS : READ_CLASS;
}
} else if(src.getDeclaringType().getPackageName().equals(fr.getDeclaringType().getPackageName())) {
curStatus |= write ? WRITE_PACKAGE : READ_PACKAGE;
} else {
curStatus |= write ? WRITE_OUTSIDE : READ_OUTSIDE;
}
if(write && !hadNull) {
curStatus |= WRITE_NONNULL;
}
if(prevStatus != curStatus) {
fieldRecords.put(fr.getName(), curStatus);
}
}
示例5: visit
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visit(Expression expr, NodeChain nc, MethodContext mc, MethodDefinition md, TypeDefinition td) {
if(expr.getCode() == AstCode.PutStatic) {
FieldReference fr = (FieldReference) expr.getOperand();
FieldDefinition fd = fr.resolve();
if(fd != null && fd.isSynthetic())
return;
int priority = 0;
if(md.isPrivate() || td.isPrivate())
priority += 20;
else if(!md.isPublic() || !td.isPublic())
priority += 10;
else if(md.isConstructor())
priority += 5;
if(nc.isSynchronized() || Flags.testAny(md.getFlags(), Flags.SYNCHRONIZED))
priority += 15;
if(Exprs.getChild(expr, 0).getCode() == AstCode.AConstNull)
priority += 5;
String name = fr.getName().toLowerCase(Locale.ENGLISH);
if (fr.getFieldType().getSimpleType() == JvmType.Boolean) {
priority += 10;
if (name.contains("verbose"))
priority += 5;
}
if (name.contains("debug"))
priority += 15;
if ((md.getName().equals("start") || md.getName().equals("stop")) && md.getErasedSignature().equals(
"(Lorg/osgi/framework/BundleContext;)V") && Types.isInstance(td,
"org/osgi/framework/BundleActivator")) {
priority += 30;
}
mc.report("StaticFieldFromInstanceMethod", priority, expr);
}
}
示例6: visitCall
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visitCall(MethodContext mc, Expression expr, MethodDefinition md, NodeChain nc, TypeDefinition td) {
if(expr.getCode() == AstCode.InvokeVirtual) {
Expression target = expr.getArguments().get(0);
if(target.getCode() != AstCode.GetStatic) {
target = Exprs.getChild(expr, 0);
}
if(target.getCode() == AstCode.GetStatic) {
FieldReference fr = (FieldReference) target.getOperand();
if(md.isTypeInitializer() && td.isEquivalentTo(fr.getDeclaringType()))
return;
MethodReference mr = (MethodReference) expr.getOperand();
String methodName = mr.getName();
if(methodName.startsWith("get"))
return;
if(nc.isSynchronized() || Flags.testAny(md.getFlags(), Flags.SYNCHRONIZED))
return;
if(!isNotThreadSafe(mr.getDeclaringType()))
return;
int priority = 0;
if(Methods.isMain(md))
priority += 30;
if(!methodName.startsWith("set") && !DANGEROUS_METHODS.contains(methodName))
priority += 20;
mc.report("StaticNotThreadSafeFieldInvoke", priority, expr, Roles.FIELD.create(fr));
}
}
}
示例7: checkFieldRead
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private void checkFieldRead(Expression expr, MethodContext mc) {
if (Nodes.isFieldRead(expr)) {
FieldDefinition fd = ((FieldReference) expr.getOperand()).resolve();
if (fd != null && !Flags.testAny(fd.getFlags(), Flags.VOLATILE)) {
mc.report("SpinLoopOnField", 0, expr, Roles.FIELD.create(fd));
}
}
}
示例8: visit
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc) {
if(expr.getCode() == AstCode.InvokeVirtual || expr.getCode() == AstCode.InitObject) {
MethodReference mr = (MethodReference) expr.getOperand();
if(mr.getDeclaringType().getInternalName().equals("java/lang/String") && mr.getSignature().equals("()Ljava/lang/String;")
&& (mr.getName().equals("toUpperCase") || mr.getName().equals("toLowerCase"))) {
mc.report("ConvertCaseWithDefaultLocale", 0, expr, Roles.REPLACEMENT_METHOD.create(mr.getDeclaringType()
.getInternalName(), mr.getName(), "(Ljava/util/Locale;)Ljava/lang/String;"));
} else {
MemberInfo mi = new MemberInfo(mr);
if(defEncodingMethods.containsKey(mi)) {
if(!expr.getArguments().isEmpty()) {
Expression arg = Exprs.getChild(expr, 0);
if(arg.getCode() == AstCode.GetStatic) {
FieldReference fr = (FieldReference) arg.getOperand();
if(fr.getDeclaringType().getInternalName().equals("java/lang/System")) {
// Usages like new Formatter(System.out) are considered ok
return;
}
}
}
MemberInfo replacement = defEncodingMethods.get(mi);
if(replacement != null) {
mc.report("MethodReliesOnDefaultEncoding", replacement.getSignature().contains("Charset") ? 0
: 3, expr, Roles.REPLACEMENT_METHOD.create(replacement));
} else {
mc.report("MethodReliesOnDefaultEncoding", 10, expr);
}
}
}
}
}
示例9: visitCode
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor(nodes=AstNodes.EXPRESSIONS)
public void visitCode(Expression expr, NodeChain nc, MethodContext mc, MethodDefinition md, TypeDefinition td) {
if(expr.getCode() == AstCode.PutField) {
FieldDefinition fd = ((FieldReference) expr.getOperand()).resolve();
if (fd.getDeclaringType().isEquivalentTo(td) && !nc.isSynchronized() && !Flags.testAny(fd.getFlags(),
Flags.VOLATILE) && reportedFields.add(fd)) {
mc.report("MutableServletField", 0, expr);
}
}
}
示例10: equiOperands
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private static boolean equiOperands(Object left, Object right, EquiContext ctx) {
if (left == null)
return right == null;
if (right == null)
return false;
if (left instanceof FieldReference) {
if (!(right instanceof FieldReference))
return false;
return equiFields((FieldReference) left, (FieldReference) right);
}
if (left instanceof MethodReference) {
if (!(right instanceof MethodReference))
return false;
return equiMethods((MethodReference) left, (MethodReference) right);
}
if (left instanceof Lambda) {
if(right.getClass() != left.getClass())
return false;
return equiLambdas((Lambda)left, (Lambda)right, ctx);
}
if (left instanceof Variable) {
if(right.getClass() != left.getClass())
return false;
return ctx.varMatcher.test((Variable)left, (Variable)right);
}
return Objects.equals(right, left);
}
示例11: isAssertionStatusCheck
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private static boolean isAssertionStatusCheck(Expression expr) {
if(expr.getCode() != AstCode.LogicalNot)
return false;
Expression arg = expr.getArguments().get(0);
if(arg.getCode() != AstCode.GetStatic)
return false;
FieldReference fr = (FieldReference) arg.getOperand();
return fr.getName().startsWith("$assertions");
}
示例12: report
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
public void report(String warning, int priority, Node node, Collection<WarningAnnotation<?>> annotations) {
WarningType wt = resolveWarningType(warning, priority);
if(wt == null)
return;
List<WarningAnnotation<?>> anno = new ArrayList<>();
anno.addAll(cc.getTypeSpecificAnnotations());
anno.addAll(mdata.getMethodSpecificAnnotations());
Location loc = getLocation(node);
if (node instanceof Expression) {
Expression expr = (Expression) node;
Object operand = expr.getOperand();
if (operand instanceof Variable) {
anno.add(WarningAnnotation.forVariable((Variable) operand));
operand = ValuesFlow.getSource(expr).getOperand();
}
if (operand instanceof FieldReference && !annotations.stream().anyMatch(wa -> wa
.getRole() == Roles.FIELD)) {
anno.add(Roles.FIELD.create((FieldReference) operand));
}
if (operand instanceof MethodReference && !annotations.stream().anyMatch(wa -> wa
.getRole() == Roles.CALLED_METHOD)) {
MethodReference mr = (MethodReference) operand;
anno.add(Roles.CALLED_METHOD.create(mr));
}
}
anno.addAll(annotations);
WarningInfo info = new WarningInfo(wt, priority, loc, anno);
if (lastWarning == null) {
lastWarning = info;
} else if (!lastWarning.tryMerge(info)) {
reportWarning(lastWarning.build());
lastWarning = info;
}
}
示例13: isStaticFieldAccess
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
private boolean isStaticFieldAccess(Node n, TypeDefinition td) {
if(!Nodes.isOp(n, AstCode.GetStatic) && !Nodes.isOp(n, AstCode.PutStatic))
return false;
FieldReference fr = (FieldReference)((Expression)n).getOperand();
return fr.getDeclaringType().isEquivalentTo(td);
}
示例14: visit
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@AstVisitor
public void visit(Node node, NodeChain nc, MethodDefinition md, MethodContext mc) {
if(node instanceof Block) {
List<Node> body = ((Block) node).getBody();
for(int i=0; i<body.size()-1; i++) {
Node n = body.get(i);
if(!(n instanceof Expression))
continue;
Expression e = (Expression) n;
if(e.getCode() == AstCode.PutField) {
Expression receiver = Exprs.getChildNoSpecial(e, 0);
FieldReference fr = (FieldReference) e.getOperand();
for(int j=i+1; j<body.size(); j++) {
Node n2 = body.get(j);
if(!(n2 instanceof Expression))
break;
Expression e2 = (Expression) n2;
if(e2.getCode() == AstCode.Store || e2.getCode() == AstCode.StoreElement) {
if(Exprs.findExpression(e2, e1 -> !Nodes.isSideEffectFree(e1)) != null)
break;
continue;
}
if(e2.getCode() != AstCode.PutField)
break;
if(!Nodes.isSideEffectFree(e2.getArguments().get(1)))
break;
if (Exprs.findExpression(Exprs.getChild(e2, 1),
ex -> ex.getCode() == AstCode.GetField
&& fr.isEquivalentTo((FieldReference) ex.getOperand())
&& Nodes.isEquivalent(Exprs.getChildNoSpecial(ex, 0), receiver)) != null)
break;
Expression receiver2 = Exprs.getChildNoSpecial(e2, 0);
FieldReference fr2 = (FieldReference) e2.getOperand();
if(fr.isEquivalentTo(fr2) && Nodes.isEquivalent(receiver, receiver2)) {
int priority = 0;
if(md.isConstructor() && nc == null && Exprs.isThis(receiver2))
continue;
mc.report("FieldDoubleAssignment", priority, e, DUPLICATE_ASSIGNMENT_AT.create(mc
.getLocation(e2)));
}
}
}
}
}
}
示例15: makeFact
import com.strobel.assembler.metadata.FieldReference; //导入依赖的package包/类
@Override
public Nullness makeFact(ContextNulls state, Expression expr) {
if (Inf.CONST.getValue(expr) != null)
return Nullness.createAt(expr, NullState.NONNULL);
switch (expr.getCode()) {
case TernaryOp: {
Object cond = Inf.CONST.get(expr.getArguments().get(0));
Nullness left = get(expr.getArguments().get(1));
Nullness right = get(expr.getArguments().get(2));
if (Integer.valueOf(1).equals(cond) || Boolean.TRUE.equals(cond)) {
return left;
}
if (Integer.valueOf(0).equals(cond) || Boolean.FALSE.equals(cond)) {
return right;
}
if(left == right)
return left;
if(left == Nullness.UNKNOWN)
left = Nullness.createAt(expr.getArguments().get(1), NullState.UNKNOWN);
if(right == Nullness.UNKNOWN)
right = Nullness.createAt(expr.getArguments().get(2), NullState.UNKNOWN);
return left.or(right);
}
case Load:
if (!md.isStatic() && Exprs.isThis(expr))
return Nullness.createAt(expr, NullState.NONNULL);
return state.resolve(expr);
case GetField:
return Nullness.UNKNOWN;
case GetStatic: {
FieldReference fr = (FieldReference) expr.getOperand();
FieldDefinition fd = fr.resolve();
if (fd != null && fd.isEnumConstant())
return Nullness.createAt(expr, NullState.NONNULL);
return Nullness.UNKNOWN;
}
case InitObject:
case InitArray:
case MultiANewArray:
case NewArray:
return Nullness.createAt(expr, NullState.NONNULL);
case CheckCast:
case Store:
case PutStatic:
return get(expr.getArguments().get(0));
case PutField:
return get(expr.getArguments().get(1));
case StoreElement:
return get(expr.getArguments().get(2));
case AConstNull:
return Nullness.nullAt(expr);
default:
return Nullness.UNKNOWN;
}
}