use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.
the class TypeUtil method getAllowedValues.
/**
* @return An array of allowed values for a given type. If an array is returned then
* *only* values in the array are valid and using any other value constitutes an error.
* This may return null if allowedValues list is unknown or the type is not characterizable
* as a simple enumaration of allowed values.
* @param caseMode determines whether Enum values are returned in 'lower case form', 'orignal form',
* or 'aliased' (meaning both forms are returned).
*/
public Collection<StsValueHint> getAllowedValues(Type enumType, EnumCaseMode caseMode) {
if (enumType != null) {
try {
String[] values = TYPE_VALUES.get(enumType.getErasure());
if (values != null) {
if (caseMode == EnumCaseMode.ALIASED) {
ImmutableSet.Builder<String> aliased = ImmutableSet.builder();
aliased.add(values);
for (int i = 0; i < values.length; i++) {
aliased.add(values[i].toUpperCase());
}
return aliased.build().stream().map(StsValueHint::create).collect(Collectors.toList());
} else {
return Arrays.stream(values).map(StsValueHint::create).collect(Collectors.toList());
}
}
IType type = findType(enumType.getErasure());
if (type != null && type.isEnum()) {
ImmutableList.Builder<StsValueHint> enums = ImmutableList.builder();
boolean addOriginal = caseMode == EnumCaseMode.ORIGNAL || caseMode == EnumCaseMode.ALIASED;
boolean addLowerCased = caseMode == EnumCaseMode.LOWER_CASE || caseMode == EnumCaseMode.ALIASED;
type.getFields().filter(f -> f.isEnumConstant()).forEach(f -> {
String rawName = f.getElementName();
if (addOriginal) {
enums.add(StsValueHint.create(rawName, f));
}
if (addLowerCased) {
enums.add(StsValueHint.create(StringUtil.upperCaseToHyphens(rawName), f));
}
});
return enums.build();
}
} 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 JavadocContents method computeMethodRange.
/*
* Compute the ranges of the parts of the javadoc that describe each method of the type
*/
private int[] computeMethodRange(IMethod method) throws Exception {
IType type = method.getDeclaringType();
if (!this.hasComputedChildrenSections) {
computeChildrenSections();
}
char[] anchor = computeMethodAnchorPrefixEnd(method).toCharArray();
int[] range = null;
if (this.indexOfAllMethodsTop == -1 || this.indexOfAllMethodsBottom == -1) {
// the detail section has no top or bottom, so the doc has an unknown format
if (this.unknownFormatAnchorIndexes == null) {
int childernCount = (int) (type.getMethods().count() + type.getFields().count());
this.unknownFormatAnchorIndexes = new int[childernCount];
this.unknownFormatAnchorIndexesCount = 0;
this.unknownFormatLastAnchorFoundIndex = this.childrenStart;
}
this.tempAnchorIndexes = this.unknownFormatAnchorIndexes;
this.tempAnchorIndexesCount = this.unknownFormatAnchorIndexesCount;
this.tempLastAnchorFoundIndex = this.unknownFormatLastAnchorFoundIndex;
range = computeChildRange(anchor, this.indexOfFieldsBottom);
if (range == null) {
range = computeChildRange(getJavadoc8Anchor(anchor), this.indexOfAllMethodsBottom);
}
this.unknownFormatLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
this.unknownFormatAnchorIndexesCount = this.tempAnchorIndexesCount;
this.unknownFormatAnchorIndexes = this.tempAnchorIndexes;
} else {
if (this.methodAnchorIndexes == null) {
this.methodAnchorIndexes = new int[(int) type.getMethods().count()];
this.methodAnchorIndexesCount = 0;
this.methodLastAnchorFoundIndex = this.indexOfAllMethodsTop;
}
this.tempAnchorIndexes = this.methodAnchorIndexes;
this.tempAnchorIndexesCount = this.methodAnchorIndexesCount;
this.tempLastAnchorFoundIndex = this.methodLastAnchorFoundIndex;
range = computeChildRange(anchor, this.indexOfAllMethodsBottom);
if (range == null) {
range = computeChildRange(getJavadoc8Anchor(anchor), this.indexOfAllMethodsBottom);
}
this.methodLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
this.methodAnchorIndexesCount = this.tempAnchorIndexesCount;
this.methodAnchorIndexes = this.tempAnchorIndexes;
}
return range;
}
use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.
the class HtmlJavadocProvider method getJavadoc.
@Override
public IJavadoc getJavadoc(IMethod method) {
try {
IType declaringType = method.getDeclaringType();
JavadocContents javadocContents = findHtml(declaringType);
String html = javadocContents == null ? null : javadocContents.getMethodDoc(method);
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 ApplicationPropertiesEditorTest method testPredefinedProject.
@Test
public void testPredefinedProject() throws Exception {
IJavaProject p = createPredefinedMavenProject("tricky-getters-boot-1.3.1-app");
IType type = p.getClasspath().findType("demo.DemoApplication");
assertNotNull(type);
}
use of org.springframework.ide.vscode.commons.java.IType in project sts4 by spring-projects.
the class JavadocContents method computeFieldRange.
/*
* Compute the ranges of the parts of the javadoc that describe each child of the type (fields, methods)
*/
private int[] computeFieldRange(IField field) throws Exception {
IType type = field.getDeclaringType();
if (!this.hasComputedChildrenSections) {
computeChildrenSections();
}
StringBuffer buffer = new StringBuffer(field.getElementName());
buffer.append(JavadocConstants.ANCHOR_PREFIX_END);
char[] anchor = String.valueOf(buffer).toCharArray();
int[] range = null;
int top = field.isEnumConstant() ? this.indexOfEnumConstantsDetails : this.indexOfFieldDetails;
int bottom = field.isEnumConstant() ? this.indexOfEnumConstantsBottom : this.indexOfFieldsBottom;
if (top == -1 || bottom == -1) {
// the detail section has no top or bottom, so the doc has an unknown format
if (this.unknownFormatAnchorIndexes == null) {
this.unknownFormatAnchorIndexes = new int[(int) type.getFields().count()];
this.unknownFormatAnchorIndexesCount = 0;
this.unknownFormatLastAnchorFoundIndex = this.childrenStart;
}
this.tempAnchorIndexes = this.unknownFormatAnchorIndexes;
this.tempAnchorIndexesCount = this.unknownFormatAnchorIndexesCount;
this.tempLastAnchorFoundIndex = this.unknownFormatLastAnchorFoundIndex;
range = computeChildRange(anchor, bottom);
this.unknownFormatLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
this.unknownFormatAnchorIndexesCount = this.tempAnchorIndexesCount;
this.unknownFormatAnchorIndexes = this.tempAnchorIndexes;
} else {
if (this.fieldAnchorIndexes == null) {
this.fieldAnchorIndexes = new int[(int) type.getFields().count()];
this.fieldAnchorIndexesCount = 0;
this.fieldLastAnchorFoundIndex = top;
}
this.tempAnchorIndexes = this.fieldAnchorIndexes;
this.tempAnchorIndexesCount = this.fieldAnchorIndexesCount;
this.tempLastAnchorFoundIndex = this.fieldLastAnchorFoundIndex;
range = computeChildRange(anchor, bottom);
this.fieldLastAnchorFoundIndex = this.tempLastAnchorFoundIndex;
this.fieldAnchorIndexesCount = this.tempAnchorIndexesCount;
this.fieldAnchorIndexes = this.tempAnchorIndexes;
}
return range;
}
Aggregations