Search in sources :

Example 11 with IType

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;
}
Also used : Arrays(java.util.Arrays) Provider(javax.inject.Provider) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) IMethod(org.springframework.ide.vscode.commons.java.IMethod) LazyProvider(org.springframework.ide.vscode.commons.util.LazyProvider) ArrayUtils.firstElement(org.springframework.ide.vscode.commons.util.ArrayUtils.firstElement) ArrayList(java.util.ArrayList) IJavaElement(org.springframework.ide.vscode.commons.java.IJavaElement) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Charset(java.nio.charset.Charset) ImmutableList(com.google.common.collect.ImmutableList) IField(org.springframework.ide.vscode.commons.java.IField) Locale(java.util.Locale) Flags(org.springframework.ide.vscode.commons.java.Flags) Map(java.util.Map) DeprecationUtil(org.springframework.ide.vscode.boot.metadata.util.DeprecationUtil) ValueProviderStrategy(org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry.ValueProviderStrategy) ResourceHintProvider(org.springframework.ide.vscode.boot.metadata.ResourceHintProvider) ValueParser(org.springframework.ide.vscode.commons.util.ValueParser) ImmutableSet(com.google.common.collect.ImmutableSet) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) Log(org.springframework.ide.vscode.commons.util.Log) Collection(java.util.Collection) ArrayUtils(org.springframework.ide.vscode.commons.util.ArrayUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) Assert(org.springframework.ide.vscode.commons.util.Assert) Flux(reactor.core.publisher.Flux) ArrayUtils.lastElement(org.springframework.ide.vscode.commons.util.ArrayUtils.lastElement) List(java.util.List) CollectionUtil(org.springframework.ide.vscode.commons.util.CollectionUtil) Stream(java.util.stream.Stream) EnumValueParser(org.springframework.ide.vscode.commons.util.EnumValueParser) MimeTypes(org.springframework.ide.vscode.commons.util.MimeTypes) Entry(java.util.Map.Entry) Optional(java.util.Optional) IType(org.springframework.ide.vscode.commons.java.IType) Collections(java.util.Collections) Deprecation(org.springframework.ide.vscode.boot.configurationmetadata.Deprecation) AlwaysFailingParser(org.springframework.ide.vscode.commons.util.AlwaysFailingParser) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) StsValueHint(org.springframework.ide.vscode.boot.metadata.hints.StsValueHint) IType(org.springframework.ide.vscode.commons.java.IType)

Example 12 with IType

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;
}
Also used : IType(org.springframework.ide.vscode.commons.java.IType)

Example 13 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(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;
    }
}
Also used : JavadocContents(org.springframework.ide.vscode.commons.javadoc.internal.JavadocContents) IType(org.springframework.ide.vscode.commons.java.IType)

Example 14 with IType

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);
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) IType(org.springframework.ide.vscode.commons.java.IType) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Example 15 with IType

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;
}
Also used : 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