blob: 79e894aa37bef9d509b5c3a408c7b8166e35b5c8 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.core;
import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.JavaModelException;
/**
* Common functionality for Binary member handles.
*/
public abstract class BinaryMember extends NamedMember {
/*
* Constructs a binary member.
*/
protected BinaryMember(JavaElement parent, String name) {
super(parent, name);
}
/*
* @see ISourceManipulation
*/
public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
}
/*
* @see JavaElement#generateInfos
*/
protected void generateInfos(Object info, HashMap newElements, IProgressMonitor pm) throws JavaModelException {
Openable openableParent = (Openable)getOpenableParent();
if (openableParent == null) return;
ClassFileInfo openableParentInfo = (ClassFileInfo) JavaModelManager.getJavaModelManager().getInfo(openableParent);
if (openableParentInfo == null) {
openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
openableParentInfo = (ClassFileInfo)newElements.get(openableParent);
}
if (openableParentInfo == null) return;
openableParentInfo.getBinaryChildren(newElements); // forces the initialization
}
public String getKey() {
try {
return getKey(false/*don't open*/);
} catch (JavaModelException e) {
// happen only if force open is true
return null;
}
}
/**
* @see org.eclipse.jdt.internal.compiler.lookup.Binding#computeUniqueKey()
*/
public abstract String getKey(boolean forceOpen) throws JavaModelException;
/*
* @see ISourceReference
*/
public ISourceRange getNameRange() throws JavaModelException {
SourceMapper mapper= getSourceMapper();
if (mapper != null) {
// ensure the class file's buffer is open so that source ranges are computed
((ClassFile)getClassFile()).getBuffer();
return mapper.getNameRange(this);
} else {
return SourceMapper.fgUnknownRange;
}
}
/*
* @see ISourceReference
*/
public ISourceRange getSourceRange() throws JavaModelException {
SourceMapper mapper= getSourceMapper();
if (mapper != null) {
// ensure the class file's buffer is open so that source ranges are computed
((ClassFile)getClassFile()).getBuffer();
return mapper.getSourceRange(this);
} else {
return SourceMapper.fgUnknownRange;
}
}
/*
* @see IMember
*/
public boolean isBinary() {
return true;
}
/*
* @see IJavaElement
*/
public boolean isStructureKnown() throws JavaModelException {
return ((IJavaElement)getOpenableParent()).isStructureKnown();
}
/*
* @see ISourceManipulation
*/
public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, IProgressMonitor monitor) throws JavaModelException {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
}
/*
* @see ISourceManipulation
*/
public void rename(String newName, boolean force, IProgressMonitor monitor) throws JavaModelException {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
}
/*
* Sets the contents of this element.
* Throws an exception as this element is read only.
*/
public void setContents(String contents, IProgressMonitor monitor) throws JavaModelException {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
}
}