blob: d195a4d252fd4c9d43d5cd74d0628d830f93e1ae [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2020 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.ltk.model.core.impl;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.statet.ecommons.text.ISourceFragment;
import org.eclipse.statet.ltk.core.LTK;
import org.eclipse.statet.ltk.model.core.ISourceUnitFactory;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnit;
import org.eclipse.statet.ltk.model.core.elements.IWorkspaceSourceUnit;
/**
* Abstract factory for {@link LTK#EDITOR_CONTEXT}.
*/
public abstract class AbstractEditorSourceUnitFactory implements ISourceUnitFactory {
@Override
public String createId(final Object from) {
if (from instanceof IFileStore) {
return AbstractFilePersistenceSourceUnitFactory.createResourceId(((IFileStore) from).toURI());
}
if (from instanceof ISourceFragment) {
return ((ISourceFragment) from).getId();
}
return null;
}
@Override
public ISourceUnit createSourceUnit(final String id, final Object from) {
if (from instanceof IWorkspaceSourceUnit) {
return createSourceUnit(id, (IWorkspaceSourceUnit) from);
}
if (from instanceof IFileStore) {
return createSourceUnit(id, (IFileStore) from);
}
if (from instanceof ISourceFragment) {
return createSourceUnit(id, (ISourceFragment) from);
}
return null;
}
protected abstract ISourceUnit createSourceUnit(final String id, final IWorkspaceSourceUnit su);
protected abstract ISourceUnit createSourceUnit(final String id, final IFileStore file);
protected ISourceUnit createSourceUnit(final String id, final ISourceFragment fragment) {
return null;
}
}