blob: 7b97cbba876795db579df55500de7ecc04e59038 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 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.runtime.IProgressMonitor;
import org.eclipse.statet.ltk.ast.core.AstInfo;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnit;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnitModelInfo;
/**
* {@link GenericSourceUnitWorkingCopy} plus:
* <ul>
* <li>Support for {@link SourceUnitModelContainer}</li>
* </ul>
*
* @param <M>
*/
public abstract class GenericSourceUnitWorkingCopy2<M extends SourceUnitModelContainer<? extends ISourceUnit, ? extends ISourceUnitModelInfo>>
extends GenericSourceUnitWorkingCopy {
private final M model;
public GenericSourceUnitWorkingCopy2(final ISourceUnit from) {
super(from);
this.model= createModelContainer();
}
protected abstract M createModelContainer();
protected final M getModelContainer() {
return this.model;
}
@Override
protected void unregister() {
super.unregister();
// this.model.clear();
}
@Override
public AstInfo getAstInfo(final String type, final boolean ensureSync,
final IProgressMonitor monitor) {
if (type == null || this.model.isContainerFor(type)) {
return this.model.getAstInfo(ensureSync, monitor);
}
return null;
}
@Override
public ISourceUnitModelInfo getModelInfo(final String type, final int flags,
final IProgressMonitor monitor) {
if (type == null || this.model.isContainerFor(type)) {
return this.model.getModelInfo(flags, monitor);
}
return null;
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(final Class<T> adapterType) {
if (adapterType == this.model.getAdapterClass()) {
return (T) this.model;
}
return super.getAdapter(adapterType);
}
}