@Override public Void visitNewClass(NewClassTree node, AnnotatedTypeMirror p) { super.visitNewClass(node, p); if (useFbc) { boolean allCommitted = true; Type type = ((JCTree) node).type; for (ExpressionTree a : node.getArguments()) { final AnnotatedTypeMirror t = getAnnotatedType(a); allCommitted &= (isCommitted(t) || isFbcBottom(t)); } if (!allCommitted) { p.replaceAnnotation(createFreeAnnotation(type)); } } return null; }
private static List<? extends TypeMirror> computeNewClass( Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { NewClassTree nct = (NewClassTree) parent.getLeaf(); boolean errorInRealArguments = false; for (Tree param : nct.getArguments()) { errorInRealArguments |= param == error; } if (errorInRealArguments) { TypeMirror[] proposedType = new TypeMirror[1]; int[] proposedIndex = new int[1]; ExecutableElement ee = org.netbeans.modules.editor.java.Utilities.fuzzyResolveMethodInvocation( info, parent, proposedType, proposedIndex); if (ee == null) { // cannot be resolved return null; } types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); return Collections.singletonList(proposedType[0]); } Tree id = nct.getIdentifier(); if (id.getKind() == Kind.PARAMETERIZED_TYPE) { id = ((ParameterizedTypeTree) id).getType(); } if (id == error) { return resolveType( EnumSet.noneOf(ElementKind.class), info, parent.getParentPath(), nct, offset, null, null); } return null; }
@Override public Void visitNewClass(NewClassTree tree, AnnotatedTypeMirror type) { boolean wrapperClass = TypesUtils.isBoxedPrimitive(type.getUnderlyingType()) || TypesUtils.isDeclaredOfName(type.getUnderlyingType(), "java.lang.String"); if (wrapperClass || (isUnderlyingTypeAValue(type) && methodIsStaticallyExecutable(TreeUtils.elementFromUse(tree)))) { // get arugment values List<? extends ExpressionTree> arguments = tree.getArguments(); ArrayList<List<?>> argValues; if (arguments.size() > 0) { argValues = new ArrayList<List<?>>(); for (ExpressionTree argument : arguments) { AnnotatedTypeMirror argType = getAnnotatedType(argument); List<?> values = getValues(argType, argType.getUnderlyingType()); if (values.isEmpty()) { // values aren't known, so don't try to evaluate the // method return null; } argValues.add(values); } } else { argValues = null; } // Evaluate method List<?> returnValues = evalutator.evaluteConstrutorCall(argValues, tree, type.getUnderlyingType()); AnnotationMirror returnType = resultAnnotationHandler(type.getUnderlyingType(), returnValues, tree); type.replaceAnnotation(returnType); } return null; }