use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class MavenArtifact method getAvailableVersions.
@Nullable
public Collection<String> getAvailableVersions(DBRProgressMonitor monitor, String versionSpec) throws IOException {
if (CommonUtils.isEmpty(versions) && !metadataLoaded) {
loadMetadata(monitor);
}
if (!isVersionPattern(versionSpec)) {
return versions;
}
// Filter versions according to spec
Pattern versionPattern = null;
VersionRange versionRange = null;
if (versionSpec.startsWith("{") && versionSpec.endsWith("}")) {
// Regex - find most recent version matching this pattern
try {
versionPattern = Pattern.compile(versionSpec.substring(1, versionSpec.length() - 1));
} catch (Exception e) {
log.error("Bad version pattern: " + versionSpec);
}
} else {
try {
versionRange = VersionRange.createFromVersionSpec(versionSpec);
} catch (Exception e) {
log.error("Bad version specification: " + versionSpec);
}
}
List<String> filtered = new ArrayList<>();
for (String version : versions) {
boolean matches;
if (versionPattern != null) {
matches = versionPattern.matcher(version).matches();
} else if (versionRange != null) {
matches = versionRange.containsVersion(new DefaultArtifactVersion(version));
} else {
matches = true;
}
if (matches) {
filtered.add(version);
}
}
return filtered;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DataTypeProviderRegistry method getDataTypeProvider.
////////////////////////////////////////////////////
// DataType providers
@Nullable
public DBDValueHandlerProvider getDataTypeProvider(@NotNull DBPDataSource dataSource, @NotNull DBSTypedObject typedObject) {
DBPDriver driver = dataSource.getContainer().getDriver();
if (!(driver instanceof DriverDescriptor)) {
log.warn("Bad datasource specified (driver is not recognized by registry) - " + dataSource);
return null;
}
DataSourceProviderDescriptor dsProvider = ((DriverDescriptor) driver).getProviderDescriptor();
// First try to find type provider for specific datasource type
for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
if (!dtProvider.isGlobal() && dtProvider.supportsDataSource(dataSource, dsProvider) && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
// Find in global providers
for (ValueHandlerDescriptor dtProvider : dataTypeProviders) {
if (dtProvider.isGlobal() && dtProvider.supportsType(typedObject)) {
return dtProvider.getInstance();
}
}
return null;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class DriverLibraryLocal method getLocalFile.
@Nullable
@Override
public File getLocalFile() {
// Try to use direct path
String localFilePath = this.getLocalFilePath();
File libraryFile = new File(localFilePath);
if (libraryFile.exists()) {
return libraryFile;
}
// Try to get local file
File platformFile = detectLocalFile();
if (platformFile != null && platformFile.exists()) {
// Relative file do not exists - use plain one
return platformFile;
}
URL url = driver.getProviderDescriptor().getContributorBundle().getEntry(localFilePath);
if (url == null) {
// Find in external resources
url = driver.getProviderDescriptor().getRegistry().findResourceURL(localFilePath);
}
if (url != null) {
try {
url = FileLocator.toFileURL(url);
} catch (IOException ex) {
log.warn(ex);
}
if (url != null) {
return new File(url.getFile());
}
} else {
try {
url = FileLocator.toFileURL(new URL(localFilePath));
File urlFile = new File(url.getFile());
if (urlFile.exists()) {
platformFile = urlFile;
}
} catch (IOException ex) {
// ignore
}
}
// Nothing fits - just return plain url
return platformFile;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class SQLCompletionProcessor method computeContextInformation.
/**
* This method is incomplete in that it does not implement logic to produce
* some context help relevant to SQL. It just hard codes two strings to
* demonstrate the action
*
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(ITextViewer,
* int)
*/
@Nullable
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
SQLQuery statementInfo = editor.extractQueryAtPos(documentOffset);
if (statementInfo == null || CommonUtils.isEmpty(statementInfo.getQuery())) {
return null;
}
IContextInformation[] result = new IContextInformation[1];
result[0] = new ContextInformation(statementInfo.getQuery(), statementInfo.getQuery());
return result;
}
use of org.jkiss.code.Nullable in project dbeaver by serge-rider.
the class SQLHyperlinkDetector method detectHyperlinks.
@Nullable
@Override
public synchronized IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
this.contextInformer.searchInformation(region);
if (!this.contextInformer.hasObjects()) {
// Long task - just return no links for now
return null;
} else {
// Create hyperlinks based on references
final SQLIdentifierDetector.WordRegion wordRegion = this.contextInformer.getWordRegion();
final IRegion hlRegion = new Region(wordRegion.identStart, wordRegion.identEnd - wordRegion.identStart);
final List<DBSObjectReference> references = this.contextInformer.getObjectReferences();
IHyperlink[] links = new IHyperlink[references.size()];
for (int i = 0, objectsSize = references.size(); i < objectsSize; i++) {
links[i] = new EntityHyperlink(contextInformer.getEditor().getSite(), references.get(i), hlRegion);
}
return links;
}
}
Aggregations