/*******************************************************************************
 * Copyright (c) 2018 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.boot.java.links;

import java.nio.file.Path;
import java.util.Optional;

import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.util.LspClient;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;

/**
 * Factory for creating {@link SourceLinks}
 *
 * @author Alex Boyko
 *
 */
public final class SourceLinkFactory {

	public static final SourceLinks NO_SOURCE_LINKS = new SourceLinks() {

		@Override
		public Optional<String> sourceLinkUrlForFQName(IJavaProject project, String fqName) {
			return Optional.empty();
		}

		@Override
		public Optional<String> sourceLinkUrlForClasspathResource(IJavaProject project, String path) {
			return Optional.empty();
		}

		@Override
		public Optional<String> sourceLinkForResourcePath(Path path) {
			return Optional.empty();
		}

	};

	/**
	 * Creates {@link SourceLinks} for specific server based on client type
	 * @param server the boot LS
	 * @return appropriate source links object
	 */
	public static SourceLinks createSourceLinks(SimpleLanguageServer server, CompilationUnitCache cuCache) {
		switch (LspClient.currentClient()) {
		case VSCODE:
			return /*new VSCodeSourceLinks(cuCache);*/new JavaServerSourceLinks(server);
		case THEIA:
			return new VSCodeSourceLinks(cuCache);
		case ECLIPSE:
			return /*new EclipseSourceLinks();*/new JavaServerSourceLinks(server);
		case ATOM:
			return new AtomSourceLinks(cuCache);
		default:
			return NO_SOURCE_LINKS;
		}

	}

	@Deprecated
	public static SourceLinks createSourceLinks(BootJavaLanguageServerComponents server) {
		return server == null
				? createSourceLinks(null, (CompilationUnitCache)null)
				: createSourceLinks(server.getServer(), server.getCompilationUnitCache());
	}
}

/*******************************************************************************
 * Copyright (c) 2018 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.boot.java.links;

import java.nio.file.Path;
import java.util.Optional;

import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.util.LspClient;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;

/**
 * Factory for creating {@link SourceLinks}
 *
 * @author Alex Boyko
 *
 */
public final class SourceLinkFactory {

	public static final SourceLinks NO_SOURCE_LINKS = new SourceLinks() {

		@Override
		public Optional<String> sourceLinkUrlForFQName(IJavaProject project, String fqName) {
			return Optional.empty();
		}

		@Override
		public Optional<String> sourceLinkUrlForClasspathResource(IJavaProject project, String path) {
			return Optional.empty();
		}

		@Override
		public Optional<String> sourceLinkForResourcePath(Path path) {
			return Optional.empty();
		}

	};

	/**
	 * Creates {@link SourceLinks} for specific server based on client type
	 * @param server the boot LS
	 * @return appropriate source links object
	 */
	public static SourceLinks createSourceLinks(SimpleLanguageServer server, CompilationUnitCache cuCache) {
		switch (LspClient.currentClient()) {
		case VSCODE:
			return /*new VSCodeSourceLinks(cuCache);*/server == null ? new VSCodeSourceLinks(cuCache) :new  JavaServerSourceLinks(server);
		case THEIA:
			return new VSCodeSourceLinks(cuCache);
		case ECLIPSE:
			return /*new EclipseSourceLinks();*/server == null ? new EclipseSourceLinks() : new JavaServerSourceLinks(server);
		case ATOM:
			return new AtomSourceLinks(cuCache);
		default:
			return NO_SOURCE_LINKS;
		}

	}

	@Deprecated
	public static SourceLinks createSourceLinks(BootJavaLanguageServerComponents server) {
		return server == null
				? createSourceLinks(null, (CompilationUnitCache)null)
				: createSourceLinks(server.getServer(), server.getCompilationUnitCache());
	}
}

Fix regression for properties editor CA docs