com.github.javaparser.resolution.UnsolvedSymbolException Java Examples

The following examples show how to use com.github.javaparser.resolution.UnsolvedSymbolException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapKeyClass.java    From jeddict with Apache License 2.0 6 votes vote down vote up
public static ResolvedTypeDeclaration getDeclaredType(MemberExplorer member) {
    Optional<ResolvedTypeDeclaration> keyTypeOpt;
    ResolvedTypeDeclaration keyType;
    Optional<AnnotationExplorer> mapKeyClassOpt = member.getAnnotation(javax.persistence.MapKeyClass.class);
    if (mapKeyClassOpt.isPresent()) {
        Optional<ResolvedTypeDeclaration> mapKeyClassValueOpt = mapKeyClassOpt.get().getResolvedClass("value");
        if (mapKeyClassValueOpt.isPresent()) {
            keyType = mapKeyClassValueOpt.get();
        } else {
            throw new UnsolvedSymbolException("@MapKeyClass value not defind '" + member.getFieldName() + "'");
        }
    } else {
        keyTypeOpt = member.getTypeArgumentDeclaration(0);
        if (keyTypeOpt.isPresent()) {
            keyType = keyTypeOpt.get();
        } else {
            throw new UnsolvedSymbolException("@MapKeyClass or generic type not defined in ElementCollection attribute '" + member.getFieldName() + "'");
        }
    }
    return keyType;
}
 
Example #2
Source File: RefactoringHelper.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * @param targetClass
 * @param targetMethod
 * @return list of resolved classes and interfaces which are ancestors of the
 *         given classes (not including java.lang.Object or external
 *         dependencies) and contain the given target method
 * @throws BotRefactoringException
 */
private static Set<ResolvedReferenceTypeDeclaration> findAllAncestors(ClassOrInterfaceDeclaration targetClass,
		MethodDeclaration targetMethod) throws BotRefactoringException {
	List<ResolvedReferenceType> ancestors = new ArrayList<>();
	Set<ResolvedReferenceTypeDeclaration> result = new HashSet<>();

	try {
		ancestors = targetClass.resolve().getAllAncestors();
	} catch (UnsolvedSymbolException u) {
		ancestors = RefactoringHelper.getAllResolvableAncestors(targetClass.resolve());
		logger.warn("Refactored classes might extend/implement classes or interfaces from external dependency! "
				+ "Please validate the correctness of the refactoring.");
		// TODO propagate warning
	} catch (InvalidPathException i) {
		throw new BotRefactoringException("Javaparser could not parse file: " + i.getMessage());
	} catch (Exception e) {
		throw new BotRefactoringException("Error while resolving superclasses occured!");
	}

	for (ResolvedReferenceType ancestor : ancestors) {
		if (!ancestor.getQualifiedName().equals("java.lang.Object")) {
			for (ResolvedMethodDeclaration method : ancestor.getAllMethods()) {
				if (method.getSignature().equals(targetMethod.resolve().getSignature())) {
					result.add(ancestor.getTypeDeclaration());
				}
			}
		}
	}

	return result;
}
 
Example #3
Source File: JavaParserUtil.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @param type
 * 		Resolved field declaration.
 *
 * @return Descriptor of the resolved field. May be {@code null}.
 */
public static String getDescriptor(ResolvedFieldDeclaration type) {
	String desc = null;
	try {
		desc =	getDescriptor(type.getType());
	} catch(UnsolvedSymbolException ex) {
		if (type instanceof JavaParserFieldDeclaration) {
			desc = getDescriptor(((JavaParserFieldDeclaration) type).getWrappedNode().getCommonType());
		}
	} catch(UnsupportedOperationException e) { /* Ignored */ }
	return desc;
}
 
Example #4
Source File: ParserTypeUtil.java    From JRemapper with MIT License 5 votes vote down vote up
/**
 * @param type
 * 		Resolved field declaration.
 *
 * @return Descriptor of the resolved field.
 */
public static String getResolvedFieldDesc(ResolvedFieldDeclaration type) {
	String desc = null;
	try {
		desc =	ParserTypeUtil.getDescriptor(type.getType());
	} catch(UnsolvedSymbolException ex) {
		if (type instanceof JavaParserFieldDeclaration) {
			desc = ParserTypeUtil.getDescriptor(((JavaParserFieldDeclaration) type).getWrappedNode().getCommonType());
		}
	} catch(UnsupportedOperationException e) {}
	return desc;
}
 
Example #5
Source File: MultiRelationAttribute.java    From jeddict with Apache License 2.0 4 votes vote down vote up
@Override
public void loadAttribute(MemberExplorer member, AnnotationExplorer annotation) {
    super.loadAttribute(member, annotation);

    annotation.getString("mappedBy").ifPresent(this::setMappedBy);

    this.orderBy = OrderBy.load(member);
    this.orderColumn = OrderColumn.load(member);
    this.collectionType = member.getType();
    Class collectionTypeClass = null;
    try {
        collectionTypeClass = Class.forName(this.collectionType);
    } catch (ClassNotFoundException ex) {
    }
    boolean mapKeyExist = collectionTypeClass != null && Map.class.isAssignableFrom(collectionTypeClass);

    Optional<ResolvedTypeDeclaration> targetEntityOpt = annotation.getResolvedClass("targetEntity");
    ResolvedTypeDeclaration targetEntityValue;
    if (targetEntityOpt.isPresent()) {
        targetEntityValue = targetEntityOpt.get();
    } else {
        targetEntityOpt = member.getTypeArgumentDeclaration(mapKeyExist ? 1 : 0);
        if (targetEntityOpt.isPresent()) {
            targetEntityValue = targetEntityOpt.get();
            this.setValueConstraints(member.getTypeArgumentBeanValidationConstraints(mapKeyExist ? 1 : 0));
        } else {
            throw new UnsolvedSymbolException("targetEntity or generic type not defined in relation attribute '" + member.getFieldName() + "'");
        }
    }
    this.targetEntityPackage = targetEntityValue.getPackageName();
    this.targetEntity = targetEntityValue.getClassName();

    if (mapKeyExist) {
        this.mapKeyConvert = Convert.load(member, mapKeyExist, true);
        this.mapKey = MapKey.load(member);
        this.mapKeyType = this.mapKey != null ? MapKeyType.EXT : MapKeyType.NEW;

        ResolvedTypeDeclaration keyType = MapKeyClass.getDeclaredType(member);
        if (keyType instanceof ResolvedReferenceTypeDeclaration) {
            ResolvedReferenceTypeDeclaration refKeyType = (ResolvedReferenceTypeDeclaration) keyType;
            if (refKeyType.hasDirectlyAnnotation(EMBEDDABLE_FQN)) {
                Optional<Embeddable> embeddableOpt = member.getSource().findEmbeddable(refKeyType);
                if (!embeddableOpt.isPresent()) {
                    throw new IllegalStateException("Embeddable Not found " + keyType.getQualifiedName());
                }
                this.mapKeyAttributeType = embeddableOpt.get().getClazz(); //TODO set Embeddable
            } else if (refKeyType.hasDirectlyAnnotation(ENTITY_FQN)) {
                Optional<Entity> entityOpt = member.getSource().findEntity(refKeyType);
                if (!entityOpt.isPresent()) {
                    throw new IllegalStateException("Entity Not found " + keyType.getQualifiedName());
                }
                this.mapKeyAttributeType = entityOpt.get().getClazz(); //TODO set Entity
            }
        } else {
            this.mapKeyAttributeType = keyType.getQualifiedName();
        }

        this.mapKeyColumn = Column.loadMapKey(member);
        this.mapKeyTemporal = TemporalType.loadMapKey(member);
        this.mapKeyEnumerated = EnumType.loadMapKey(member);
        this.mapKeyJoinColumn = JoinColumn.loadMapKey(member);

        member.getAnnotation(javax.persistence.ForeignKey.class)
                .map(ForeignKey::load)
                .ifPresent(this::setMapKeyForeignKey);
        this.mapKeyAttributeOverride = AttributeOverride.load(member);
    }
}