use of com.intellij.openapi.diagnostic.ControlFlowException in project midpoint-studio by Evolveum.
the class ConnectorXmlSchemaCacheService method getSchema.
public XmlFile getSchema(String url, XmlFile file) {
if (url == null || (!SchemaConstantsGenerated.NS_ICF_CONFIGURATION.equals(url) && !url.startsWith(ICF_NS_PREFIX))) {
return null;
}
XmlTag rootTag = file.getRootTag();
QName root = MidPointUtils.createQName(rootTag);
if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(root)) {
String fileName = file.getVirtualFile().getName();
String uuid = fileName.replaceFirst("^connector-", "").replaceFirst("-schema.xsd$", "");
if (MidPointUtils.UUID_PATTERN.matcher(uuid).matches()) {
return getSchema(url, uuid);
}
}
if (SchemaConstants.C_OBJECTS.equals(root)) {
XmlTag[] tags = rootTag.getSubTags();
if (tags.length > 0) {
rootTag = tags[0];
root = MidPointUtils.createQName(rootTag);
}
}
if (!SchemaConstantsGenerated.C_RESOURCE.equals(root) && !isResourceUsingXsi(rootTag)) {
return null;
}
XmlTag connectorRef = MidPointUtils.findSubTag(rootTag, ResourceType.F_CONNECTOR_REF);
if (connectorRef == null) {
return null;
}
String oid = connectorRef.getAttributeValue("oid", SchemaConstantsGenerated.NS_COMMON);
if (oid != null) {
List<ConnectorType> keys = cache.keySet().stream().filter(c -> oid.equals(c.getOid())).collect(Collectors.toList());
if (keys.size() != 1) {
return null;
}
CacheValue value = cache.get(keys.get(0));
return getSchema(url, value);
}
XmlTag filter = MidPointUtils.findSubTag(connectorRef, ObjectReferenceType.F_FILTER);
RunnableUtils.PluginClassCallable<XmlFile> callable = new RunnableUtils.PluginClassCallable<>() {
@Override
public XmlFile callWithPluginClassLoader() throws Exception {
ObjectFilter of = null;
try {
String xml = updateNamespaces(filter);
PrismContext ctx = MidPointUtils.DEFAULT_PRISM_CONTEXT;
PrismParser parser = ClientUtils.createParser(ctx, xml);
SearchFilterType filterType = parser.parseRealValue(SearchFilterType.class);
of = ctx.getQueryConverter().parseFilter(filterType, ConnectorType.class);
} catch (Exception ex) {
LOG.debug("Couldn't parse connectorRef filter defined in resource, reason: " + ex.getMessage() + "(" + ex.getClass().getName() + ")");
}
if (of == null) {
return null;
}
// todo check if this for-cycle returns more than one result -> more connector matches filter, throw some error
for (Map.Entry<ConnectorType, CacheValue> e : cache.entrySet()) {
try {
boolean match = ObjectQuery.match(e.getKey(), of, MATCHING_REGISTRY);
if (!match) {
continue;
}
} catch (SchemaException ex) {
LOG.error("Couldn't match connector with connectorRef filter defined in resource", ex);
}
return getSchema(url, e.getValue());
}
return null;
}
};
try {
return callable.call();
} catch (Exception ex) {
if (!(ex instanceof ControlFlowException)) {
LOG.error("Couldn't find connector schema", ex);
}
}
return null;
}
use of com.intellij.openapi.diagnostic.ControlFlowException in project tabnine-intellij by codota.
the class LimitExceededLookupElement method handleInlayCreation.
private void handleInlayCreation(AtomicReference<Inlay> inlayHolder, AtomicBoolean documentChanged, Editor editor, int inlayOffset) {
// get the inlay and hover popup data
HoverBinaryResponse hoverBinaryResponse = this.binaryRequestFacade.executeRequest(new HoverBinaryRequest());
if (hoverBinaryResponse == null || hoverBinaryResponse.getTitle() == null || documentChanged.get()) {
return;
}
// inlay must be added from UI thread
ApplicationManager.getApplication().invokeLater(() -> {
try {
addInlay(editor, inlayOffset, inlayHolder, documentChanged, hoverBinaryResponse);
} catch (Exception e) {
if (e instanceof ControlFlowException) {
throw e;
}
Logger.getInstance(getClass()).warn("Error adding locked item inlay.", e);
}
});
}
use of com.intellij.openapi.diagnostic.ControlFlowException in project tabnine-intellij by codota.
the class LimitExceededLookupElement method tryAddLimitExceededInlay.
private void tryAddLimitExceededInlay(Editor editor, int caretOffset, AtomicReference<Inlay> inlayHolder, AtomicBoolean documentChanged) {
ApplicationManager.getApplication().executeOnPooledThread(() -> {
try {
final Document document = editor.getDocument();
// add the inlay at the end of the line. Ideally we would use
// 'addAfterLineEndElement' but that's
// only available from IJ > 191.
final int currentLineNumber = document.getLineNumber(caretOffset);
final int inlayOffset = document.getLineEndOffset(currentLineNumber);
if (isInlayAlreadyDisplayed(editor, inlayOffset, currentLineNumber)) {
// inlay already displayed at the end of this line - don't add another one.
return;
}
handleInlayCreation(inlayHolder, documentChanged, editor, inlayOffset);
} catch (Exception e) {
if (e instanceof ControlFlowException) {
throw e;
}
Logger.getInstance(getClass()).warn("Error on locked item selection.", e);
}
});
}
Aggregations