本文整理汇总了Java中lombok.ast.ConstructorInvocation类的典型用法代码示例。如果您正苦于以下问题:Java ConstructorInvocation类的具体用法?Java ConstructorInvocation怎么用?Java ConstructorInvocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorInvocation类属于lombok.ast包,在下文中一共展示了ConstructorInvocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJavaVisitor
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public AstVisitor createJavaVisitor(final @NonNull JavaContext context) {
return new ForwardingAstVisitor() {
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
TypeReference reference = node.astTypeReference();
String typeName = reference.astParts().last().astIdentifier().astValue();
// TODO: Should we handle factory method constructions of HashMaps as well,
// e.g. via Guava? This is a bit trickier since we need to infer the type
// arguments from the calling context.
if (typeName.equals(HASH_MAP)) {
checkHashMap(context, node, reference);
}
return super.visitConstructorInvocation(node);
}
};
}
示例2: visitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
JavaParser.ResolvedNode resolvedType = mContext.resolve(node.astTypeReference());
JavaParser.ResolvedClass resolvedClass = (JavaParser.ResolvedClass) resolvedType;
if (resolvedClass != null
&& resolvedClass.isSubclassOf("android.os.Message", false)){
mContext.report(ISSUE,
node,
mContext.getLocation(node),
"You should not call `new Message()` directly.");
return true;
}
return super.visitConstructorInvocation(node);
}
示例3: afterVisitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public void afterVisitConstructorInvocation(@NonNull ConstructorInvocation node) {
ResolvedNode resolved = mContext.resolve(node);
if (resolved instanceof ResolvedMethod) {
ResolvedMethod method = (ResolvedMethod) resolved;
mTypes.put(node, method.getContainingClass());
} else {
// Implicit constructor?
TypeDescriptor type = mContext.getType(node);
if (type != null) {
ResolvedClass typeClass = type.getTypeClass();
if (typeClass != null) {
mTypes.put(node, typeClass);
}
}
}
}
示例4: visitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
if (node == mTargetNode) {
Expression arg = getTargetArgument();
if (arg instanceof VariableReference) {
VariableReference reference = (VariableReference) arg;
String variable = reference.astIdentifier().astValue();
mName = mMap.get(variable);
mDone = true;
return true;
}
}
// Is this a getString() call? On a resource object? If so,
// promote the resource argument up to the left hand side
return super.visitConstructorInvocation(node);
}
示例5: createChainOfQualifiedConstructorInvocations
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
public Node createChainOfQualifiedConstructorInvocations(
org.parboiled.Node<Node> qualifier,
List<org.parboiled.Node<Node>> constructorInvocations) {
Node current = qualifier.getValue();
if (constructorInvocations == null) return current;
for (org.parboiled.Node<Node> pNode : constructorInvocations) {
Node n = pNode.getValue();
if (n instanceof ConstructorInvocation) {
current = ((ConstructorInvocation)n).rawQualifier(current);
positionSpan(current, qualifier, pNode);
} else DanglingNodes.addDanglingNode(current, n);
}
return current;
}
示例6: checkHashMap
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
/**
* Checks whether the given constructor call and type reference refers
* to a HashMap constructor call that is eligible for replacement by a
* SparseArray call instead
*/
private void checkHashMap(JavaContext context, ConstructorInvocation node, TypeReference reference) {
StrictListAccessor<TypeReference, TypeReference> types = reference.getTypeArguments();
if (types == null || types.size() != 2) {
/*
JDK7 新写法
HashMap<Integer, String> map2 = new HashMap<>();
map2.put(1, "name");
Map<Integer, String> map3 = new HashMap<>();
map3.put(1, "name");
*/
Node result = node.getParent().getParent();
if (result instanceof VariableDefinition) {
TypeReference typeReference = ((VariableDefinition) result).astTypeReference();
checkCore(context, result, typeReference);
return;
}
if (result instanceof ExpressionStatement) {
Expression expression = ((ExpressionStatement) result).astExpression();
if (expression instanceof BinaryExpression) {
Expression left = ((BinaryExpression) expression).astLeft();
String fullTypeName = context.getType(left).getName();
checkCore2(context, result, fullTypeName);
}
}
}
// else --> lint本身已经检测
}
示例7: visitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
Node containingMethod = JavaContext.findSurroundingMethod(node);
if (null == containingMethod) {
return super.visitConstructorInvocation(node);
}
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, containingMethod);
if (null == resolvedMethod) {
return super.visitConstructorInvocation(node);
}
JavaParser.ResolvedClass resolvedClass = resolvedMethod.getContainingClass();
if (null == resolvedClass) {
return super.visitConstructorInvocation(node);
}
for (String observedClass : OBSERVED_METHODS.keySet()) {
if (resolvedClass.isSubclassOf(observedClass, false) &&
OBSERVED_METHODS.get(observedClass).contains(resolvedMethod.getName())) {
mContext.report(
WrongAllocationDetector.ISSUE,
mContext.getLocation(node),
String.format("Please don't create new objects in %s : %s", resolvedClass.getName(), resolvedMethod.getName())
);
}
}
return super.visitConstructorInvocation(node);
}
示例8: visitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
JavaParser.ResolvedClass typeClass = NodeUtils.parseContainingClass(mContext, node);
if (null != typeClass &&
typeClass.isSubclassOf("android.os.Message", false)) {
mContext.report(
NewMessageDetector.ISSUE,
mContext.getLocation(node),
"Please use Message.obtain() instead of new Message()"
);
}
return super.visitConstructorInvocation(node);
}
示例9: visitConstructor
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@SuppressWarnings("javadoc")
public void visitConstructor(
@NonNull JavaContext context,
@Nullable AstVisitor visitor,
@NonNull ConstructorInvocation node,
@NonNull ResolvedMethod constructor) {
}
示例10: visitConstructorInvocation
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public boolean visitConstructorInvocation(ConstructorInvocation node) {
NormalTypeBody anonymous = node.astAnonymousClassBody();
if (anonymous != null) {
ResolvedNode resolved = mContext.resolve(anonymous);
if (resolved instanceof ResolvedMethod) {
resolved = ((ResolvedMethod) resolved).getContainingClass();
}
if (!(resolved instanceof ResolvedClass)) {
return true;
}
ResolvedClass resolvedClass = (ResolvedClass) resolved;
ResolvedClass cls = resolvedClass;
while (cls != null) {
String fqcn = cls.getSignature();
if (fqcn != null) {
List<VisitingDetector> list = mSuperClassDetectors.get(fqcn);
if (list != null) {
for (VisitingDetector v : list) {
v.getJavaScanner().checkClass(mContext, null, anonymous,
resolvedClass);
}
}
}
cls = cls.getSuperClass();
}
}
return true;
}
示例11: visitConstructor
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public void visitConstructor(@NonNull JavaContext context, @Nullable AstVisitor visitor,
@NonNull ConstructorInvocation node, @NonNull ResolvedMethod constructor) {
if (!specifiesLocale(constructor)) {
Location location = context.getLocation(node);
String message =
"To get local formatting use `getDateInstance()`, `getDateTimeInstance()`, " +
"or `getTimeInstance()`, or use `new SimpleDateFormat(String template, " +
"Locale locale)` with for example `Locale.US` for ASCII dates.";
context.report(DATE_FORMAT, node, location, message);
}
}
示例12: getApplicableNodeTypes
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
@Nullable
public List<Class<? extends Node>> getApplicableNodeTypes() {
List<Class<? extends Node>> types = new ArrayList<Class<? extends Node>>(3);
types.add(MethodDeclaration.class);
types.add(ConstructorInvocation.class);
return types;
}
示例13: getApplicableNodeTypes
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
@Override
public List<Class<? extends Node>> getApplicableNodeTypes() {
List<Class<? extends Node>> types = new ArrayList<Class<? extends Node>>(3);
types.add(ConstructorInvocation.class);
types.add(MethodDeclaration.class);
types.add(MethodInvocation.class);
return types;
}
示例14: checkHashMap
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
/**
* Checks whether the given constructor call and type reference refers
* to a HashMap constructor call that is eligible for replacement by a
* SparseArray call instead
*/
private void checkHashMap(ConstructorInvocation node, TypeReference reference) {
// reference.hasTypeArguments returns false where it should not
StrictListAccessor<TypeReference, TypeReference> types = reference.getTypeArguments();
if (types != null && types.size() == 2) {
TypeReference first = types.first();
String typeName = first.getTypeName();
int minSdk = mContext.getMainProject().getMinSdk();
if (typeName.equals(INTEGER) || typeName.equals(BYTE)) {
String valueType = types.last().getTypeName();
if (valueType.equals(INTEGER)) {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
"Use new `SparseIntArray(...)` instead for better performance");
} else if (valueType.equals(LONG) && minSdk >= 18) {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
"Use `new SparseLongArray(...)` instead for better performance");
} else if (valueType.equals(BOOLEAN)) {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
"Use `new SparseBooleanArray(...)` instead for better performance");
} else {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
String.format(
"Use `new SparseArray<%1$s>(...)` instead for better performance",
valueType));
}
} else if (typeName.equals(LONG) && (minSdk >= 16 ||
Boolean.TRUE == mContext.getMainProject().dependsOn(
SUPPORT_LIB_ARTIFACT))) {
boolean useBuiltin = minSdk >= 16;
String message = useBuiltin ?
"Use `new LongSparseArray(...)` instead for better performance" :
"Use `new android.support.v4.util.LongSparseArray(...)` instead for better performance";
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
message);
}
}
}
示例15: checkSparseArray
import lombok.ast.ConstructorInvocation; //导入依赖的package包/类
private void checkSparseArray(ConstructorInvocation node, TypeReference reference) {
// reference.hasTypeArguments returns false where it should not
StrictListAccessor<TypeReference, TypeReference> types = reference.getTypeArguments();
if (types != null && types.size() == 1) {
TypeReference first = types.first();
String valueType = first.getTypeName();
if (valueType.equals(INTEGER)) {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
"Use `new SparseIntArray(...)` instead for better performance");
} else if (valueType.equals(BOOLEAN)) {
mContext.report(USE_SPARSE_ARRAY, node, mContext.getLocation(node),
"Use `new SparseBooleanArray(...)` instead for better performance");
}
}
}