Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.ballerina.flowmodelgenerator.extension.request.DataMapperTypesRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMapperVisualizeRequest;
import io.ballerina.flowmodelgenerator.extension.request.DataMappingDeleteRequest;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperClearCacheResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperFieldPositionResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperModelResponse;
import io.ballerina.flowmodelgenerator.extension.response.DataMapperNodePositionResponse;
Expand All @@ -47,6 +48,7 @@
import io.ballerina.flowmodelgenerator.extension.response.DataMappingDeleteResponse;
import io.ballerina.projects.Document;
import org.ballerinalang.annotation.JavaSPIService;
import org.ballerinalang.diagramutil.connector.models.connector.ReferenceType;
import org.ballerinalang.langserver.commons.LanguageServerContext;
import org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService;
import org.ballerinalang.langserver.commons.workspace.WorkspaceManager;
Expand Down Expand Up @@ -442,6 +444,28 @@ public CompletableFuture<DataMapperSourceResponse> transformationFunction(
});
}

/**
* Clears the visited type map cache in ReferenceType.
* This API can be used to reset the type cache when needed.
*
* @return Response indicating whether the cache was successfully cleared
* @since 1.2.0
*/
@JsonRequest
public CompletableFuture<DataMapperClearCacheResponse> clearTypeCache() {
return CompletableFuture.supplyAsync(() -> {
DataMapperClearCacheResponse response = new DataMapperClearCacheResponse();
try {
ReferenceType.clearVisitedTypeMap();
response.setSuccess(true);
} catch (Throwable e) {
response.setError(e);
response.setSuccess(false);
}
return response;
});
}

private Optional<Document> getDocumentFromFile(Path projectPath, String fileName) {
try {
return this.workspaceManagerProxy.get().document(projectPath.resolve(fileName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.extension.response;

/**
* Represents the response for clearing the data mapper type cache.
*
* @since 1.2.0
*/
public class DataMapperClearCacheResponse extends AbstractFlowModelResponse {

private boolean success;

public DataMapperClearCacheResponse() {
this.success = false;
}

public boolean isSuccess() {
return success;
}

public void setSuccess(boolean success) {
this.success = success;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class ReferenceType {
private static final Map<String, RefType> visitedTypeMap = new HashMap<>();
private static final Map<String, RefType> visitedTypeMap = new ConcurrentHashMap<>();

public record Field(String fieldName, RefType type, boolean optional, String defaultValue) {
}
Expand Down Expand Up @@ -469,4 +470,8 @@ private static void validateDependentTypes(RefType type, List<Symbol> typeDefSym
}
}

public static void clearVisitedTypeMap() {
visitedTypeMap.clear();
}

}
Loading