Search in sources :

Example 16 with IType

use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.

the class JandexIndex method allSubtypesOf.

public Flux<IType> allSubtypesOf(IType type) {
    DotName name = DotName.createSimple(type.getFullyQualifiedName());
    Flux<IType> flux = Flux.fromIterable(index.keySet()).publishOn(Schedulers.parallel()).flatMap(file -> {
        Optional<IndexView> optional = index.get(file).get();
        if (optional.isPresent()) {
            return Flux.fromIterable(type.isInterface() ? optional.get().getAllKnownImplementors(name) : optional.get().getAllKnownSubclasses(name)).publishOn(Schedulers.parallel()).map(info -> createType(Tuples.of(file, info)));
        } else {
            return Flux.empty();
        }
    });
    if (baseIndex == null) {
        return flux;
    } else {
        return Flux.merge(flux, Flux.fromArray(baseIndex).flatMap(index -> index.allSubtypesOf(type)));
    }
}
Also used : Arrays(java.util.Arrays) JarIndexer(org.jboss.jandex.JarIndexer) DotName(org.jboss.jandex.DotName) Supplier(com.google.common.base.Supplier) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) HashMap(java.util.HashMap) IJavadocProvider(org.springframework.ide.vscode.commons.java.IJavadocProvider) FuzzyMatcher(org.springframework.ide.vscode.commons.util.FuzzyMatcher) ClassInfo(org.jboss.jandex.ClassInfo) IMethod(org.springframework.ide.vscode.commons.java.IMethod) Indexer(org.jboss.jandex.Indexer) IField(org.springframework.ide.vscode.commons.java.IField) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) Schedulers(reactor.core.scheduler.Schedulers) IAnnotation(org.springframework.ide.vscode.commons.java.IAnnotation) IndexView(org.jboss.jandex.IndexView) IndexReader(org.jboss.jandex.IndexReader) Iterator(java.util.Iterator) Log(org.springframework.ide.vscode.commons.util.Log) Predicate(java.util.function.Predicate) IJavadoc(org.springframework.ide.vscode.commons.javadoc.IJavadoc) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Flux(reactor.core.publisher.Flux) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) IType(org.springframework.ide.vscode.commons.java.IType) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) InputStream(java.io.InputStream) IndexView(org.jboss.jandex.IndexView) DotName(org.jboss.jandex.DotName) IType(org.springframework.ide.vscode.commons.java.IType)

Example 17 with IType

use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.

the class HtmlJavadocProvider method getJavadoc.

@Override
public IJavadoc getJavadoc(IField field) {
    try {
        IType declaringType = field.getDeclaringType();
        JavadocContents javadocContents = findHtml(declaringType);
        String html = javadocContents == null ? null : javadocContents.getFieldDoc(field);
        return html == null ? null : new HtmlJavadoc(html);
    } catch (Exception e) {
        Log.log(e);
        return null;
    }
}
Also used : JavadocContents(org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents) IType(org.springframework.ide.vscode.commons.java.IType)

Example 18 with IType

use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.

the class TypeUtil method getEnumConstant.

public IField getEnumConstant(Type enumType, String propName) {
    IType type = findType(enumType);
    // 1: if propname is already spelled exactly...
    IField f = getExactField(type, propName);
    if (f != null)
        return f;
    // 2: most likely enum constant is upper-case form of propname
    String fieldName = StringUtil.hyphensToUpperCase(propName);
    return getExactField(type, fieldName);
}
Also used : IField(org.springframework.ide.vscode.commons.java.IField) IType(org.springframework.ide.vscode.commons.java.IType)

Example 19 with IType

use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.

the class TypeUtil method getProperties.

/**
 * Determine properties that are setable on object of given type.
 * <p>
 * Note that this may return both null or an empty list, but they mean
 * different things. Null means that the properties on the object are not known,
 * and therefore reconciling should not check property validity. On the other hand
 * returning an empty list means that there are no properties. In this case,
 * accessing properties is invalid and reconciler should show an error message
 * for any property access.
 *
 * @return A list of known properties or null if the list of properties is unknown.
 */
public List<TypedProperty> getProperties(Type type, EnumCaseMode enumMode, BeanPropertyNameMode beanMode) {
    if (type == null) {
        return null;
    }
    if (!isDotable(type)) {
        // If dot navigation is not valid then really this is just like saying the type has no properties.
        return Collections.emptyList();
    }
    if (isMap(type)) {
        Type keyType = getKeyType(type);
        if (keyType != null) {
            Collection<StsValueHint> keyHints = getAllowedValues(keyType, enumMode);
            if (CollectionUtil.hasElements(keyHints)) {
                Type valueType = getDomainType(type);
                ArrayList<TypedProperty> properties = new ArrayList<>(keyHints.size());
                for (StsValueHint hint : keyHints) {
                    String propName = hint.getValue();
                    properties.add(new TypedProperty(propName, valueType, hint.getDescription(), hint.getDeprecation()));
                }
                return properties;
            }
        }
    } else {
        String typename = type.getErasure();
        IType typeFromIndex = findType(typename);
        // TODO: handle type parameters.
        if (typeFromIndex != null) {
            ArrayList<TypedProperty> properties = new ArrayList<>();
            getGetterMethods(typeFromIndex).forEach(m -> {
                Deprecation deprecation = DeprecationUtil.extract(m);
                Type propType = null;
                try {
                    propType = Type.fromJavaType(m.getReturnType());
                } catch (Exception e) {
                    Log.log(e);
                }
                if (beanMode.includesHyphenated()) {
                    properties.add(new TypedProperty(getterOrSetterNameToProperty(m.getElementName()), propType, deprecation));
                }
                if (beanMode.includesCamelCase()) {
                    properties.add(new TypedProperty(getterOrSetterNameToCamelName(m.getElementName()), propType, deprecation));
                }
            });
            return properties;
        }
    }
    return null;
}
Also used : IType(org.springframework.ide.vscode.commons.java.IType) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) Deprecation(org.springframework.ide.vscode.boot.configurationmetadata.Deprecation) ArrayList(java.util.ArrayList) IType(org.springframework.ide.vscode.commons.java.IType)

Example 20 with IType

use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.

the class TypeUtil method getGetter.

public IJavaElement getGetter(Type beanType, String propName) {
    String getterName = "get" + StringUtil.hyphensToCamelCase(propName, true);
    IType type = findType(beanType);
    IMethod m = type.getMethod(getterName, Stream.empty());
    if (m.exists()) {
        return m;
    }
    return null;
}
Also used : IMethod(org.springframework.ide.vscode.commons.java.IMethod) IType(org.springframework.ide.vscode.commons.java.IType)

Aggregations

IType (org.springframework.ide.vscode.commons.java.IType)30 Test (org.junit.Test)19 MavenJavaProject (org.springframework.ide.vscode.commons.maven.java.MavenJavaProject)18 IMethod (org.springframework.ide.vscode.commons.java.IMethod)14 IJavadoc (org.springframework.ide.vscode.commons.javadoc.IJavadoc)11 IField (org.springframework.ide.vscode.commons.java.IField)9 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Stream (java.util.stream.Stream)3 Deprecation (org.springframework.ide.vscode.boot.configurationmetadata.Deprecation)3 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)3 Cache (com.google.common.cache.Cache)2