public boolean hasField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return true; } } ReferenceTypeImpl superclass = getSuperClass(); if (superclass == null) { return false; } else { return superclass.getTypeDeclaration().hasField(name); } }
public boolean hasField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return true; } } for (ResolvedReferenceType ancestor : typeDeclaration.getAllAncestors()) { if (ancestor.getTypeDeclaration().hasField(name)) { return true; } } return false; }
public boolean hasField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return true; } } ReferenceTypeImpl superclass = getSuperClass(); if (superclass == null) { return false; } else { return superclass.getTypeDeclaration().hasField(name); } }
public ResolvedFieldDeclaration getField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return new ReflectionFieldDeclaration(field, typeSolver); } } for (ResolvedReferenceType ancestor : typeDeclaration.getAllAncestors()) { if (ancestor.getTypeDeclaration().hasField(name)) { ReflectionFieldDeclaration reflectionFieldDeclaration = (ReflectionFieldDeclaration) ancestor.getTypeDeclaration().getField(name); return reflectionFieldDeclaration.replaceType(ancestor.getFieldType(name).get()); } } throw new UnsolvedSymbolException(name, "Field in " + this); }
public ResolvedFieldDeclaration getField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return new ReflectionFieldDeclaration(field, typeSolver); } } for (ResolvedReferenceType ancestor : typeDeclaration.getAllAncestors()) { if (ancestor.getTypeDeclaration().hasField(name)) { ReflectionFieldDeclaration reflectionFieldDeclaration = (ReflectionFieldDeclaration) ancestor.getTypeDeclaration().getField(name); return reflectionFieldDeclaration.replaceType(ancestor.getFieldType(name).get()); } } throw new UnsolvedSymbolException(name, "Field in " + this); }
public ResolvedFieldDeclaration getField(String name) { for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(name)) { return new ReflectionFieldDeclaration(field, typeSolver); } } for (ResolvedReferenceType ancestor : typeDeclaration.getAllAncestors()) { if (ancestor.getTypeDeclaration().hasField(name)) { ReflectionFieldDeclaration reflectionFieldDeclaration = (ReflectionFieldDeclaration) ancestor.getTypeDeclaration().getField(name); return reflectionFieldDeclaration.replaceType(ancestor.getFieldType(name).get()); } } throw new UnsolvedSymbolException(name, "Field in " + this); }
@Override public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name) { if (typeSolver == null) throw new IllegalArgumentException(); // among constants for (EnumConstantDeclaration constant : wrappedNode.getEntries()) { if (constant.getName().getId().equals(name)) { return SymbolReference.solved(new JavaParserEnumConstantDeclaration(constant, typeSolver)); } } if (this.getDeclaration().hasField(name)) { return SymbolReference.solved(this.getDeclaration().getField(name)); } // then to parent return getParent().solveSymbol(name); }
@Override public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) { if (typeSolver == null) throw new IllegalArgumentException(); // among constants for (EnumConstantDeclaration constant : wrappedNode.getEntries()) { if (constant.getName().getId().equals(name)) { return SymbolReference.solved(new JavaParserEnumConstantDeclaration(constant, typeSolver)); } } if (this.getDeclaration().hasField(name)) { return SymbolReference.solved(this.getDeclaration().getField(name)); } // then to parent return getParent().solveSymbol(name, typeSolver); }
@Override public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) { if (typeSolver == null) throw new IllegalArgumentException(); // among constants for (EnumConstantDeclaration constant : wrappedNode.getEntries()) { if (constant.getName().getId().equals(name)) { return SymbolReference.solved(new JavaParserEnumConstantDeclaration(constant, typeSolver)); } } if (this.getDeclaration().hasField(name)) { return SymbolReference.solved(this.getDeclaration().getField(name)); } // then to parent return getParent().solveSymbol(name, typeSolver); }
/** * Java Parser can't differentiate between packages, internal types, and fields. * All three are lumped together into FieldAccessExpr. We need to differentiate them. */ private ResolvedType solveDotExpressionType(ResolvedReferenceTypeDeclaration parentType, FieldAccessExpr node) { // Fields and internal type declarations cannot have the same name. // Thus, these checks will always be mutually exclusive. if (parentType.hasField(node.getName().getId())) { return parentType.getField(node.getName().getId()).getType(); } else if (parentType.hasInternalType(node.getName().getId())) { return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId()), typeSolver); } else { throw new UnsolvedSymbolException(node.getName().getId()); } }
/** * Java Parser can't differentiate between packages, internal types, and fields. * All three are lumped together into FieldAccessExpr. We need to differentiate them. */ private ResolvedType solveDotExpressionType(ResolvedReferenceTypeDeclaration parentType, FieldAccessExpr node) { // Fields and internal type declarations cannot have the same name. // Thus, these checks will always be mutually exclusive. if (parentType.hasField(node.getName().getId())) { return parentType.getField(node.getName().getId()).getType(); } else if (parentType.hasInternalType(node.getName().getId())) { return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId()), typeSolver); } else { throw new UnsolvedSymbolException(node.getName().getId()); } }
@Override public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) { SwitchStmt switchStmt = (SwitchStmt) getParentNode(wrappedNode); ResolvedType type = JavaParserFacade.get(typeSolver).getType(switchStmt.getSelector()); if (type.isReferenceType() && type.asReferenceType().getTypeDeclaration().isEnum()) { if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl typeUsageOfTypeDeclaration = (ReferenceTypeImpl) type; if (typeUsageOfTypeDeclaration.getTypeDeclaration().hasField(name)) { return SymbolReference.solved(typeUsageOfTypeDeclaration.getTypeDeclaration().getField(name)); } } else { throw new UnsupportedOperationException(); } } // look for declaration in other switch statements for (SwitchEntryStmt seStmt : switchStmt.getEntries()) { if (!seStmt.equals(wrappedNode)) { for (Statement stmt : seStmt.getStatements()) { SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(stmt, typeSolver); SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name); if (symbolReference.isSolved()) { return symbolReference; } } } } return getParent().solveSymbol(name, typeSolver); }
@Override public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) { SwitchStmt switchStmt = (SwitchStmt) getParentNode(wrappedNode); ResolvedType type = JavaParserFacade.get(typeSolver).getType(switchStmt.getSelector()); if (type.isReferenceType() && type.asReferenceType().getTypeDeclaration().isEnum()) { if (type instanceof ReferenceTypeImpl) { ReferenceTypeImpl typeUsageOfTypeDeclaration = (ReferenceTypeImpl) type; if (typeUsageOfTypeDeclaration.getTypeDeclaration().hasField(name)) { return SymbolReference.solved(typeUsageOfTypeDeclaration.getTypeDeclaration().getField(name)); } } else { throw new UnsupportedOperationException(); } } // look for declaration in other switch statements for (SwitchEntryStmt seStmt : switchStmt.getEntries()) { if (!seStmt.equals(wrappedNode)) { for (Statement stmt : seStmt.getStatements()) { SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(stmt, typeSolver); SymbolReference<? extends ResolvedValueDeclaration> symbolReference = solveWith(symbolDeclarator, name); if (symbolReference.isSolved()) { return symbolReference; } } } } return getParent().solveSymbol(name, typeSolver); }
return SymbolReference.solved(typeUsageOfTypeDeclaration.getTypeDeclaration().asEnum().getEnumConstant(name)); if (typeUsageOfTypeDeclaration.getTypeDeclaration().hasField(name)) { return SymbolReference.solved(typeUsageOfTypeDeclaration.getTypeDeclaration().getField(name));
/** * Java Parser can't differentiate between packages, internal types, and fields. * All three are lumped together into FieldAccessExpr. We need to differentiate them. */ private ResolvedType solveDotExpressionType(ResolvedReferenceTypeDeclaration parentType, FieldAccessExpr node) { // Fields and internal type declarations cannot have the same name. // Thus, these checks will always be mutually exclusive. if (parentType.isEnum() && parentType.asEnum().hasEnumConstant(node.getName().getId())) { return parentType.asEnum().getEnumConstant(node.getName().getId()).getType(); } else if (parentType.hasField(node.getName().getId())) { return parentType.getField(node.getName().getId()).getType(); } else if (parentType.hasInternalType(node.getName().getId())) { return new ReferenceTypeImpl(parentType.getInternalType(node.getName().getId()), typeSolver); } else { throw new UnsolvedSymbolException(node.getName().getId()); } }