mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
The method ICElement.getResource() do not throw an Exception.
This commit is contained in:
parent
70725d89a4
commit
216ade4221
10 changed files with 30 additions and 50 deletions
|
@ -255,7 +255,7 @@ public interface ICElement extends IAdaptable {
|
|||
* @exception CModelException if this element does not exist or if an
|
||||
* exception occurs while accessing its resource
|
||||
*/
|
||||
IResource getResource() throws CModelException;
|
||||
IResource getResource() ;
|
||||
/**
|
||||
* Returns whether this C element is read-only. An element is read-only
|
||||
* if its structure cannot be modified by the C model.
|
||||
|
|
|
@ -13,8 +13,7 @@ package org.eclipse.cdt.internal.core.model;
|
|||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.internal.core.util.LRUCache;
|
||||
|
@ -95,17 +94,13 @@ public class BufferManager implements IBufferFactory {
|
|||
*/
|
||||
public IBuffer createBuffer(IOpenable owner) {
|
||||
ICElement element = (ICElement)owner;
|
||||
try{
|
||||
IResource resource = element.getResource();
|
||||
return
|
||||
new Buffer(
|
||||
resource instanceof IFile ? (IFile)resource : null,
|
||||
owner,
|
||||
element.isReadOnly());
|
||||
}
|
||||
catch (CModelException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IResource resource = element.getResource();
|
||||
return
|
||||
new Buffer(
|
||||
resource instanceof IFile ? (IFile)resource : null,
|
||||
owner,
|
||||
element.isReadOnly());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,10 +6,10 @@ package org.eclipse.cdt.internal.core.model;
|
|||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ICModel;
|
||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IOpenable;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -79,12 +79,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
}
|
||||
|
||||
public boolean exists() {
|
||||
try {
|
||||
return getResource() != null;
|
||||
} catch (CModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
return getResource() != null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly () {
|
||||
|
@ -163,7 +158,7 @@ public abstract class CElement extends PlatformObject implements ICElement {
|
|||
|
||||
public abstract IResource getUnderlyingResource() throws CModelException;
|
||||
|
||||
public abstract IResource getResource() throws CModelException;
|
||||
public abstract IResource getResource() ;
|
||||
|
||||
protected abstract CElementInfo createElementInfo();
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class CFile extends CElement implements ICFile {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.model.ICElement#getResource()
|
||||
*/
|
||||
public IResource getResource() throws CModelException {
|
||||
public IResource getResource() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
|
@ -223,13 +223,10 @@ public class CModelManager implements IResourceChangeListener {
|
|||
if (parent instanceof CElement) {
|
||||
ICElement[] children = ((CElement)parent).getElementInfo().getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
try {
|
||||
IResource res = children[i].getResource();
|
||||
if (res != null && res.equals(file)) {
|
||||
cfile = children[i];
|
||||
break;
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
IResource res = children[i].getResource();
|
||||
if (res != null && res.equals(file)) {
|
||||
cfile = children[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,16 +127,12 @@ public class CommitWorkingCopyOperation extends CModelOperation {
|
|||
return new CModelStatus(ICModelStatusConstants.INVALID_ELEMENT_TYPES, wc);
|
||||
}
|
||||
|
||||
try {
|
||||
ITranslationUnit original= (ITranslationUnit)wc.getOriginalElement();
|
||||
IResource resource = original.getResource();
|
||||
if (!wc.isBasedOn(resource) && !fForce) {
|
||||
return new CModelStatus(ICModelStatusConstants.UPDATE_CONFLICT);
|
||||
}
|
||||
} catch (CModelException e){
|
||||
// unable to get the underlying resource
|
||||
return new CModelStatus(ICModelStatusConstants.INVALID_RESOURCE);
|
||||
ITranslationUnit original= (ITranslationUnit)wc.getOriginalElement();
|
||||
IResource resource = original.getResource();
|
||||
if (!wc.isBasedOn(resource) && !fForce) {
|
||||
return new CModelStatus(ICModelStatusConstants.UPDATE_CONFLICT);
|
||||
}
|
||||
|
||||
// no read-only check, since some repository adapters can change the flag on save
|
||||
// operation.
|
||||
return CModelStatus.VERIFIED_OK;
|
||||
|
|
|
@ -49,7 +49,7 @@ public abstract class Openable extends Parent implements IOpenable, IBufferChang
|
|||
return res;
|
||||
}
|
||||
|
||||
public IResource getResource() throws CModelException {
|
||||
public IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public abstract class Parent extends CElement implements IParent {
|
|||
return resource;
|
||||
}
|
||||
|
||||
public IResource getResource() throws CModelException {
|
||||
public IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class SourceManipulation extends Parent implements ISourceManipulation, I
|
|||
return getParent().getUnderlyingResource();
|
||||
}
|
||||
|
||||
public IResource getResource() throws CModelException {
|
||||
public IResource getResource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,12 +141,9 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
|||
}
|
||||
|
||||
protected IFile getFile() {
|
||||
try {
|
||||
IResource res = getResource();
|
||||
if (res instanceof IFile) {
|
||||
return (IFile)res;
|
||||
}
|
||||
} catch (CModelException e) {
|
||||
IResource res = getResource();
|
||||
if (res instanceof IFile) {
|
||||
return (IFile)res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue