/** * Returns the ClassTree, if any, where the specified symbol has been declared. * If the symbol has been declared more that once, returns any of these declarations. */ private static Optional<ClassTree> getDeclarationTree(Symbol symbol) { Optional<Usage> tree = symbol.usages().stream() .filter(Usage::isDeclaration) .findFirst(); if (tree.isPresent()) { IdentifierTree id = tree.get().identifierTree(); Tree parent = id.parent(); if (parent.is(Kind.CLASS_DECLARATION, Kind.CLASS_EXPRESSION)) { return Optional.of((ClassTree) parent); } } return Optional.empty(); }
private static boolean isWriteUsage(Usage usage) { if (usage.isWrite()) { return true; } return usage.identifierTree().parent().is(Tree.Kind.DOT_MEMBER_EXPRESSION, Tree.Kind.BRACKET_MEMBER_EXPRESSION, Tree.Kind.CALL_EXPRESSION); }
private static Set<Usage> getExcludedProperties(Usage usage) { Set<Usage> excludedProperties = new HashSet<>(); Tree parent = usage.identifierTree().parent(); if (parent.is(Kind.OBJECT_BINDING_PATTERN) && hasUsedRestElement((ObjectBindingPatternTree) parent)) { ((ObjectBindingPatternTree) parent).elements().stream() .filter(element -> element.is(Kind.BINDING_IDENTIFIER)) .forEach(element -> ((IdentifierTree) element).symbolUsage().ifPresent(excludedProperties::add)); } return excludedProperties; }
private static boolean initializedToBasicValue(Usage usage) { if (usage.isDeclaration()) { Tree parent = usage.identifierTree().parent(); if (parent.is(Kind.INITIALIZED_BINDING_ELEMENT)) { ExpressionTree expression = ((InitializedBindingElementTree) parent).right(); return isBasicValue(expression); } } return false; }