Interface ExprMirror.CtorInvocationMirror
-
- All Superinterfaces:
ExprMirror
,ExprMirror.InvocationMirror
,ExprMirror.PolyExprMirror
- Enclosing interface:
- ExprMirror
public static interface ExprMirror.CtorInvocationMirror extends ExprMirror.InvocationMirror
An invocation mirror reflecting a constructor invocation expression.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror
ExprMirror.BranchingMirror, ExprMirror.CtorInvocationMirror, ExprMirror.FunctionalExprMirror, ExprMirror.InvocationMirror, ExprMirror.LambdaExprMirror, ExprMirror.MethodRefMirror, ExprMirror.PolyExprMirror, ExprMirror.TypeSpecies
-
Nested classes/interfaces inherited from interface net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.InvocationMirror
ExprMirror.InvocationMirror.MethodCtDecl
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Iterable<JMethodSig>
getAccessibleCandidates()
Enumerates *accessible* method (or ctor) signatures with *the same name* as this invocation.Iterable<JMethodSig>
getAccessibleCandidates(JTypeMirror newType)
Returns the accessible candidates for this node, as ifgetNewType()
returned the type passed as parameter.default String
getName()
Must returnJConstructorSymbol.CTOR_NAME
.@NonNull JTypeMirror
getNewType()
Return the type name being instantiated.boolean
isAnonymous()
True if this creates an anonymous class.boolean
isDiamond()
Return true if this is a diamond constructor call.-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror
finishStandaloneInference, getInferredType, getLocation, getStandaloneSpecies, getTypingContext, isEquivalentToUnderlyingAst, setInferredType
-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.InvocationMirror
getArgumentCount, getArgumentExpressions, getCtDecl, getErasedReceiverType, getExplicitTargLoc, getExplicitTypeArguments, getReceiverType, setCtDecl
-
Methods inherited from interface net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.PolyExprMirror
getEnclosingType, getStandaloneType, unresolvedType
-
-
-
-
Method Detail
-
getNewType
@NonNull JTypeMirror getNewType()
Return the type name being instantiated. If the constructor call is a diamond invocation (or no type args), returns the generic type declaration. Otherwise returns the parameterised type. If the call declares an anonymous class, then this does *not* return the anonymous type, but its explicit supertype.- e.g. for
new ArrayList<>()
, returnsArrayList<T>
. - e.g. for
new ArrayList()
, returnsArrayList
. - e.g. for
new ArrayList<String>()
, returnsArrayList<String>
. - e.g. for
new Runnable() {}
(anonymous), returnsRunnable
.
Note that this returns a
JClassType
in valid code. Other return values may be egTypeSystem.UNKNOWN
, or aJTypeVar
, but indicate malformed code. - e.g. for
-
isAnonymous
boolean isAnonymous()
True if this creates an anonymous class. Since java 9 those can also be diamond-inferred.
-
isDiamond
boolean isDiamond()
Return true if this is a diamond constructor call. In that case the type parameters of the created instance must be inferred. Returns false if the constructor call mentions no type arguments.- e.g. for
new ArrayList<>()
, returns true. - e.g. for
new ArrayList()
, returns false. - e.g. for
new ArrayList<String>()
, returns false.
- e.g. for
-
getAccessibleCandidates
default Iterable<JMethodSig> getAccessibleCandidates()
Enumerates *accessible* method (or ctor) signatures with *the same name* as this invocation. Name and accessibility will not be checked later. The details on how to determine this are here: https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.12.1Returns the constructor of the
getNewType()
. If this is an anonymous class declaration implementing an interface, then returns the constructors of classObject
.This default implementation uses
getAccessibleCandidates(JTypeMirror)
, which should be implemented instead.- Specified by:
getAccessibleCandidates
in interfaceExprMirror.InvocationMirror
-
getAccessibleCandidates
Iterable<JMethodSig> getAccessibleCandidates(JTypeMirror newType)
Returns the accessible candidates for this node, as ifgetNewType()
returned the type passed as parameter. Since candidates depend on the new type, this allows us to write simple "spy" wrappers to redo an invocation in different conditions (ie, pretending the newtype is the parameter)- Parameters:
newType
- Assumed value ofgetNewType()
-
getName
default String getName()
Must returnJConstructorSymbol.CTOR_NAME
.- Specified by:
getName
in interfaceExprMirror.InvocationMirror
-
-