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)));
}
}
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;
}
}
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);
}
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;
}
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;
}
Aggregations