idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
32,000 | private VisitorState createVisitorState ( Context context , DescriptionListener listener ) { ErrorProneOptions options = requireNonNull ( context . get ( ErrorProneOptions . class ) ) ; return VisitorState . createConfiguredForCompilation ( context , listener , scanner ( ) . severityMap ( ) , options ) ; } | Create a VisitorState object from a compilation unit . |
32,001 | private static boolean missingFormatArgs ( String value ) { try { Formatter . check ( value ) ; } catch ( MissingFormatArgumentException e ) { return true ; } catch ( Exception ignored ) { } return false ; } | Returns true for strings that contain format specifiers . |
32,002 | private static boolean shouldSkipImportTreeFix ( DiagnosticPosition position , Fix f ) { if ( position . getTree ( ) != null && position . getTree ( ) . getKind ( ) != Kind . IMPORT ) { return false ; } return ! f . getImportsToAdd ( ) . isEmpty ( ) || ! f . getImportsToRemove ( ) . isEmpty ( ) ; } | be fixed if they were specified via SuggestedFix . replace for example . |
32,003 | public Description matchMemberSelect ( MemberSelectTree tree , VisitorState state ) { Symbol symbol = ASTHelpers . getSymbol ( tree ) ; if ( symbol == null || symbol . owner == null || symbol . getKind ( ) != ElementKind . FIELD || ! symbol . isStatic ( ) || ! R_STRING_CLASSNAME . contentEquals ( symbol . owner . getQualifiedName ( ) ) ) { return Description . NO_MATCH ; } String misleading = symbol . getSimpleName ( ) . toString ( ) ; String preferred = MISLEADING . get ( misleading ) ; if ( preferred == null ) { return Description . NO_MATCH ; } return buildDescription ( tree ) . setMessage ( String . format ( "%s.%s is not \"%s\" but \"%s\"; prefer %s.%s for clarity" , R_STRING_CLASSNAME , misleading , ASSUMED_MEANINGS . get ( misleading ) , ASSUMED_MEANINGS . get ( preferred ) , R_STRING_CLASSNAME , preferred ) ) . addFix ( SuggestedFix . replace ( tree , state . getSourceForNode ( tree . getExpression ( ) ) + "." + preferred ) ) . build ( ) ; } | assumed and actual meaning |
32,004 | private boolean isTypeParameterThreadSafe ( TypeVariableSymbol symbol , Set < String > containerTypeParameters ) { if ( ! recursiveThreadSafeTypeParameter . add ( symbol ) ) { return true ; } try { for ( Type bound : symbol . getBounds ( ) ) { if ( ! isThreadSafeType ( true , containerTypeParameters , bound ) . isPresent ( ) ) { return true ; } } return hasThreadSafeTypeParameterAnnotation ( symbol ) ; } finally { recursiveThreadSafeTypeParameter . remove ( symbol ) ; } } | Returns whether a type parameter is thread - safe . |
32,005 | public Type mutableEnclosingInstance ( Optional < ClassTree > tree , ClassType type ) { if ( tree . isPresent ( ) && ! CanBeStaticAnalyzer . referencesOuter ( tree . get ( ) , ASTHelpers . getSymbol ( tree . get ( ) ) , state ) ) { return null ; } Type enclosing = type . getEnclosingType ( ) ; while ( ! Type . noType . equals ( enclosing ) ) { if ( getMarkerOrAcceptedAnnotation ( enclosing . tsym , state ) == null && isThreadSafeType ( false , ImmutableSet . of ( ) , enclosing ) . isPresent ( ) ) { return enclosing ; } enclosing = enclosing . getEnclosingType ( ) ; } return null ; } | Returns an enclosing instance for the specified type if it is thread - safe . |
32,006 | public Set < String > threadSafeTypeParametersInScope ( Symbol sym ) { if ( sym == null ) { return ImmutableSet . of ( ) ; } ImmutableSet . Builder < String > result = ImmutableSet . builder ( ) ; OUTER : for ( Symbol s = sym ; s . owner != null ; s = s . owner ) { switch ( s . getKind ( ) ) { case INSTANCE_INIT : continue ; case PACKAGE : break OUTER ; default : break ; } AnnotationInfo annotation = getMarkerOrAcceptedAnnotation ( s , state ) ; if ( annotation == null ) { continue ; } for ( TypeVariableSymbol typaram : s . getTypeParameters ( ) ) { String name = typaram . getSimpleName ( ) . toString ( ) ; if ( annotation . containerOf ( ) . contains ( name ) ) { result . add ( name ) ; } } if ( s . isStatic ( ) ) { break ; } } return result . build ( ) ; } | Gets the set of in - scope threadsafe type parameters from the containerOf specs on annotations . |
32,007 | public AnnotationInfo getInheritedAnnotation ( Symbol sym , VisitorState state ) { return getAnnotation ( sym , markerAnnotations , state ) ; } | Gets the possibly inherited marker annotation on the given symbol and reverse - propagates containerOf spec s from super - classes . |
32,008 | public Violation checkInstantiation ( Collection < TypeVariableSymbol > typeParameters , Collection < Type > typeArguments ) { return Streams . zip ( typeParameters . stream ( ) , typeArguments . stream ( ) , ( sym , type ) -> { if ( ! hasThreadSafeTypeParameterAnnotation ( sym ) ) { return Violation . absent ( ) ; } Violation info = isThreadSafeType ( true , ImmutableSet . of ( ) , type ) ; if ( ! info . isPresent ( ) ) { return Violation . absent ( ) ; } return info . plus ( String . format ( "instantiation of '%s' is %s" , sym , purpose . mutableOrNotThreadSafe ( ) ) ) ; } ) . filter ( Violation :: isPresent ) . findFirst ( ) . orElse ( Violation . absent ( ) ) ; } | Checks that any thread - safe type parameters are instantiated with thread - safe types . |
32,009 | public Violation checkInvocation ( Type methodType , Symbol symbol ) { if ( methodType == null ) { return Violation . absent ( ) ; } List < TypeVariableSymbol > typeParameters = symbol . getTypeParameters ( ) ; if ( typeParameters . stream ( ) . noneMatch ( this :: hasThreadSafeTypeParameterAnnotation ) ) { return Violation . absent ( ) ; } ImmutableMap < TypeVariableSymbol , Type > instantiation = getInstantiation ( state . getTypes ( ) , methodType ) ; typeParameters = typeParameters . stream ( ) . filter ( instantiation :: containsKey ) . collect ( toImmutableList ( ) ) ; return checkInstantiation ( typeParameters , typeParameters . stream ( ) . map ( instantiation :: get ) . collect ( toImmutableList ( ) ) ) ; } | Checks the instantiation of any thread - safe type parameters in the current invocation . |
32,010 | private static boolean isImmutable ( Type type , VisitorState state ) { switch ( type . getKind ( ) ) { case BOOLEAN : case BYTE : case SHORT : case INT : case CHAR : case FLOAT : return true ; case LONG : case DOUBLE : return true ; default : break ; } return IMMUTABLE_WHITELIST . contains ( state . getTypes ( ) . erasure ( type ) . tsym . getQualifiedName ( ) . toString ( ) ) ; } | Recognize a small set of known - immutable types that are safe for DCL even without a volatile field . |
32,011 | private Description handleLocal ( DCLInfo info , VisitorState state ) { JCExpressionStatement expr = getChild ( info . synchTree ( ) . getBlock ( ) , JCExpressionStatement . class ) ; if ( expr == null ) { return Description . NO_MATCH ; } if ( expr . getStartPosition ( ) > ( ( JCTree ) info . innerIf ( ) ) . getStartPosition ( ) ) { return Description . NO_MATCH ; } if ( ! ( expr . getExpression ( ) instanceof JCAssign ) ) { return Description . NO_MATCH ; } JCAssign assign = ( JCAssign ) expr . getExpression ( ) ; if ( ! Objects . equals ( ASTHelpers . getSymbol ( assign . getVariable ( ) ) , info . sym ( ) ) ) { return Description . NO_MATCH ; } Symbol sym = ASTHelpers . getSymbol ( assign . getExpression ( ) ) ; if ( ! ( sym instanceof VarSymbol ) ) { return Description . NO_MATCH ; } VarSymbol fvar = ( VarSymbol ) sym ; if ( fvar . getKind ( ) != ElementKind . FIELD ) { return Description . NO_MATCH ; } return handleField ( info . outerIf ( ) , fvar , state ) ; } | Report a diagnostic for an instance of DCL on a local variable . A match is only reported if a non - volatile field is written to the variable after acquiring the lock and before the second null - check on the local . |
32,012 | private static JCTree findFieldDeclaration ( TreePath path , VarSymbol var ) { for ( TreePath curr = path ; curr != null ; curr = curr . getParentPath ( ) ) { Tree leaf = curr . getLeaf ( ) ; if ( ! ( leaf instanceof JCClassDecl ) ) { continue ; } for ( JCTree tree : ( ( JCClassDecl ) leaf ) . getMembers ( ) ) { if ( Objects . equals ( var , ASTHelpers . getSymbol ( tree ) ) ) { return tree ; } } } return null ; } | Performs a best - effort search for the AST node of a field declaration . |
32,013 | private boolean matches ( TypeCastTree tree , VisitorState state ) { Type treeType = ASTHelpers . getType ( tree . getType ( ) ) ; if ( treeType . getTag ( ) != TypeTag . INT ) { return false ; } ExpressionTree expression = ASTHelpers . stripParentheses ( tree . getExpression ( ) ) ; if ( expression . getKind ( ) != Kind . MINUS ) { return false ; } Type expressionType = getTypeOfSubtract ( ( BinaryTree ) expression , state ) ; TypeTag expressionTypeTag = state . getTypes ( ) . unboxedTypeOrType ( expressionType ) . getTag ( ) ; return ( expressionTypeTag == TypeTag . LONG ) ; } | Matches if this is a narrowing integral cast between signed types where the expression is a subtract . |
32,014 | boolean isMemberUnsupported ( String className , ClassMemberKey memberKey ) { return unsupportedMembersByClass ( ) . containsEntry ( className , memberKey ) || unsupportedMembersByClass ( ) . containsEntry ( className , ClassMemberKey . create ( memberKey . identifier ( ) , "" ) ) ; } | Returns true if the member with the given declaring class is unsupported . |
32,015 | private static Matcher < ExpressionTree > methodReturnsSameTypeAsReceiver ( ) { return new Matcher < ExpressionTree > ( ) { public boolean matches ( ExpressionTree expressionTree , VisitorState state ) { return isSameType ( ASTHelpers . getReceiverType ( expressionTree ) , ASTHelpers . getReturnType ( expressionTree ) , state ) ; } } ; } | Matches method invocations that return the same type as the receiver object . |
32,016 | private static Matcher < ExpressionTree > methodReceiverHasType ( final Set < String > typeSet ) { return new Matcher < ExpressionTree > ( ) { public boolean matches ( ExpressionTree expressionTree , VisitorState state ) { Type receiverType = ASTHelpers . getReceiverType ( expressionTree ) ; return typeSet . contains ( receiverType . toString ( ) ) ; } } ; } | Matches method calls whose receiver objects are of a type included in the set . |
32,017 | private static Optional < Fix > stringBufferFix ( VisitorState state ) { Tree tree = state . getPath ( ) . getLeaf ( ) ; if ( ! ( tree instanceof NewClassTree ) ) { return Optional . empty ( ) ; } NewClassTree newClassTree = ( NewClassTree ) tree ; Tree parent = state . getPath ( ) . getParentPath ( ) . getLeaf ( ) ; if ( ! ( parent instanceof VariableTree ) ) { return Optional . empty ( ) ; } VariableTree varTree = ( VariableTree ) parent ; VarSymbol varSym = ASTHelpers . getSymbol ( varTree ) ; TreePath methodPath = findEnclosingMethod ( state ) ; if ( methodPath == null ) { return Optional . empty ( ) ; } boolean [ ] escape = { false } ; new TreePathScanner < Void , Void > ( ) { public Void visitIdentifier ( IdentifierTree tree , Void unused ) { if ( varSym . equals ( ASTHelpers . getSymbol ( tree ) ) ) { Tree parent = getCurrentPath ( ) . getParentPath ( ) . getLeaf ( ) ; if ( parent == varTree ) { return null ; } if ( ! ( parent instanceof MemberSelectTree ) || ( ( MemberSelectTree ) parent ) . getExpression ( ) != tree ) { escape [ 0 ] = true ; } } return null ; } } . scan ( methodPath , null ) ; if ( escape [ 0 ] ) { return Optional . empty ( ) ; } return Optional . of ( SuggestedFix . builder ( ) . replace ( newClassTree . getIdentifier ( ) , "StringBuilder" ) . replace ( varTree . getType ( ) , "StringBuilder" ) . build ( ) ) ; } | current method . |
32,018 | private boolean mockingObsoleteMethod ( MethodTree enclosingMethod , VisitorState state , Type type ) { boolean [ ] found = { false } ; enclosingMethod . accept ( new TreeScanner < Void , Void > ( ) { public Void visitMethodInvocation ( MethodInvocationTree node , Void unused ) { if ( found [ 0 ] ) { return null ; } if ( MOCKITO_MATCHER . matches ( node , state ) ) { Type stubber = ASTHelpers . getReturnType ( node ) ; if ( ! stubber . getTypeArguments ( ) . isEmpty ( ) && ASTHelpers . isSameType ( getOnlyElement ( stubber . getTypeArguments ( ) ) , type , state ) ) { found [ 0 ] = true ; } } return super . visitMethodInvocation ( node , null ) ; } } , null ) ; return found [ 0 ] ; } | Allow mocking APIs that return obsolete types . |
32,019 | private static boolean implementingObsoleteMethod ( MethodTree enclosingMethod , VisitorState state , Type type ) { MethodSymbol method = ASTHelpers . getSymbol ( enclosingMethod ) ; if ( method == null ) { return false ; } if ( ASTHelpers . findSuperMethods ( method , state . getTypes ( ) ) . isEmpty ( ) ) { return false ; } if ( ! ASTHelpers . isSameType ( method . getReturnType ( ) , type , state ) ) { return false ; } return true ; } | Allow creating obsolete types when overriding a method with an obsolete return type . |
32,020 | protected SuppressedState isSuppressed ( Suppressible suppressible , ErrorProneOptions errorProneOptions ) { boolean suppressedInGeneratedCode = errorProneOptions . disableWarningsInGeneratedCode ( ) && severityMap ( ) . get ( suppressible . canonicalName ( ) ) != SeverityLevel . ERROR ; return currentSuppressions . suppressedState ( suppressible , suppressedInGeneratedCode ) ; } | Returns if this checker should be suppressed on the current tree path . |
32,021 | public JCExpression getUnderlyingBinding ( Unifier unifier ) { return ( unifier == null ) ? null : unifier . getBinding ( new UFreeIdent . Key ( identifier ( ) ) ) ; } | Gets the binding of the underlying identifier in the unifier . |
32,022 | public static Optional < String > loadVersionFromPom ( ) { try ( InputStream stream = ErrorProneVersion . class . getResourceAsStream ( PROPERTIES_RESOURCE ) ) { if ( stream == null ) { return Optional . absent ( ) ; } Properties mavenProperties = new Properties ( ) ; mavenProperties . load ( stream ) ; return Optional . of ( mavenProperties . getProperty ( "version" ) ) ; } catch ( IOException expected ) { return Optional . absent ( ) ; } } | Loads the Error Prone version . |
32,023 | public static void analyze ( VisitorState state , LockEventListener listener , Predicate < Tree > isSuppressed ) { HeldLockSet locks = HeldLockSet . empty ( ) ; locks = handleMonitorGuards ( state , locks ) ; new LockScanner ( state , listener , isSuppressed ) . scan ( state . getPath ( ) , locks ) ; } | Analyzes a method body tracking the set of held locks and checking accesses to guarded members . |
32,024 | private static Matcher < UnaryTree > expressionFromUnaryTree ( final Matcher < ExpressionTree > exprMatcher ) { return new Matcher < UnaryTree > ( ) { public boolean matches ( UnaryTree tree , VisitorState state ) { return exprMatcher . matches ( tree . getExpression ( ) , state ) ; } } ; } | Extracts the expression from a UnaryTree and applies a matcher to it . |
32,025 | private static Matcher < CompoundAssignmentTree > variableFromCompoundAssignmentTree ( final Matcher < ExpressionTree > exprMatcher ) { return new Matcher < CompoundAssignmentTree > ( ) { public boolean matches ( CompoundAssignmentTree tree , VisitorState state ) { return exprMatcher . matches ( tree . getVariable ( ) , state ) ; } } ; } | Extracts the variable from a CompoundAssignmentTree and applies a matcher to it . |
32,026 | private static Matcher < AssignmentTree > variableFromAssignmentTree ( final Matcher < ExpressionTree > exprMatcher ) { return new Matcher < AssignmentTree > ( ) { public boolean matches ( AssignmentTree tree , VisitorState state ) { return exprMatcher . matches ( tree . getVariable ( ) , state ) ; } } ; } | Extracts the variable from an AssignmentTree and applies a matcher to it . |
32,027 | private static Matcher < AssignmentTree > assignmentIncrementDecrementMatcher ( ExpressionTree variable ) { return allOf ( variableFromAssignmentTree ( Matchers . < ExpressionTree > hasModifier ( Modifier . VOLATILE ) ) , not ( inSynchronized ( ) ) , assignment ( Matchers . < ExpressionTree > anything ( ) , toType ( BinaryTree . class , Matchers . < BinaryTree > allOf ( Matchers . < BinaryTree > anyOf ( kindIs ( Kind . PLUS ) , kindIs ( Kind . MINUS ) ) , binaryTree ( sameVariable ( variable ) , Matchers . < ExpressionTree > anything ( ) ) ) ) ) ) ; } | Matches patterns like i = i + 1 and i = i - 1 in which i is volatile and the pattern is not enclosed by a synchronized block . |
32,028 | public static boolean referencesOuter ( Tree tree , Symbol owner , VisitorState state ) { CanBeStaticAnalyzer scanner = new CanBeStaticAnalyzer ( owner , state ) ; ( ( JCTree ) tree ) . accept ( scanner ) ; return ! scanner . canPossiblyBeStatic || ! scanner . outerReferences . isEmpty ( ) ; } | Returns true if the tree references its enclosing class . |
32,029 | private static boolean memberOfEnclosing ( Symbol owner , VisitorState state , Symbol sym ) { if ( sym == null || ! sym . hasOuterInstance ( ) ) { return false ; } for ( ClassSymbol encl = owner . owner . enclClass ( ) ; encl != null ; encl = encl . owner != null ? encl . owner . enclClass ( ) : null ) { if ( sym . isMemberOf ( encl , state . getTypes ( ) ) ) { return true ; } } return false ; } | Is sym a non - static member of an enclosing class of currentClass? |
32,030 | private static double computeCost ( int [ ] assignments , double [ ] [ ] costMatrix , double [ ] sourceTermDeletionCosts , double [ ] targetTermDeletionCosts ) { double totalCost = DoubleStream . of ( targetTermDeletionCosts ) . sum ( ) ; for ( int sourceTermIndex = 0 ; sourceTermIndex < assignments . length ; sourceTermIndex ++ ) { int targetTermIndex = assignments [ sourceTermIndex ] ; if ( targetTermIndex == - 1 ) { totalCost += sourceTermDeletionCosts [ sourceTermIndex ] ; } else { totalCost += costMatrix [ sourceTermIndex ] [ targetTermIndex ] ; totalCost -= targetTermDeletionCosts [ targetTermIndex ] ; } } return totalCost ; } | Compute the total cost of this assignment including the costs of unassigned source and target terms . |
32,031 | private static boolean floatingPointArgument ( ExpressionTree tree ) { if ( tree . getKind ( ) == Kind . UNARY_PLUS || tree . getKind ( ) == Kind . UNARY_MINUS ) { tree = ( ( UnaryTree ) tree ) . getExpression ( ) ; } return tree . getKind ( ) == Kind . DOUBLE_LITERAL || tree . getKind ( ) == Kind . FLOAT_LITERAL ; } | accept multiple unary prefixes . |
32,032 | private static < T , R > Choice < State < R > > chooseSubtrees ( State < ? > state , Function < State < ? > , Choice < ? extends State < ? extends T > > > choice1 , Function < T , R > finalizer ) { return choice1 . apply ( state ) . transform ( s -> s . withResult ( finalizer . apply ( s . result ( ) ) ) ) ; } | This method and its overloads take |
32,033 | public static Optional < Attribute > getValue ( Attribute . Compound attribute , String name ) { return attribute . getElementValues ( ) . entrySet ( ) . stream ( ) . filter ( e -> e . getKey ( ) . getSimpleName ( ) . contentEquals ( name ) ) . map ( Map . Entry :: getValue ) . findFirst ( ) ; } | Returns the value of the annotation element - value pair with the given name if it is not explicitly set . |
32,034 | public static Optional < Integer > asIntegerValue ( Attribute a ) { class Visitor extends SimpleAnnotationValueVisitor8 < Integer , Void > { public Integer visitInt ( int i , Void unused ) { return i ; } } return Optional . ofNullable ( a . accept ( new Visitor ( ) , null ) ) ; } | Converts the given attribute to an integer value . |
32,035 | public static Optional < String > asStringValue ( Attribute a ) { class Visitor extends SimpleAnnotationValueVisitor8 < String , Void > { public String visitString ( String s , Void unused ) { return s ; } } return Optional . ofNullable ( a . accept ( new Visitor ( ) , null ) ) ; } | Converts the given attribute to an string value . |
32,036 | public static < T extends Enum < T > > Optional < T > asEnumValue ( Class < T > clazz , Attribute a ) { class Visitor extends SimpleAnnotationValueVisitor8 < T , Void > { public T visitEnumConstant ( VariableElement c , Void unused ) { return Enum . valueOf ( clazz , c . getSimpleName ( ) . toString ( ) ) ; } } return Optional . ofNullable ( a . accept ( new Visitor ( ) , null ) ) ; } | Converts the given attribute to an enum value . |
32,037 | private static Fix replaceTargetAnnotation ( Target annotation , AnnotationTree targetAnnotationTree ) { Set < ElementType > types = EnumSet . copyOf ( REQUIRED_ELEMENT_TYPES ) ; types . addAll ( Arrays . asList ( annotation . value ( ) ) ) ; return replaceTargetAnnotation ( targetAnnotationTree , types ) ; } | Rewrite the annotation with static imports adding TYPE and METHOD to the |
32,038 | private boolean shouldExcludeSourceFile ( CompilationUnitTree tree ) { Pattern excludedPattern = errorProneOptions . getExcludedPattern ( ) ; return excludedPattern != null && excludedPattern . matcher ( ASTHelpers . getFileName ( tree ) ) . matches ( ) ; } | Returns true if the given source file should be excluded from analysis . |
32,039 | private boolean finishedCompilation ( CompilationUnitTree tree ) { OUTER : for ( Tree decl : tree . getTypeDecls ( ) ) { switch ( decl . getKind ( ) ) { case EMPTY_STATEMENT : continue OUTER ; case IMPORT : continue OUTER ; default : break ; } if ( ! seen . contains ( decl ) ) { return false ; } } return true ; } | Returns true if all declarations inside the given compilation unit have been visited . |
32,040 | Set < UVariableDecl > requiredParameters ( ) { return Maps . filterValues ( annotatedParameters ( ) , ( ImmutableClassToInstanceMap < Annotation > annotations ) -> ! annotations . containsKey ( MayOptionallyUse . class ) ) . keySet ( ) ; } | Parameters which must be referenced in any tree matched to this placeholder . |
32,041 | public static boolean hasJUnitAnnotation ( MethodTree tree , VisitorState state ) { MethodSymbol methodSym = getSymbol ( tree ) ; if ( methodSym == null ) { return false ; } if ( hasJUnitAttr ( methodSym ) ) { return true ; } return findSuperMethods ( methodSym , state . getTypes ( ) ) . stream ( ) . anyMatch ( JUnitMatchers :: hasJUnitAttr ) ; } | Checks if a method or any overridden method is annotated with any annotation from the org . junit package . |
32,042 | private static boolean hasJUnitAttr ( MethodSymbol methodSym ) { return methodSym . getRawAttributes ( ) . stream ( ) . anyMatch ( attr -> attr . type . tsym . getQualifiedName ( ) . toString ( ) . startsWith ( "org.junit." ) ) ; } | Checks if a method symbol has any attribute from the org . junit package . |
32,043 | private Symbol resolveType ( String name , SearchSuperTypes searchSuperTypes ) { Symbol type = null ; if ( searchSuperTypes == SearchSuperTypes . YES ) { type = getSuperType ( enclosingClass , name ) ; } if ( enclosingClass . getSimpleName ( ) . contentEquals ( name ) ) { type = enclosingClass ; } if ( type == null ) { type = getLexicallyEnclosing ( enclosingClass , name ) ; } if ( type == null ) { type = attribIdent ( name ) ; } checkGuardedBy ( ! ( type instanceof Symbol . PackageSymbol ) , "All we could find for '%s' was a package symbol." , name ) ; return type ; } | Resolves a simple name as a type . Considers super classes lexically enclosing classes and then arbitrary types available in the current environment . |
32,044 | private static boolean isEnumIdentifier ( Parameter parameter ) { switch ( parameter . kind ( ) ) { case IDENTIFIER : case MEMBER_SELECT : break ; default : return false ; } TypeSymbol typeSymbol = parameter . type ( ) . tsym ; if ( typeSymbol != null ) { return typeSymbol . getKind ( ) == ElementKind . ENUM ; } return false ; } | Returns true if this parameter is an enum identifier |
32,045 | private static MethodTree enclosingMethod ( VisitorState state ) { for ( Tree node : state . getPath ( ) . getParentPath ( ) ) { switch ( node . getKind ( ) ) { case LAMBDA_EXPRESSION : case NEW_CLASS : return null ; case METHOD : return ( MethodTree ) node ; default : break ; } } return null ; } | Returns the enclosing method of the given visitor state . Returns null if the state is within a lambda expression or anonymous class . |
32,046 | private String buildMessage ( Set < String > unhandled ) { StringBuilder message = new StringBuilder ( "Non-exhaustive switch; either add a default or handle the remaining cases: " ) ; int numberToShow = unhandled . size ( ) > MAX_CASES_TO_PRINT ? 3 : unhandled . size ( ) ; message . append ( unhandled . stream ( ) . limit ( numberToShow ) . collect ( Collectors . joining ( ", " ) ) ) ; if ( numberToShow < unhandled . size ( ) ) { message . append ( String . format ( ", and %d others" , unhandled . size ( ) - numberToShow ) ) ; } return message . toString ( ) ; } | Build the diagnostic message . |
32,047 | public static SuggestedFix replace ( int startPos , int endPos , String replaceWith ) { return builder ( ) . replace ( startPos , endPos , replaceWith ) . build ( ) ; } | Replace the characters from startPos inclusive until endPos exclusive with the given string . |
32,048 | public boolean isAcceptableChange ( Changes changes , Tree node , MethodSymbol symbol , VisitorState state ) { ImmutableList < Commented < ExpressionTree > > comments = findCommentsForArguments ( node , state ) ; return changes . changedPairs ( ) . stream ( ) . noneMatch ( p -> { MatchType match = NamedParameterComment . match ( comments . get ( p . formal ( ) . index ( ) ) , p . formal ( ) . name ( ) ) . matchType ( ) ; return match == MatchType . EXACT_MATCH || match == MatchType . APPROXIMATE_MATCH ; } ) ; } | Return true if there are no comments on the original actual parameter of a change which match the name of the formal parameter . |
32,049 | public Description matchMethodInvocation ( MethodInvocationTree t , VisitorState state ) { if ( IS_COLLECTION_MODIFIED_WITH_ITSELF . matches ( t , state ) ) { return describe ( t , state ) ; } return Description . NO_MATCH ; } | Matches calls to addAll containsAll removeAll and retainAll on itself |
32,050 | private List < Type > getArgumentTypesWithoutMessage ( MethodInvocationTree methodInvocationTree , VisitorState state ) { List < Type > argumentTypes = new ArrayList < > ( ) ; for ( ExpressionTree argument : methodInvocationTree . getArguments ( ) ) { JCTree tree = ( JCTree ) argument ; argumentTypes . add ( tree . type ) ; } removeMessageArgumentIfPresent ( state , argumentTypes ) ; return argumentTypes ; } | Gets the argument types excluding the message argument if present . |
32,051 | private void removeMessageArgumentIfPresent ( VisitorState state , List < Type > argumentTypes ) { if ( argumentTypes . size ( ) == 2 ) { return ; } Types types = state . getTypes ( ) ; Type firstType = argumentTypes . get ( 0 ) ; if ( types . isSameType ( firstType , state . getSymtab ( ) . stringType ) ) { argumentTypes . remove ( 0 ) ; } } | Removes the message argument if it is present . |
32,052 | private boolean canBeConvertedToJUnit4 ( VisitorState state , List < Type > argumentTypes ) { if ( argumentTypes . size ( ) > 2 ) { return true ; } Type firstType = argumentTypes . get ( 0 ) ; Type secondType = argumentTypes . get ( 1 ) ; if ( ! isFloatingPoint ( state , firstType ) && ! isFloatingPoint ( state , secondType ) ) { return true ; } if ( ! isNumeric ( state , firstType ) || ! isNumeric ( state , secondType ) ) { return true ; } if ( ! firstType . isPrimitive ( ) && ! secondType . isPrimitive ( ) ) { return true ; } return false ; } | Determines if the invocation can be safely converted to JUnit 4 based on its argument types . |
32,053 | private boolean isFloatingPoint ( VisitorState state , Type type ) { Type trueType = unboxedTypeOrType ( state , type ) ; return ( trueType . getKind ( ) == TypeKind . DOUBLE ) || ( trueType . getKind ( ) == TypeKind . FLOAT ) ; } | Determines if the type is a floating - point type including reference types . |
32,054 | private boolean isNumeric ( VisitorState state , Type type ) { Type trueType = unboxedTypeOrType ( state , type ) ; return trueType . isNumeric ( ) ; } | Determines if the type is a numeric type including reference types . |
32,055 | private Type unboxedTypeOrType ( VisitorState state , Type type ) { Types types = state . getTypes ( ) ; return types . unboxedTypeOrType ( type ) ; } | Gets the unboxed type or the original type if it is not unboxable . |
32,056 | private Fix addDeltaArgument ( MethodInvocationTree methodInvocationTree , VisitorState state , List < Type > argumentTypes ) { int insertionIndex = getDeltaInsertionIndex ( methodInvocationTree , state ) ; String deltaArgument = getDeltaArgument ( state , argumentTypes ) ; return SuggestedFix . replace ( insertionIndex , insertionIndex , deltaArgument ) ; } | Creates the fix to add a delta argument . |
32,057 | private int getDeltaInsertionIndex ( MethodInvocationTree methodInvocationTree , VisitorState state ) { JCTree lastArgument = ( JCTree ) Iterables . getLast ( methodInvocationTree . getArguments ( ) ) ; return state . getEndPosition ( lastArgument ) ; } | Gets the index of where to insert the delta argument . |
32,058 | private String getDeltaArgument ( VisitorState state , List < Type > argumentTypes ) { Type firstType = argumentTypes . get ( 0 ) ; Type secondType = argumentTypes . get ( 1 ) ; boolean doublePrecisionUsed = isDouble ( state , firstType ) || isDouble ( state , secondType ) ; return doublePrecisionUsed ? ", 0.0" : ", 0.0f" ; } | Gets the text for the delta argument to be added . |
32,059 | private boolean isDouble ( VisitorState state , Type type ) { Type trueType = unboxedTypeOrType ( state , type ) ; return trueType . getKind ( ) == TypeKind . DOUBLE ; } | Determines if the type is a double including reference types . |
32,060 | static Replacement handleNonDaylightSavingsZone ( boolean inJodaTimeContext , String daylightSavingsZone , String fixedOffset ) { if ( inJodaTimeContext ) { String newDescription = SUMMARY + "\n\n" + observesDaylightSavingsMessage ( "DateTimeZone" , daylightSavingsZone , fixedOffset ) ; return new Replacement ( newDescription , ImmutableList . of ( daylightSavingsZone , fixedOffset ) ) ; } else { String newDescription = SUMMARY + "\n\n" + "This TimeZone will not observe daylight savings. " + "If this is intended, use " + fixedOffset + " instead; to observe daylight savings, use " + daylightSavingsZone + "." ; return new Replacement ( newDescription , ImmutableList . of ( fixedOffset , daylightSavingsZone ) ) ; } } | How we handle it depends upon whether we are in a JodaTime context or not . |
32,061 | private Fix longFix ( ExpressionTree expr , VisitorState state ) { BinaryTree binExpr = null ; while ( expr instanceof BinaryTree ) { binExpr = ( BinaryTree ) expr ; expr = binExpr . getLeftOperand ( ) ; } if ( ! ( expr instanceof LiteralTree ) || expr . getKind ( ) != Kind . INT_LITERAL ) { return null ; } Type intType = state . getSymtab ( ) . intType ; if ( ! isSameType ( getType ( binExpr ) , intType , state ) ) { return null ; } SuggestedFix . Builder fix = SuggestedFix . builder ( ) . postfixWith ( expr , "L" ) ; Tree parent = state . getPath ( ) . getParentPath ( ) . getLeaf ( ) ; if ( parent instanceof VariableTree && isSameType ( getType ( parent ) , intType , state ) ) { fix . replace ( ( ( VariableTree ) parent ) . getType ( ) , "long" ) ; } return fix . build ( ) ; } | If the left operand of an int binary expression is an int literal suggest making it a long . |
32,062 | public static < T extends Tree > Matcher < T > anything ( ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { return true ; } } ; } | A matcher that matches any AST node . |
32,063 | public static < T extends Tree > Matcher < T > nothing ( ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { return false ; } } ; } | A matcher that matches no AST node . |
32,064 | public static < T extends Tree > Matcher < T > not ( final Matcher < T > matcher ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { return ! matcher . matches ( t , state ) ; } } ; } | Matches an AST node iff it does not match the given matcher . |
32,065 | public static < T extends Tree > Matcher < T > allOf ( final Matcher < ? super T > ... matchers ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { for ( Matcher < ? super T > matcher : matchers ) { if ( ! matcher . matches ( t , state ) ) { return false ; } } return true ; } } ; } | Compose several matchers together such that the composite matches an AST node iff all the given matchers do . |
32,066 | public static < T extends Tree > Matcher < T > anyOf ( final Iterable < ? extends Matcher < ? super T > > matchers ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { for ( Matcher < ? super T > matcher : matchers ) { if ( matcher . matches ( t , state ) ) { return true ; } } return false ; } } ; } | Compose several matchers together such that the composite matches an AST node if any of the given matchers do . |
32,067 | public static < T extends Tree > Matcher < T > isInstance ( final java . lang . Class < ? > klass ) { return new Matcher < T > ( ) { public boolean matches ( T t , VisitorState state ) { return klass . isInstance ( t ) ; } } ; } | Matches if an AST node is an instance of the given class . |
32,068 | public static < T extends Tree > Matcher < T > kindIs ( final Kind kind ) { return new Matcher < T > ( ) { public boolean matches ( T tree , VisitorState state ) { return tree . getKind ( ) == kind ; } } ; } | Matches an AST node of a given kind for example an Annotation or a switch block . |
32,069 | public static < T extends Tree > Matcher < T > isSame ( final Tree t ) { return new Matcher < T > ( ) { public boolean matches ( T tree , VisitorState state ) { return tree == t ; } } ; } | Matches an AST node which is the same object reference as the given node . |
32,070 | public static Matcher < ExpressionTree > isInstanceField ( ) { return new Matcher < ExpressionTree > ( ) { public boolean matches ( ExpressionTree expressionTree , VisitorState state ) { Symbol symbol = ASTHelpers . getSymbol ( expressionTree ) ; return symbol != null && symbol . getKind ( ) == ElementKind . FIELD && ! symbol . isStatic ( ) ; } } ; } | Matches an AST node that represents a non - static field . |
32,071 | public static Matcher < ExpressionTree > isVariable ( ) { return new Matcher < ExpressionTree > ( ) { public boolean matches ( ExpressionTree expressionTree , VisitorState state ) { Symbol symbol = ASTHelpers . getSymbol ( expressionTree ) ; if ( symbol == null ) { return false ; } return symbol . getKind ( ) == ElementKind . LOCAL_VARIABLE || symbol . getKind ( ) == ElementKind . PARAMETER ; } } ; } | Matches an AST node that represents a local variable or parameter . |
32,072 | public static CompoundAssignment compoundAssignment ( Kind operator , Matcher < ExpressionTree > leftOperandMatcher , Matcher < ExpressionTree > rightOperandMatcher ) { Set < Kind > operators = new HashSet < > ( 1 ) ; operators . add ( operator ) ; return new CompoundAssignment ( operators , leftOperandMatcher , rightOperandMatcher ) ; } | Matches a compound assignment operator AST node which matches a given left - operand matcher a given right - operand matcher and a specific compound assignment operator . |
32,073 | public static CompoundAssignment compoundAssignment ( Set < Kind > operators , Matcher < ExpressionTree > receiverMatcher , Matcher < ExpressionTree > expressionMatcher ) { return new CompoundAssignment ( operators , receiverMatcher , expressionMatcher ) ; } | Matches a compound assignment operator AST node which matches a given left - operand matcher a given right - operand matcher and is one of a set of compound assignment operators . Does not match compound assignment operators . |
32,074 | public static < T extends Tree > MultiMatcher < T , AnnotationTree > annotations ( MatchType matchType , Matcher < AnnotationTree > annotationMatcher ) { return new AnnotationMatcher < > ( matchType , annotationMatcher ) ; } | Matches if the given annotation matcher matches all of or any of the annotations on this tree node . |
32,075 | public static Matcher < ExpressionTree > methodInvocation ( Matcher < ExpressionTree > methodSelectMatcher , MatchType matchType , Matcher < ExpressionTree > methodArgumentMatcher ) { return new MethodInvocation ( methodSelectMatcher , matchType , methodArgumentMatcher ) ; } | Matches an AST node if it is a method invocation and the given matchers match . |
32,076 | public static < T extends Tree > Matcher < T > isSameType ( Supplier < Type > type ) { return new IsSameType < > ( type ) ; } | Matches an AST node if it has the same erased type as the given type . |
32,077 | public static < T extends Tree > Matcher < T > isSameType ( Class < ? > clazz ) { return new IsSameType < > ( typeFromClass ( clazz ) ) ; } | Matches an AST node if it has the same erased type as the given class . |
32,078 | public static < T extends Tree > Matcher < T > isArrayType ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree t , VisitorState state ) { Type type = getType ( t ) ; return type != null && state . getTypes ( ) . isArray ( type ) ; } } ; } | Matches an AST node if its type is an array type . |
32,079 | public static < T extends Tree > Matcher < T > isPrimitiveArrayType ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree t , VisitorState state ) { Type type = getType ( t ) ; return type != null && state . getTypes ( ) . isArray ( type ) && state . getTypes ( ) . elemtype ( type ) . isPrimitive ( ) ; } } ; } | Matches an AST node if its type is a primitive array type . |
32,080 | public static < T extends Tree > Matcher < T > isPrimitiveType ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree t , VisitorState state ) { Type type = getType ( t ) ; return type != null && type . isPrimitive ( ) ; } } ; } | Matches an AST node if its type is a primitive type . |
32,081 | public static < T extends Tree > Matcher < T > isPrimitiveOrBoxedPrimitiveType ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree t , VisitorState state ) { Type type = getType ( t ) ; return type != null && state . getTypes ( ) . unboxedTypeOrType ( type ) . isPrimitive ( ) ; } } ; } | Matches an AST node if its type is a primitive type or a boxed version of a primitive type . |
32,082 | public static < T extends Tree > Enclosing . Block < T > enclosingBlock ( Matcher < BlockTree > matcher ) { return new Enclosing . Block < > ( matcher ) ; } | Matches an AST node which is enclosed by a block node that matches the given matcher . |
32,083 | public static < T extends Tree > Enclosing . Class < T > enclosingClass ( Matcher < ClassTree > matcher ) { return new Enclosing . Class < > ( matcher ) ; } | Matches an AST node which is enclosed by a class node that matches the given matcher . |
32,084 | public static < T extends Tree > Enclosing . Method < T > enclosingMethod ( Matcher < MethodTree > matcher ) { return new Enclosing . Method < > ( matcher ) ; } | Matches an AST node which is enclosed by a method node that matches the given matcher . |
32,085 | public static < T extends Tree > Matcher < Tree > enclosingNode ( final Matcher < T > matcher ) { return new Matcher < Tree > ( ) { @ SuppressWarnings ( "unchecked" ) public boolean matches ( Tree t , VisitorState state ) { TreePath path = state . getPath ( ) . getParentPath ( ) ; while ( path != null ) { Tree node = path . getLeaf ( ) ; state = state . withPath ( path ) ; if ( matcher . matches ( ( T ) node , state ) ) { return true ; } path = path . getParentPath ( ) ; } return false ; } } ; } | Matches an AST node that is enclosed by some node that matches the given matcher . |
32,086 | public static < T extends StatementTree > NextStatement < T > nextStatement ( Matcher < StatementTree > matcher ) { return new NextStatement < > ( matcher ) ; } | Matches a statement AST node if the following statement in the enclosing block matches the given matcher . |
32,087 | public static < T extends StatementTree > Matcher < T > previousStatement ( Matcher < StatementTree > matcher ) { return ( T statement , VisitorState state ) -> { BlockTree block = state . findEnclosing ( BlockTree . class ) ; if ( block == null ) { return false ; } List < ? extends StatementTree > statements = block . getStatements ( ) ; int idx = statements . indexOf ( statement ) ; if ( idx <= 0 ) { return false ; } return matcher . matches ( statements . get ( idx - 1 ) , state ) ; } ; } | Matches a statement AST node if the previous statement in the enclosing block matches the given matcher . |
32,088 | public static Matcher < ExpressionTree > nonNullLiteral ( ) { return new Matcher < ExpressionTree > ( ) { public boolean matches ( ExpressionTree tree , VisitorState state ) { switch ( tree . getKind ( ) ) { case MEMBER_SELECT : return ( ( MemberSelectTree ) tree ) . getIdentifier ( ) . contentEquals ( "class" ) ; case INT_LITERAL : case LONG_LITERAL : case FLOAT_LITERAL : case DOUBLE_LITERAL : case BOOLEAN_LITERAL : case CHAR_LITERAL : case STRING_LITERAL : return true ; default : return false ; } } } ; } | Matches an AST node if it is a literal other than null . |
32,089 | public static Matcher < ExpressionTree > methodReturnsNonNull ( ) { return anyOf ( instanceMethod ( ) . onDescendantOf ( "java.lang.Object" ) . named ( "toString" ) , instanceMethod ( ) . onExactClass ( "java.lang.String" ) , staticMethod ( ) . onClass ( "java.lang.String" ) , instanceMethod ( ) . onExactClass ( "java.util.StringTokenizer" ) . named ( "nextToken" ) ) ; } | Matches a whitelisted method invocation that is known to never return null |
32,090 | public static Matcher < MethodTree > methodIsNamed ( final String methodName ) { return new Matcher < MethodTree > ( ) { public boolean matches ( MethodTree methodTree , VisitorState state ) { return methodTree . getName ( ) . contentEquals ( methodName ) ; } } ; } | Match a method declaration with a specific name . |
32,091 | public static Matcher < MethodTree > methodNameStartsWith ( final String prefix ) { return new Matcher < MethodTree > ( ) { public boolean matches ( MethodTree methodTree , VisitorState state ) { return methodTree . getName ( ) . toString ( ) . startsWith ( prefix ) ; } } ; } | Match a method declaration that starts with a given string . |
32,092 | public static Matcher < MethodTree > methodWithClassAndName ( final String className , final String methodName ) { return new Matcher < MethodTree > ( ) { public boolean matches ( MethodTree methodTree , VisitorState state ) { return ASTHelpers . getSymbol ( methodTree ) . getEnclosingElement ( ) . getQualifiedName ( ) . contentEquals ( className ) && methodTree . getName ( ) . contentEquals ( methodName ) ; } } ; } | Match a method declaration with a specific enclosing class and method name . |
32,093 | public static Matcher < MethodTree > constructorOfClass ( final String className ) { return new Matcher < MethodTree > ( ) { public boolean matches ( MethodTree methodTree , VisitorState state ) { Symbol symbol = ASTHelpers . getSymbol ( methodTree ) ; return symbol . getEnclosingElement ( ) . getQualifiedName ( ) . contentEquals ( className ) && symbol . isConstructor ( ) ; } } ; } | Matches a constructor declaration in a specific enclosing class . |
32,094 | public static Matcher < ClassTree > hasMethod ( final Matcher < MethodTree > methodMatcher ) { return new Matcher < ClassTree > ( ) { public boolean matches ( ClassTree t , VisitorState state ) { for ( Tree member : t . getMembers ( ) ) { if ( member instanceof MethodTree ) { if ( methodMatcher . matches ( ( MethodTree ) member , state ) ) { return true ; } } } return false ; } } ; } | Matches a class in which at least one method matches the given methodMatcher . |
32,095 | public static Matcher < VariableTree > variableType ( final Matcher < Tree > treeMatcher ) { return new Matcher < VariableTree > ( ) { public boolean matches ( VariableTree variableTree , VisitorState state ) { return treeMatcher . matches ( variableTree . getType ( ) , state ) ; } } ; } | Matches on the type of a VariableTree AST node . |
32,096 | public static Matcher < VariableTree > variableInitializer ( final Matcher < ExpressionTree > expressionTreeMatcher ) { return new Matcher < VariableTree > ( ) { public boolean matches ( VariableTree variableTree , VisitorState state ) { ExpressionTree initializer = variableTree . getInitializer ( ) ; return initializer == null ? false : expressionTreeMatcher . matches ( initializer , state ) ; } } ; } | Matches on the initializer of a VariableTree AST node . |
32,097 | public static Matcher < ClassTree > nestingKind ( final NestingKind kind ) { return new Matcher < ClassTree > ( ) { public boolean matches ( ClassTree classTree , VisitorState state ) { ClassSymbol sym = ASTHelpers . getSymbol ( classTree ) ; return sym . getNestingKind ( ) == kind ; } } ; } | Matches an class based on whether it is nested in another class or method . |
32,098 | public static < T extends Tree > Matcher < T > isStatic ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree tree , VisitorState state ) { Symbol sym = ASTHelpers . getSymbol ( tree ) ; return sym != null && sym . isStatic ( ) ; } } ; } | Matches an AST node that is static . |
32,099 | public static < T extends Tree > Matcher < T > isTransient ( ) { return new Matcher < T > ( ) { public boolean matches ( Tree tree , VisitorState state ) { Symbol sym = ASTHelpers . getSymbol ( tree ) ; return sym . getModifiers ( ) . contains ( Modifier . TRANSIENT ) ; } } ; } | Matches an AST node that is transient . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.