Skip to content

Commit

Permalink
Temporary fix for typetools#3224
Browse files Browse the repository at this point in the history
  • Loading branch information
PRITI1999 committed Jul 25, 2020
1 parent 3723b51 commit 32a728f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Expand Up @@ -2,6 +2,7 @@

import com.sun.source.tree.AnnotationTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
Expand Down Expand Up @@ -76,6 +77,18 @@ protected void commonAssignmentCheck(
getTypeFactory().createIntRangeAnnotation(Range.CHAR_EVERYTHING));
}

if (valueTree.getKind() == Kind.METHOD_INVOCATION
&& TreeUtils.isArrayscopyOfMethodInvocation((MethodInvocationTree) valueTree)
&& valueType.getKind() == TypeKind.ARRAY) {
List<? extends ExpressionTree> args = ((MethodInvocationTree) valueTree).getArguments();
AnnotatedTypeMirror arrType = atypeFactory.getAnnotatedType(args.get(0));
if (args.size() == 2) {
if (TreeUtils.isArrayLengthAccess(args.get(1))) {
valueType = arrType;
}
}
}

super.commonAssignmentCheck(varType, valueType, valueTree, errorKey, extraArgs);
}

Expand Down
Expand Up @@ -1273,6 +1273,27 @@ public static boolean isAnonymousConstructor(final MethodTree method) {
return false;
}

/**
* Determines if the tree is a call to Arrays.copyOf()
*
* @param tree tree to check
* @return true if the given tree is a call to Arrays.copyOf() method
*/
public static boolean isArrayscopyOfMethodInvocation(MethodInvocationTree tree) {
if (tree.getMethodSelect().getKind() != Kind.MEMBER_SELECT) {
return false;
}

MemberSelectTree memberSelectTree = (MemberSelectTree) (tree.getMethodSelect());

if (memberSelectTree.getExpression().toString().equals("Arrays")
&& getMethodName(memberSelectTree).equals("copyOf")) {
return true;
}

return false;
}

/**
* Converts the given AnnotationTrees to AnnotationMirrors.
*
Expand Down

0 comments on commit 32a728f

Please sign in to comment.