private static boolean isProtoRepeatedFieldCountMethod(ExpressionTree tree, VisitorState state) { // Instance method, on proto class, named `get<Field>Count`. if (!PROTO_METHOD_NAMED_GET_COUNT.matches(tree, state)) { return false; } // Make sure it's the count method for a repeated field, not the get method for a non-repeated // field named <something>_count, by checking for other methods on the repeated field. MethodSymbol methodCallSym = getSymbol((MethodInvocationTree) tree); if (methodCallSym == null) { return false; } Scope protoClassMembers = methodCallSym.owner.members(); java.util.regex.Matcher getCountRegexMatcher = PROTO_COUNT_METHOD_PATTERN.matcher(methodCallSym.getSimpleName().toString()); if (!getCountRegexMatcher.matches()) { return false; } String fieldName = getCountRegexMatcher.group(1); return protoClassMembers.findFirst(state.getName("get" + fieldName + "List")) != null; }
@Override public Description matchCompilationUnit(CompilationUnitTree tree, final VisitorState state) { Symbol mockitoSym = state.getSymbolFromString(MOCKITO_CLASS); if (mockitoSym == null) { // fast path if mockito isn't being used return Description.NO_MATCH; } // collect variable symbols for standard Answer constants that don't support generics final Set<Symbol> badAnswers = new LinkedHashSet<>(); for (Symbol member : mockitoSym.members().getSymbols(LookupKind.NON_RECURSIVE)) { if (member.getKind() != ElementKind.FIELD) { continue; } if (BAD_ANSWER_STRATEGIES.contains(member.getSimpleName().toString())) { badAnswers.add(member); } } // collect mocks that are initialized in this compilation unit using a bad answer strategy final Set<VarSymbol> mockVariables = MockInitializationScanner.scan(state, badAnswers); // check for when(...) calls on mocks using a bad answer strategy new WhenNeedsCastScanner(mockVariables, state).scan(state.getPath(), null); // errors are reported in WhenNeedsCastScanner return Description.NO_MATCH; }
public Scope members() { return other.members(); } public boolean isInner() { return other.isInner(); }
public Scope members() { return other.members(); } public boolean isInner() { return other.isInner(); }
public Scope members() { return other.members(); } public boolean isInner() { return other.isInner(); }
public Scope members() { return other.members(); } public boolean isInner() { return other.isInner(); }
/** Import given class. * @param pos Position to be used for error reporting. * @param tsym The class to be imported. * @param env The environment containing the named import * scope to add to. */ private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { if (tsym.kind == TYP && chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); }
/** Import given class. * @param pos Position to be used for error reporting. * @param tsym The class to be imported. * @param env The environment containing the named import * scope to add to. */ private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { if (tsym.kind == TYP && chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); }
/** Import given class. * @param pos Position to be used for error reporting. * @param tsym The class to be imported. * @param env The environment containing the named import * scope to add to. */ private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { if (tsym.kind == TYP && chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); }
/** Import given class. * @param pos Position to be used for error reporting. * @param tsym The class to be imported. * @param env The environment containing the named import * scope to add to. */ private void importNamed(DiagnosticPosition pos, Symbol tsym, Env<AttrContext> env) { if (tsym.kind == TYP && chk.checkUniqueImport(pos, tsym, env.toplevel.namedImportScope)) env.toplevel.namedImportScope.enter(tsym, tsym.owner.members()); }
private void validateDefault(Symbol container, Symbol contained, DiagnosticPosition pos) { // validate that all other elements of containing type has defaults Scope scope = container.members(); for(Symbol elm : scope.getElements()) { if (elm.name != names.value && elm.kind == Kinds.MTH && ((MethodSymbol)elm).defaultValue == null) { log.error(pos, "invalid.repeatable.annotation.elem.nondefault", container, elm); } } }
private void validateDefault(Symbol container, DiagnosticPosition pos) { // validate that all other elements of containing type has defaults Scope scope = container.members(); for(Symbol elm : scope.getElements()) { if (elm.name != names.value && elm.kind == Kinds.MTH && ((MethodSymbol)elm).defaultValue == null) { log.error(pos, "invalid.repeatable.annotation.elem.nondefault", container, elm); } } }
/** Create a new toplevel or member class symbol with given name * and owner and enter in `classes' unless already there. */ public ClassSymbol enterClass(Name name, TypeSymbol owner) { Name flatname = TypeSymbol.formFlatName(name, owner); ClassSymbol c = classes.get(flatname); if (c == null) { c = defineClass(name, owner); classes.put(flatname, c); } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) { // reassign fields of classes that might have been loaded with // their flat names. c.owner.members().remove(c); c.name = name; c.owner = owner; c.fullname = ClassSymbol.formFullName(name, owner); } return c; }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }
/** * Tries to complete lexically enclosing classes if c looks like a * nested class. This is similar to completeOwners but handles * the situation when a nested class is accessed directly as it is * possible with the Tree API or javax.lang.model.*. */ private void completeEnclosing(ClassSymbol c) { if (c.owner.kind == PCK) { Symbol owner = c.owner; for (Name name : Convert.enclosingCandidates(Convert.shortName(c.name))) { Symbol encl = owner.members().lookup(name).sym; if (encl == null) encl = classes.get(TypeSymbol.formFlatName(name, owner)); if (encl != null) encl.complete(); } } }
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where
/** * {@inheritDoc} */ public FilteredMemberList getAllMembers(TypeElement element) { Symbol sym = cast(Symbol.class, element); Scope scope = sym.members().dupUnshared(); List<Type> closure = types.closure(sym.asType()); for (Type t : closure) addMembers(scope, t); return new FilteredMemberList(scope); } // where