blob: 0d0a860435de663ef79552054e46aaba3b24ce86 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2018 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.internal.r.rdata;
import org.eclipse.jface.text.IRegion;
import org.eclipse.statet.ltk.model.core.elements.IModelElement;
import org.eclipse.statet.ltk.model.core.elements.ISourceUnit;
import org.eclipse.statet.r.core.data.ICombinedRElement;
import org.eclipse.statet.r.core.model.RElementName;
import org.eclipse.statet.r.core.model.RModel;
import org.eclipse.statet.rj.data.RList;
import org.eclipse.statet.rj.data.RObject;
public abstract class CombinedElement implements ICombinedRElement {
private final CombinedElement fParent;
private RElementName fElementName;
protected CombinedElement(final CombinedElement parent, final RElementName name) {
fParent = parent;
fElementName = name;
}
@Override
public RList getAttributes() {
return null;
}
@Override
public String getModelTypeId() {
return RModel.R_TYPE_ID;
}
@Override
public String getId() {
return null; // not yet implemented
}
@Override
public final RElementName getElementName() {
return fElementName;
}
/** Internal **/
public final void setElementName(final RElementName name) {
fElementName = name;
}
@Override
public boolean exists() {
return true;
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public final CombinedElement getModelParent() {
return fParent;
}
@Override
public ISourceUnit getSourceUnit() {
return null;
}
@Override
public IRegion getSourceRange() {
return null;
}
@Override
public IRegion getNameSourceRange() {
return null;
}
@Override
public IRegion getDocumentationRange() {
return null;
}
@Override
@SuppressWarnings("unchecked")
public <T> T getAdapter(final Class<T> adapterType) {
if (adapterType == IModelElement.class) {
return (T) this;
}
if (adapterType == RObject.class) {
return (T) this;
}
return null;
}
@Override
public final int hashCode() {
if (fParent != null) {
return singleHash()-fParent.singleHash();
}
return singleHash();
}
protected int singleHash() {
return getElementName().hashCode();
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof CombinedElement)) {
return false;
}
final ICombinedRElement other = (ICombinedRElement) obj;
return (getElementName().equals(other.getElementName())
&& ((fParent != null) ? fParent.equals(other.getModelParent()) : (other.getModelParent() == null)) );
}
}