com.github.javaparser.symbolsolver.model.resolution.SymbolReference Java Examples

The following examples show how to use com.github.javaparser.symbolsolver.model.resolution.SymbolReference. 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: Input.java    From JRemapper with MIT License 6 votes vote down vote up
@Override
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
	try {
		String internal = name.replace(".", "/");
		if(hasRawClass(internal)) {
			InputStream is = new ByteArrayInputStream(getRawClass(internal));
			ResolvedReferenceTypeDeclaration dec = toTypeDeclaration(classPool.makeClass(is), getRoot());
			SymbolReference<ResolvedReferenceTypeDeclaration> solved = SymbolReference.solved(dec);
			if (solved.isSolved())
				return solved;
		}
	} catch(IOException ex) {
		throw new IllegalStateException("Failed to resolve type: " + name, ex);
	}
	return childSolver.tryToSolveType(name);
}
 
Example #2
Source File: ClassloaderTypeSolver.java    From jeddict with Apache License 2.0 5 votes vote down vote up
@Override
public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) {
    try {
        // Some implementations could return null when the class was loaded through the bootstrap classloader
            // see https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getClassLoader--
            if (classLoader == null) {
                throw new RuntimeException("The ClassloaderTypeSolver has been probably loaded through the bootstrap class loader. This usage is not supported by the JavaSymbolSolver");
            }

            Class<?> clazz = classLoader.loadClass(name);
            return SymbolReference.solved(ReflectionFactory.typeDeclarationFor(clazz, getRoot()));
        } catch (ClassNotFoundException e) {
            // it could be an inner class
            int lastDot = name.lastIndexOf('.');
            if (lastDot == -1) {
                return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
            } else {
                String parentName = name.substring(0, lastDot);
                String childName = name.substring(lastDot + 1);
                SymbolReference<ResolvedReferenceTypeDeclaration> parent = tryToSolveType(parentName);
                if (parent.isSolved()) {
                    Optional<ResolvedReferenceTypeDeclaration> innerClass = parent.getCorrespondingDeclaration().internalTypes()
                            .stream().filter(it -> it.getName().equals(childName)).findFirst();
                    if (innerClass.isPresent()) {
                        return SymbolReference.solved(innerClass.get());
                    } else {
                        return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
                    }
                } else {
                    return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
                }
            }
        }
}