diff options
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model')
111 files changed, 0 insertions, 18641 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java deleted file mode 100644 index 56d682e9fa5..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/APathEntry.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public abstract class APathEntry extends PathEntry { - - public static IPath[] NO_EXCLUSION_PATTERNS = {}; - IPath[] exclusionPatterns; - IPath basePath; - IPath baseRef; - private final static char[][] UNINIT_PATTERNS = new char[][] { "Non-initialized yet".toCharArray() }; //$NON-NLS-1$ - char[][]fullCharExclusionPatterns = UNINIT_PATTERNS; - - /** - * - * @param kind - * @param basePath - * @param baseRef - * @param path - * @param exclusionPatterns - * @param isExported - */ - public APathEntry (int kind, IPath basePath, IPath baseRef, IPath path, IPath[] exclusionPatterns, boolean isExported) { - super(kind, path, isExported); - this.basePath = (basePath == null) ? Path.EMPTY : basePath; - this.baseRef = (baseRef == null) ? Path.EMPTY : baseRef; - this.exclusionPatterns = (exclusionPatterns == null) ? NO_EXCLUSION_PATTERNS : exclusionPatterns; - } - - /** - * Returns the exclusion patterns - * @return IPath[] - */ - public IPath[] getExclusionPatterns() { - return exclusionPatterns; - } - - /** - * Returns the base Path - * @return IPath - */ - public IPath getBasePath() { - return basePath; - } - - /** - * - * @return - */ - public IPath getBaseReference() { - return baseRef; - } - - /** - * Returns a char based representation of the exclusions patterns full path. - */ - public char[][] fullExclusionPatternChars() { - if (this.fullCharExclusionPatterns == UNINIT_PATTERNS) { - int length = this.exclusionPatterns.length; - this.fullCharExclusionPatterns = new char[length][]; - IPath prefixPath = this.path.removeTrailingSeparator(); - for (int i = 0; i < length; i++) { - this.fullCharExclusionPatterns[i] = - prefixPath.append(this.exclusionPatterns[i]).toString().toCharArray(); - } - } - return this.fullCharExclusionPatterns; - } - - public boolean equals(Object obj) { - if (obj instanceof APathEntry) { - APathEntry otherEntry = (APathEntry)obj; - if (!super.equals(otherEntry)) { - return false; - } - IPath[] otherExcludes = otherEntry.getExclusionPatterns(); - if (exclusionPatterns != otherExcludes) { - int excludeLength = (exclusionPatterns == null) ? 0 : exclusionPatterns.length; - if (otherExcludes.length != excludeLength) { - return false; - } - for (int i = 0; i < excludeLength; i++) { - // compare toStrings instead of IPaths - // since IPath.equals is specified to ignore trailing separators - String myPattern = exclusionPatterns[i].toString(); - if (!myPattern.equals(otherExcludes[i].toString())) { - return false; - } - } - } - IPath otherBasePath = otherEntry.getBasePath(); - if (basePath != null) { - if (otherBasePath != null && !basePath.equals(otherBasePath)) { - return false; - } - } - IPath otherBaseRef = otherEntry.getBaseReference(); - if (baseRef != null) { - if (otherBaseRef != null && !baseRef.equals(otherBaseRef)) { - return false; - } - } - return true; - } - return super.equals(obj); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(super.toString()); - if (basePath != null && !basePath.isEmpty()) { - sb.append(" base-path:").append(basePath.toString()); //$NON-NLS-1$ - } - if (baseRef != null && !baseRef.isEmpty()) { - sb.append(" base-ref:").append(baseRef.toString()); //$NON-NLS-1$ - } - return sb.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java deleted file mode 100644 index cac67a4a9d6..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.Map; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IArchive; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -public class Archive extends Openable implements IArchive { - - IBinaryArchive binaryArchive; - - public Archive(ICElement parent, IFile file, IBinaryArchive ar) { - this(parent, file.getLocation(), ar); - } - - public Archive(ICElement parent, IPath path, IBinaryArchive ar) { - super (parent, path, ICElement.C_ARCHIVE); - binaryArchive = ar; - } - - public IBinary[] getBinaries() throws CModelException { - ICElement[] e = getChildren(); - IBinary[] b = new IBinary[e.length]; - System.arraycopy(e, 0, b, 0, e.length); - return b; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#isReadOnly() - */ - public boolean isReadOnly() { - return true; - } - - public CElementInfo createElementInfo() { - return new ArchiveInfo(this); - } - - protected ArchiveInfo getArchiveInfo() throws CModelException { - return (ArchiveInfo)getElementInfo(); - } - - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) - throws CModelException { - return computeChildren(info, underlyingResource); - } - - public boolean computeChildren(OpenableInfo info, IResource res) { - IBinaryArchive ar = getBinaryArchive(); - if (ar != null) { - IBinaryObject[] objects = ar.getObjects(); - for (int i = 0; i < objects.length; i++) { - final IBinaryObject obj = objects[i]; - Binary binary = new Binary(this, ar.getPath().append(obj.getName()), obj); - info.addChild(binary); - } - } else { - return false; - } - return true; - } - - IBinaryArchive getBinaryArchive() { - return binaryArchive; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - return getResource() != null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) - */ - protected void closing(Object info) throws CModelException { - ICProject cproject = getCProject(); - CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(cproject); - if (pinfo != null && pinfo.vLib != null) { - pinfo.vLib.removeChild(this); - } - super.closing(info); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java deleted file mode 100644 index 7d346ab4e78..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.Map; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IArchive; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; - -public class ArchiveContainer extends Openable implements IArchiveContainer { - - public ArchiveContainer (CProject cProject) { - super (cProject, null, CCorePlugin.getResourceString("CoreModel.ArchiveContainer.Archives"), CElement.C_VCONTAINER); //$NON-NLS-1$ - } - - public IArchive[] getArchives() throws CModelException { - ((ArchiveContainerInfo)getElementInfo()).sync(); - ICElement[] e = getChildren(); - IArchive[] a = new IArchive[e.length]; - System.arraycopy(e, 0, a, 0, e.length); - return a; - } - - public CElementInfo createElementInfo() { - return new ArchiveContainerInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) - throws CModelException { - // this will bootstrap/start the runner for the project. - CModelManager.getDefault().getBinaryRunner(getCProject(), true); - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java deleted file mode 100644 index 1ef8a5713cc..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; - - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - */ -public class ArchiveContainerInfo extends OpenableInfo { - - /** - * Constructs a new C Model Info - */ - protected ArchiveContainerInfo(CElement element) { - super(element); - } - - synchronized void sync() { - BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject(), true); - if (runner != null) { - runner.waitIfRunning(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElementInfo#addChild(org.eclipse.cdt.core.model.ICElement) - */ - protected void addChild(ICElement child) { - if (!includesChild(child)) { - super.addChild(child); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java deleted file mode 100644 index 591521636ad..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - - -/** - * Info for ICProject. - */ - -class ArchiveInfo extends OpenableInfo { - - /** - */ - public ArchiveInfo(CElement element) { - super(element); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java deleted file mode 100644 index dcc13bb615e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BatchOperation.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 Rational Software Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.CModelException; - -/** - * An operation created as a result of a call to JavaCore.run(IWorkspaceRunnable, IProgressMonitor) - * that encapsulates a user defined IWorkspaceRunnable. - */ -public class BatchOperation extends CModelOperation { - protected IWorkspaceRunnable runnable; - public BatchOperation(IWorkspaceRunnable runnable) { - this.runnable = runnable; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation() - */ - protected void executeOperation() throws CModelException { - try { - this.runnable.run(fMonitor); - } catch (CoreException ce) { - if (ce instanceof CModelException) { - throw (CModelException)ce; - } else { - if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) { - Throwable e= ce.getStatus().getException(); - if (e instanceof CModelException) { - throw (CModelException) e; - } - } - throw new CModelException(ce); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.core.JavaModelOperation#verify() - */ - protected ICModelStatus verify() { - // cannot verify user defined operation - return CModelStatus.VERIFIED_OK; - } - - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java deleted file mode 100644 index c60a926c4b7..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java +++ /dev/null @@ -1,376 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.IBinaryParser.IBinaryShared; -import org.eclipse.cdt.core.IBinaryParser.ISymbol; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBuffer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -public class Binary extends Openable implements IBinary { - - private int fBinType; - private String hasDebug; - private String cpu; - private String[] needed; - private long longData; - private long longText; - private long longBSS; - private String endian; - private String soname; - - private long fLastModification; - - IBinaryObject binaryObject; - - public Binary(ICElement parent, IFile file, IBinaryObject bin) { - super(parent, file, ICElement.C_BINARY); - binaryObject = bin; - } - - public Binary(ICElement parent, IPath path, IBinaryObject bin) { - super (parent, path, ICElement.C_BINARY); - binaryObject = bin; - } - - public boolean isSharedLib() { - return getType() == IBinaryObject.SHARED; - } - - public boolean isExecutable() { - return getType() == IBinaryObject.EXECUTABLE; - } - - public boolean isObject() { - return getType() == IBinaryObject.OBJECT; - } - - public boolean isCore() { - return getType() == IBinaryObject.CORE; - } - - public boolean hasDebug() { - if (isObject() || isExecutable() || isSharedLib()) { - if (hasDebug == null || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - hasDebug = new Boolean(obj.hasDebug()).toString(); - } - } - } - return Boolean.valueOf(hasDebug).booleanValue(); - } - - public String getCPU() { - if (isObject() || isExecutable() || isSharedLib() || isCore()) { - if (cpu == null || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - cpu = obj.getCPU(); - } - } - return (cpu == null ? "" : cpu); //$NON-NLS-1$ - } - - public String[] getNeededSharedLibs() { - if (isExecutable() || isSharedLib()) { - if (needed == null || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj instanceof IBinaryExecutable) { - needed = ((IBinaryExecutable)obj).getNeededSharedLibs(); - } - } - } - return (needed == null ? new String[0] : needed); - } - - public long getText() { - if (isObject() || isExecutable() || isSharedLib()) { - if (longText == -1 || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - longText = obj.getText(); - } - } - } - return longText; - } - - public long getData() { - if (isObject() || isExecutable() || isSharedLib()) { - if (longData == -1 || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - longData = obj.getData(); - } - } - } - return longData; - } - - public long getBSS() { - if (isObject() || isExecutable() || isSharedLib()) { - if (longBSS == -1 || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - longBSS = obj.getBSS(); - } - } - } - return longBSS; - } - - public String getSoname() { - if (isSharedLib()) { - if (soname == null || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj instanceof IBinaryShared) { - soname = ((IBinaryShared)obj).getSoName(); - } - } - } - return (soname == null ? "" : soname); //$NON-NLS-1$ - } - - public boolean isLittleEndian() { - if (isObject() || isExecutable() || isSharedLib() || isCore()) { - if (endian == null || hasChanged()) { - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - endian = new Boolean(obj.isLittleEndian()).toString(); - } - } - } - return Boolean.valueOf(endian).booleanValue(); - } - - protected IBinaryObject getBinaryObject() { - return binaryObject; - } - - protected int getType() { - IBinaryObject obj = getBinaryObject(); - if (obj != null && (fBinType == 0 || hasChanged())) { - fBinType = obj.getType(); - } - return fBinType; - } - - protected boolean hasChanged() { - long modification = getModificationStamp(); - boolean changed = modification != fLastModification; - fLastModification = modification; - if (changed) { - hasDebug = null; - needed = null; - cpu = null; - endian = null; - longBSS = -1; - longData = -1; - longText = -1; - soname = null; - } - return changed; - } - - protected long getModificationStamp() { - IResource res = getResource(); - if (res != null) { - return res.getModificationStamp(); - } - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#isReadOnly() - */ - public boolean isReadOnly() { - return true; - } - - public CElementInfo createElementInfo() { - return new BinaryInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) - throws CModelException { - return computeChildren(info, underlyingResource); - } - - boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { - boolean ok = false; - if (isObject() || isExecutable() || isSharedLib()) { - Map hash = new HashMap(); - IBinaryObject obj = getBinaryObject(); - if (obj != null) { - ISymbol[] symbols = obj.getSymbols(); - for (int i = 0; i < symbols.length; i++) { - switch (symbols[i].getType()) { - case ISymbol.FUNCTION : - addFunction(info, symbols[i], hash); - break; - - case ISymbol.VARIABLE : - addVariable(info, symbols[i], hash); - break; - } - } - ok = true; - } - } - return ok; - } - - private void addFunction(OpenableInfo info, ISymbol symbol, Map hash) throws CModelException { - IPath filename = filename = symbol.getFilename(); - BinaryFunction function = null; - - if (filename != null && !filename.isEmpty()) { - BinaryModule module = null; - if (hash.containsKey(filename)) { - module = (BinaryModule)hash.get(filename); - } else { - // A special container we do not want the file to be parse. - module = new BinaryModule(this, filename); - hash.put(filename, module); - info.addChild(module); - } - function = new BinaryFunction(module, symbol.getName(), symbol.getAddress()); - function.setLines(symbol.getStartLine(), symbol.getEndLine()); - module.addChild(function); - } else { - //function = new Function(parent, symbol.getName()); - function = new BinaryFunction(this, symbol.getName(), symbol.getAddress()); - function.setLines(symbol.getStartLine(), symbol.getEndLine()); - info.addChild(function); - } - // if (function != null) { - // if (!external) { - // function.getFunctionInfo().setAccessControl(IConstants.AccStatic); - // } - // } - } - - private void addVariable(OpenableInfo info, ISymbol symbol, Map hash) throws CModelException { - IPath filename = filename = symbol.getFilename(); - BinaryVariable variable = null; - if (filename != null) { - BinaryModule module = null; - if (hash.containsKey(filename)) { - module = (BinaryModule)hash.get(filename); - } else { - module = new BinaryModule(this, filename); - hash.put(filename, module); - info.addChild(module); - } - variable = new BinaryVariable(module, symbol.getName(), symbol.getAddress()); - variable.setLines(symbol.getStartLine(), symbol.getEndLine()); - module.addChild(variable); - } else { - variable = new BinaryVariable(this, symbol.getName(), symbol.getAddress()); - variable.setLines(symbol.getStartLine(), symbol.getEndLine()); - info.addChild(variable); - } - - //if (variable != null) { - // if (!external) { - // variable.getVariableInfo().setAccessControl(IConstants.AccStatic); - // } - //} - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - - // create buffer - translation units only use default buffer factory - BufferManager bufManager = getBufferManager(); - IBuffer buffer = getBufferFactory().createBuffer(this); - if (buffer == null) - return null; - - // set the buffer source - if (buffer.getCharacters() == null){ - IBinaryObject bin = getBinaryObject(); - if (bin != null) { - StringBuffer sb = new StringBuffer(); - try { - BufferedReader stream = new BufferedReader(new InputStreamReader(bin.getContents())); - char[] buf = new char[512]; - int len; - while ((len = stream.read(buf, 0, buf.length)) != -1) { - sb.append(buf, 0, len); - } - } catch (IOException e) { - // nothint. - } - buffer.setContents(sb.toString()); - } else { - IResource file = this.getResource(); - if (file != null && file.getType() == IResource.FILE) { - buffer.setContents(Util.getResourceContentsAsCharArray((IFile)file)); - } - } - } - - // add buffer to buffer cache - bufManager.addBuffer(buffer); - - // listen to buffer changes - // buffer.addBufferChangedListener(this); - - return buffer; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#hasBuffer() - */ - protected boolean hasBuffer() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - return getResource() != null; - } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) - */ - protected void closing(Object info) throws CModelException { - ICProject cproject = getCProject(); - CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(cproject); - if (pinfo != null && pinfo.vBin != null) { - pinfo.vBin.removeChild(this); - } - super.closing(info); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java deleted file mode 100644 index 631ab2133a2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.ArrayList; -import java.util.Map; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; - -public class BinaryContainer extends Openable implements IBinaryContainer { - - public BinaryContainer (CProject cProject) { - super (cProject, null, CCorePlugin.getResourceString("CoreModel.BinaryContainer.Binaries"), CElement.C_VCONTAINER); //$NON-NLS-1$ - } - - public IBinary[] getBinaries() throws CModelException { - ((BinaryContainerInfo)getElementInfo()).sync(); - ICElement[] e = getChildren(); - ArrayList list = new ArrayList(e.length); - for (int i = 0; i < e.length; i++) { - if (e[i] instanceof IBinary) { - IBinary bin = (IBinary)e[i]; - if (bin.isExecutable() || bin.isSharedLib()) { - list.add(bin); - } - } - } - IBinary[] b = new IBinary[list.size()]; - list.toArray(b); - return b; - } - - public CElementInfo createElementInfo() { - return new BinaryContainerInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) - throws CModelException { - // this will bootstrap/start the runner for the project. - CModelManager.getDefault().getBinaryRunner(getCProject(), true); - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java deleted file mode 100644 index 26716fcc18c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; - - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - */ -public class BinaryContainerInfo extends OpenableInfo { - - /** - * Constructs a new C Model Info - */ - protected BinaryContainerInfo(CElement element) { - super(element); - } - - synchronized void sync() { - BinaryRunner runner = CModelManager.getDefault().getBinaryRunner(getElement().getCProject(), true); - if (runner != null) { - runner.waitIfRunning(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElementInfo#addChild(org.eclipse.cdt.core.model.ICElement) - */ - protected void addChild(ICElement child) { - if (!includesChild(child)) { - super.addChild(child); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java deleted file mode 100644 index 4101adc58d1..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryElement.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -package org.eclipse.cdt.internal.core.model; - -import java.io.IOException; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBinaryElement; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceManipulation; -import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; - -/** - */ -public class BinaryElement extends CElement implements IBinaryElement, ISourceManipulation, ISourceReference { - - long addr; - - public BinaryElement(ICElement parent, String name, int type, long a) { - super(parent, name, type); - addr = a; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#copy(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void copy(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor) - throws CModelException { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void delete(boolean force, IProgressMonitor monitor) throws CModelException { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#move(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void move(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor) - throws CModelException { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void rename(String name, boolean replace, IProgressMonitor monitor) throws CModelException { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceReference#getSource() - */ - public String getSource() throws CModelException { - ITranslationUnit tu = getTranslationUnit(); - if (tu != null) { - try { - IResource res = tu.getResource(); - if (res != null && res instanceof IFile) { - StringBuffer buffer = Util.getContent((IFile)res); - return buffer.substring(getStartPos(), - getStartPos() + getLength()); - } - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } - } - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange() - */ - public ISourceRange getSourceRange() throws CModelException { - return new SourceRange(getStartPos(), - getLength(), - getIdStartPos(), - getIdLength(), - getStartLine(), - getEndLine()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceReference#getTranslationUnit() - */ - public ITranslationUnit getTranslationUnit() { - ITranslationUnit tu = null; - CModelManager mgr = CModelManager.getDefault(); - ICElement parent = getParent(); - if (parent != null) { - IPath path = parent.getPath(); - if (path != null && path.isAbsolute()) { - IResource res = mgr.getCModel().getWorkspace().getRoot().getFileForLocation(path); - if (res != null && res.exists() && res.getType() == IResource.FILE) { - ICElement e = CModelManager.getDefault().create(res, null); - if (e instanceof ITranslationUnit) { - tu = (ITranslationUnit)e; - } - } - } else { - // TODO-model: handle non-absolute paths when finding source files - // ??? assert() - path = new Path(""); //$NON-NLS-1$ - } - // Fall back to the project sourcemapper. - if (tu == null) { - ICProject cproject = getCProject(); - SourceMapper mapper = mgr.getSourceMapper(cproject); - if (mapper != null) { - String lastSegment = path.lastSegment(); - if (lastSegment != null) { - tu = mapper.findTranslationUnit(lastSegment); - } - } - } - } - return tu; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo() - */ - protected CElementInfo createElementInfo() { - return new CElementInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IBinaryElement#getAddress() - */ - public long getAddress() throws CModelException { - return addr; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IBinaryElement#getBinary() - */ - public IBinary getBinary() { - ICElement current = this; - do { - if (current instanceof IBinary) { - return (IBinary) current; - } - } while ((current = current.getParent()) != null); - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#generateInfos(java.lang.Object, java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void generateInfos(Object info, Map newElements, IProgressMonitor monitor) throws CModelException { - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryFunction.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryFunction.java deleted file mode 100644 index aed58f10c93..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryFunction.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IFunction; - -/** - */ -public class BinaryFunction extends BinaryElement implements IFunction { - - public BinaryFunction(ICElement parent, String name, long a) { - super(parent, name, ICElement.C_FUNCTION, a); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getExceptions() - */ - public String[] getExceptions() { - return new String[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getNumberOfParameters() - */ - public int getNumberOfParameters() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getParameterInitializer(int) - */ - public String getParameterInitializer(int pos) { - // TODO Auto-generated method stub - return new String(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getParameterTypes() - */ - public String[] getParameterTypes() { - // TODO Auto-generated method stub - return new String[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getReturnType() - */ - public String getReturnType() { - // TODO Auto-generated method stub - return new String(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IFunctionDeclaration#getSignature() - */ - public String getSignature() { - return getElementName(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isStatic() - */ - public boolean isStatic() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isConst() - */ - public boolean isConst() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile() - */ - public boolean isVolatile() { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java deleted file mode 100644 index e323eee3838..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -class BinaryInfo extends OpenableInfo { - - public BinaryInfo(CElement element) { - super(element); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java deleted file mode 100644 index a47c8284b29..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryModule.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.IBinaryElement; -import org.eclipse.cdt.core.model.IBinaryModule; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - */ -public class BinaryModule extends Parent implements IBinaryModule { - - IPath path; - - public BinaryModule(Binary parent, IPath p) { - super(parent, p.lastSegment(), ICElement.C_VCONTAINER); - path = p; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IBinaryModule#getBinaryElements() - */ - public IBinaryElement[] getBinaryElements() throws CModelException { - ICElement[] e = getChildren(); - IBinaryElement[] b = new IBinaryElement[e.length]; - System.arraycopy(e, 0, b, 0, e.length); - return b; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IBinaryElement#getAddress() - */ - public long getAddress() throws CModelException { - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IBinaryElement#getBinary() - */ - public IBinary getBinary() { - return (IBinary)getParent(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#isReadOnly() - */ - public boolean isReadOnly() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo() - */ - protected CElementInfo createElementInfo() { - return new CElementInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return path; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#generateInfos(java.lang.Object, java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void generateInfos(Object info, Map newElements, IProgressMonitor monitor) throws CModelException { - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java deleted file mode 100644 index 12fb7a82a4d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryRunner.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ElementChangedEvent; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; - -public class BinaryRunner { - - ICProject cproject; - Job runner; - - public BinaryRunner(IProject prj) { - cproject = CModelManager.getDefault().create(prj); - } - - public void start() { - String taskName = CCorePlugin.getResourceString("CoreModel.BinaryRunner.Binary_Search_Thread"); //$NON-NLS-1$ - runner = new Job(taskName) { - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus run(IProgressMonitor monitor) { - if (cproject == null || monitor.isCanceled()) { - return Status.CANCEL_STATUS; - } - try { - BinaryContainer vbin = (BinaryContainer) cproject.getBinaryContainer(); - ArchiveContainer vlib = (ArchiveContainer) cproject.getArchiveContainer(); - - vlib.removeChildren(); - vbin.removeChildren(); - cproject.getProject().accept(new Visitor(BinaryRunner.this, monitor)); - fireEvents(cproject, vbin); - fireEvents(cproject, vlib); - } catch (CoreException e) { - return e.getStatus(); - } - return Status.OK_STATUS; - } - }; - runner.schedule(); - - } - - /** - * wrap the wait call and the interrupteException. - */ - public void waitIfRunning() { - if (runner != null) { - try { - runner.join(); - } catch (InterruptedException e) { - } - } - } - - public void stop() { - if (runner != null && runner.getState() == Job.RUNNING) { - runner.cancel(); - } - } - - void fireEvents(ICProject cproject, Parent container) { - // Fired the event. - try { - ICElement[] children = container.getChildren(); - if (children.length > 0) { - CModelManager factory = CModelManager.getDefault(); - ICElement root = factory.getCModel(); - CElementDelta cdelta = new CElementDelta(root); - cdelta.added(cproject); - cdelta.added(container); - for (int i = 0; i < children.length; i++) { - cdelta.added(children[i]); - } - factory.registerCModelDelta(cdelta); - factory.fire(ElementChangedEvent.POST_CHANGE); - } - } catch (CModelException e) { - // - } - } - - void addChildIfBinary(IFile file) { - CModelManager factory = CModelManager.getDefault(); - // Attempt to speed things up by rejecting up front - // Things we know should not be Binary files. - if (!CoreModel.isTranslationUnit(file)) { - IBinaryFile bin = factory.createBinaryFile(file); - if (bin != null) { - // Create the file will add it to the {Archive,Binary}Containery. - factory.create(file, bin, null); - } - } - } - - class Visitor implements IResourceVisitor { - - private BinaryRunner vRunner; - private IProgressMonitor vMonitor; - - public Visitor(BinaryRunner r, IProgressMonitor monitor) { - vRunner = r; - vMonitor = monitor; - } - - public boolean visit(IResource res) throws CoreException { - if (vMonitor.isCanceled()) { - return false; - } - if (cproject.isOnOutputEntry(res)) { - if (res instanceof IFile) { - if (vRunner != null) { - vRunner.addChildIfBinary((IFile) res); - } - return false; - } - } - return true; - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryVariable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryVariable.java deleted file mode 100644 index 070fc2a2b92..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryVariable.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IVariable; - -/** - * - */ -public class BinaryVariable extends BinaryElement implements IVariable { - - public BinaryVariable(ICElement parent, String name, long a) { - super(parent, name, ICElement.C_VARIABLE, a); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IVariable#getInitializer() - */ - public String getInitializer() { - // TODO Auto-generated method stub - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName() - */ - public String getTypeName() { - // TODO Auto-generated method stub - return ""; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String) - */ - public void setTypeName(String type) { - // TODO Auto-generated method stub - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isStatic() - */ - public boolean isStatic() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isConst() - */ - public boolean isConst() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile() - */ - public boolean isVolatile() { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java deleted file mode 100644 index 03d132349f5..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Buffer.java +++ /dev/null @@ -1,464 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; - -import org.eclipse.cdt.core.ICLogConstants; -import org.eclipse.cdt.core.model.BufferChangedEvent; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBuffer; -import org.eclipse.cdt.core.model.IBufferChangedListener; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.IOpenable; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.Platform; - -/** - * @see IBuffer - * This class is similar to the JDT Buffer class. - */ -public class Buffer implements IBuffer { - protected IFile file; - protected int flags; - protected char[] contents; - protected ArrayList changeListeners; - protected IOpenable owner; - protected int gapStart= -1; - protected int gapEnd= -1; - - protected Object lock= new Object(); - - protected static final int F_HAS_UNSAVED_CHANGES= 1; - protected static final int F_IS_READ_ONLY= 2; - protected static final int F_IS_CLOSED= 4; - /** - * Creates a new buffer on an underlying resource. - */ - protected Buffer(IFile file, IOpenable owner, boolean readOnly) { - this.file = file; - this.owner = owner; - if (file == null) { - setReadOnly(readOnly); - } - } - - /** - * @see IBuffer - */ - public void addBufferChangedListener(IBufferChangedListener listener) { - if (this.changeListeners == null) { - this.changeListeners = new ArrayList(5); - } - if (!this.changeListeners.contains(listener)) { - this.changeListeners.add(listener); - } - } - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#append(char) - */ - public void append(char[] text) { - if (!isReadOnly()) { - if (text == null || text.length == 0) { - return; - } - int length = getLength(); - moveAndResizeGap(length, text.length); - System.arraycopy(text, 0, this.contents, length, text.length); - this.gapStart += text.length; - this.flags |= F_HAS_UNSAVED_CHANGES; - notifyChanged(new BufferChangedEvent(this, length, 0, new String(text))); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#append(java.lang.String) - */ - public void append(String text) { - if (text == null) { - return; - } - this.append(text.toCharArray()); - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#close() - */ - public void close() { - BufferChangedEvent event = null; - synchronized (this.lock) { - if (isClosed()) - return; - event = new BufferChangedEvent(this, 0, 0, null); - this.contents = null; - this.flags |= F_IS_CLOSED; - } - notifyChanged(event); // notify outside of synchronized block - this.changeListeners = null; - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getChar(int) - */ - public char getChar(int position) { - synchronized (this.lock) { - if (position < this.gapStart) { - return this.contents[position]; - } - int gapLength = this.gapEnd - this.gapStart; - return this.contents[position + gapLength]; - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getCharacters() - */ - public char[] getCharacters() { - if (this.contents == null) return null; - synchronized (this.lock) { - if (this.gapStart < 0) { - return this.contents; - } - int length = this.contents.length; - char[] newContents = new char[length - this.gapEnd + this.gapStart]; - System.arraycopy(this.contents, 0, newContents, 0, this.gapStart); - System.arraycopy(this.contents, this.gapEnd, newContents, this.gapStart, length - this.gapEnd); - return newContents; - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getContents() - */ - public String getContents() { - if (this.contents == null) return null; - return new String(this.getCharacters()); - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getLength() - */ - public int getLength() { - synchronized (this.lock) { - int length = this.gapEnd - this.gapStart; - return (this.contents.length - length); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getOwner() - */ - public IOpenable getOwner() { - return this.owner; - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getText(int, int) - */ - public String getText(int offset, int length) { - if (this.contents == null) - return ""; //$NON-NLS-1$ - synchronized (this.lock) { - if (offset + length < this.gapStart) - return new String(this.contents, offset, length); - if (this.gapStart < offset) { - int gapLength = this.gapEnd - this.gapStart; - return new String(this.contents, offset + gapLength, length); - } - StringBuffer buf = new StringBuffer(); - buf.append(this.contents, offset, this.gapStart - offset); - buf.append(this.contents, this.gapEnd, offset + length - this.gapStart); - return buf.toString(); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#getUnderlyingResource() - */ - public IResource getUnderlyingResource() { - return this.file; - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#hasUnsavedChanges() - */ - public boolean hasUnsavedChanges() { - return (this.flags & F_HAS_UNSAVED_CHANGES) != 0; - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#isClosed() - */ - public boolean isClosed() { - return (this.flags & F_IS_CLOSED) != 0; - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#isReadOnly() - */ - public boolean isReadOnly() { - if (this.file == null) { - return (this.flags & F_IS_READ_ONLY) != 0; - } else { - return this.file.isReadOnly(); - } - } - - /** - * Notify the listeners that this buffer has changed. - * To avoid deadlock, this should not be called in a synchronized block. - */ - protected void notifyChanged(final BufferChangedEvent event) { - if (this.changeListeners != null) { - for (int i = 0, size = this.changeListeners.size(); i < size; ++i) { - final IBufferChangedListener listener = (IBufferChangedListener) this.changeListeners.get(i); - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - Util.log(exception, "Exception occurred in listener of buffer change notification", ICLogConstants.CDT); //$NON-NLS-1$ - } - public void run() throws Exception { - listener.bufferChanged(event); - } - }); - } - } - } - /** - * @see IBuffer - */ - public void removeBufferChangedListener(IBufferChangedListener listener) { - if (this.changeListeners != null) { - this.changeListeners.remove(listener); - if (this.changeListeners.size() == 0) { - this.changeListeners = null; - } - } - } - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#replace(int, int, char) - */ - public void replace(int position, int length, char[] text) { - if (!isReadOnly()) { - int textLength = text == null ? 0 : text.length; - synchronized (this.lock) { - // move gap - moveAndResizeGap(position + length, textLength - length); - - // overwrite - int min = Math.min(textLength, length); - if (min > 0) { - System.arraycopy(text, 0, this.contents, position, min); - } - if (length > textLength) { - // enlarge the gap - this.gapStart -= length - textLength; - } else if (textLength > length) { - // shrink gap - this.gapStart += textLength - length; - System.arraycopy(text, 0, this.contents, position, textLength); - } - } - this.flags |= F_HAS_UNSAVED_CHANGES; - String string = null; - if (textLength > 0) { - string = new String(text); - } - notifyChanged(new BufferChangedEvent(this, position, length, string)); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#replace(int, int, java.lang.String) - */ - public void replace(int position, int length, String text) { - this.replace(position, length, text == null ? null : text.toCharArray()); - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#save(org.eclipse.core.runtime.IProgressMonitor, boolean) - */ - public void save(IProgressMonitor progress, boolean force) - throws CModelException { - // determine if saving is required - if (isReadOnly() || this.file == null) { - return; - } - synchronized (this.lock) { - if (!hasUnsavedChanges()) - return; - - // use a platform operation to update the resource contents - try { - String encoding = null; - try { - encoding = this.file.getCharset(); - } - catch (CoreException ce) { - // use no encoding - } - String contents = this.getContents(); - if (contents == null) return; - byte[] bytes = encoding == null - ? contents.getBytes() - : contents.getBytes(encoding); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - - if (this.file.exists()) { - this.file.setContents( - stream, - force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, - null); - } else { - this.file.create(stream, force, null); - } - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } - catch (CoreException e) { - throw new CModelException(e); - } - - // the resource no longer has unsaved changes - this.flags &= ~ (F_HAS_UNSAVED_CHANGES); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#setContents(char) - */ - public void setContents(char[] newContents) { - // allow special case for first initialization - // after creation by buffer factory - if (this.contents == null) { - this.contents = newContents; - this.flags &= ~ (F_HAS_UNSAVED_CHANGES); - return; - } - - if (!isReadOnly()) { - String string = null; - if (newContents != null) { - string = new String(newContents); - } - BufferChangedEvent event = new BufferChangedEvent(this, 0, this.getLength(), string); - synchronized (this.lock) { - this.contents = newContents; - this.flags |= F_HAS_UNSAVED_CHANGES; - this.gapStart = -1; - this.gapEnd = -1; - } - notifyChanged(event); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBuffer#setContents(java.lang.String) - */ - public void setContents(String newContents) { - this.setContents(newContents.toCharArray()); - } - - /** - * Moves the gap to location and adjust its size to the - * anticipated change size. The size represents the expected - * range of the gap that will be filled after the gap has been moved. - * Thus the gap is resized to actual size + the specified size and - * moved to the given position. - */ - protected void moveAndResizeGap(int position, int size) { - char[] content = null; - int oldSize = this.gapEnd - this.gapStart; - if (size < 0) { - if (oldSize > 0) { - content = new char[this.contents.length - oldSize]; - System.arraycopy(this.contents, 0, content, 0, this.gapStart); - System.arraycopy(this.contents, this.gapEnd, content, this.gapStart, content.length - this.gapStart); - this.contents = content; - } - this.gapStart = this.gapEnd = position; - return; - } - content = new char[this.contents.length + (size - oldSize)]; - int newGapStart = position; - int newGapEnd = newGapStart + size; - if (oldSize == 0) { - System.arraycopy(this.contents, 0, content, 0, newGapStart); - System.arraycopy(this.contents, newGapStart, content, newGapEnd, content.length - newGapEnd); - } else - if (newGapStart < this.gapStart) { - int delta = this.gapStart - newGapStart; - System.arraycopy(this.contents, 0, content, 0, newGapStart); - System.arraycopy(this.contents, newGapStart, content, newGapEnd, delta); - System.arraycopy(this.contents, this.gapEnd, content, newGapEnd + delta, this.contents.length - this.gapEnd); - } else { - int delta = newGapStart - this.gapStart; - System.arraycopy(this.contents, 0, content, 0, this.gapStart); - System.arraycopy(this.contents, this.gapEnd, content, this.gapStart, delta); - System.arraycopy(this.contents, this.gapEnd + delta, content, newGapEnd, content.length - newGapEnd); - } - this.contents = content; - this.gapStart = newGapStart; - this.gapEnd = newGapEnd; - } - - /** - * Sets this <code>Buffer</code> to be read only. - */ - protected void setReadOnly(boolean readOnly) { - if (readOnly) { - this.flags |= F_IS_READ_ONLY; - } else { - this.flags &= ~(F_IS_READ_ONLY); - } - } - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("Owner: " + ((CElement)this.owner).toString()); //$NON-NLS-1$ - buffer.append("\nHas unsaved changes: " + this.hasUnsavedChanges()); //$NON-NLS-1$ - buffer.append("\nIs readonly: " + this.isReadOnly()); //$NON-NLS-1$ - buffer.append("\nIs closed: " + this.isClosed()); //$NON-NLS-1$ - buffer.append("\nContents:\n"); //$NON-NLS-1$ - char[] contents = this.getCharacters(); - if (contents == null) { - buffer.append("<null>"); //$NON-NLS-1$ - } else { - int length = contents.length; - for (int i = 0; i < length; i++) { - char car = contents[i]; - switch (car) { - case '\n': - buffer.append("\\n\n"); //$NON-NLS-1$ - break; - case '\r': - if (i < length-1 && this.contents[i+1] == '\n') { - buffer.append("\\r\\n\n"); //$NON-NLS-1$ - i++; - } else { - buffer.append("\\r\n"); //$NON-NLS-1$ - } - break; - default: - buffer.append(car); - break; - } - } - } - return buffer.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java deleted file mode 100644 index 786835b347e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BufferManager.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.eclipse.cdt.internal.core.model; -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - - -import java.util.Enumeration; - -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; -import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -/** - * The buffer manager manages the set of open buffers. - * It implements an LRU cache of buffers. - * - * This class is similar to the JDT BufferManager class - */ - -public class BufferManager implements IBufferFactory { - - /** - * An LRU cache of <code>IBuffers</code>. - */ - public class BufferCache extends OverflowingLRUCache { - /** - * Constructs a new buffer cache of the given size. - */ - public BufferCache(int size) { - super(size); - } - /** - * Constructs a new buffer cache of the given size. - */ - public BufferCache(int size, int overflow) { - super(size, overflow); - } - /** - * Returns true if the buffer is successfully closed and - * removed from the cache, otherwise false. - * - * <p>NOTE: this triggers an external removal of this buffer - * by closing the buffer. - */ - protected boolean close(LRUCacheEntry entry) { - IBuffer buffer= (IBuffer) entry._fValue; - if (buffer.hasUnsavedChanges()) { - return false; - } else { - buffer.close(); - return true; - } - } - /** - * Returns a new instance of the reciever. - */ - protected LRUCache newInstance(int size, int overflow) { - return new BufferCache(size, overflow); - } - } - - protected static BufferManager DEFAULT_BUFFER_MANAGER; - - /** - * LRU cache of buffers. The key and value for an entry - * in the table is the identical buffer. - */ - protected OverflowingLRUCache openBuffers = new BufferCache(60); - - /** - * Creates a new buffer manager. - */ - public BufferManager() { - } - /** - * Adds a buffer to the table of open buffers. - */ - protected void addBuffer(IBuffer buffer) { - openBuffers.put(buffer.getOwner(), buffer); - } - - /** - * @see org.eclipse.cdt.internal.core.model.IBufferFactory#createBuffer(org.eclipse.cdt.core.model.IOpenable) - */ - public IBuffer createBuffer(IOpenable owner) { - ICElement element = (ICElement)owner; - - IResource resource = element.getResource(); - return - new Buffer( - resource instanceof IFile ? (IFile)resource : null, - owner, - element.isReadOnly()); - } - - /** - * Returns the open buffer associated with the given owner, - * or <code>null</code> if the owner does not have an open - * buffer associated with it. - */ - public IBuffer getBuffer(IOpenable owner) { - return (IBuffer)openBuffers.get(owner); - } - /** - * Returns the default buffer factory. - */ - public IBufferFactory getDefaultBufferFactory() { - return this; - } - /** - * Returns the default buffer manager. - */ - public synchronized static BufferManager getDefaultBufferManager() { - if (DEFAULT_BUFFER_MANAGER == null) { - DEFAULT_BUFFER_MANAGER = new BufferManager(); - } - return DEFAULT_BUFFER_MANAGER; - } - /** - * Returns an enumeration of all open buffers. - * <p> - * The <code>Enumeration</code> answered is thread safe. - * - * @see OverflowingLRUCache - * @return Enumeration of IBuffer - */ - public Enumeration getOpenBuffers() { - synchronized (openBuffers) { - openBuffers.shrink(); - return openBuffers.elements(); - } - } - - - /** - * Removes a buffer from the table of open buffers. - */ - protected void removeBuffer(IBuffer buffer) { - openBuffers.remove(buffer.getOwner()); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java deleted file mode 100644 index e1ec283a359..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java +++ /dev/null @@ -1,266 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IArchive; -import org.eclipse.cdt.core.model.IBinary; -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; - -public class CContainer extends Openable implements ICContainer { - CModelManager factory = CModelManager.getDefault(); - - public CContainer(ICElement parent, IResource res) { - this(parent, res, ICElement.C_CCONTAINER); - } - - public CContainer(ICElement parent, IResource res, int type) { - super(parent, res, type); - } - - /** - * Returns a the collection of binary files in this ccontainer - * - * @see ICContainer#getBinaries() - */ - public IBinary[] getBinaries() throws CModelException { - List list = getChildrenOfType(C_BINARY); - IBinary[] array = new IBinary[list.size()]; - list.toArray(array); - return array; - } - - /** - * @see ICContainer#getBinary(String) - */ - public IBinary getBinary(String name) { - IFile file = getContainer().getFile(new Path(name)); - return getBinary(file); - } - - public IBinary getBinary(IFile file) { - IBinaryFile bin = factory.createBinaryFile(file); - if (bin instanceof IBinaryObject) { - return new Binary(this, file, (IBinaryObject) bin); - } - return new Binary(this, file, null); - } - - /** - * Returns a the collection of archive files in this ccontainer - * - * @see ICContainer#getArchives() - */ - public IArchive[] getArchives() throws CModelException { - List list = getChildrenOfType(C_ARCHIVE); - IArchive[] array = new IArchive[list.size()]; - list.toArray(array); - return array; - } - - /** - * @see ICContainer#getArchive(String) - */ - public IArchive getArchive(String name) { - IFile file = getContainer().getFile(new Path(name)); - return getArchive(file); - } - - public IArchive getArchive(IFile file) { - IBinaryFile ar = factory.createBinaryFile(file); - if (ar != null && ar.getType() == IBinaryFile.ARCHIVE) { - return new Archive(this, file, (IBinaryArchive) ar); - } - return new Archive(this, file, null); - } - - /** - * @see ICContainer#getTranslationUnits() - */ - public ITranslationUnit[] getTranslationUnits() throws CModelException { - List list = getChildrenOfType(C_UNIT); - ITranslationUnit[] array = new ITranslationUnit[list.size()]; - list.toArray(array); - return array; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.model.ICContainer#getTranslationUnit(java.lang.String) - */ - public ITranslationUnit getTranslationUnit(String name) { - IFile file = getContainer().getFile(new Path(name)); - return getTranslationUnit(file); - } - - public ITranslationUnit getTranslationUnit(IFile file) { - return new TranslationUnit(this, file); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.model.ICContainer#getCContainers() - */ - public ICContainer[] getCContainers() throws CModelException { - List list = getChildrenOfType(C_CCONTAINER); - ICContainer[] array = new ICContainer[list.size()]; - list.toArray(array); - return array; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.model.ICContainer#getCContainer(java.lang.String) - */ - public ICContainer getCContainer(String name) { - IFolder folder = getContainer().getFolder(new Path(name)); - return getCContainer(folder); - } - - public ICContainer getCContainer(IFolder folder) { - return new CContainer(this, folder); - } - - public IContainer getContainer() { - return (IContainer) getResource(); - } - - protected CElementInfo createElementInfo() { - return new CContainerInfo(this); - } - - // CHECKPOINT: folders will return the hash code of their path - public int hashCode() { - return getPath().hashCode(); - } - - /** - * @see Openable - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) - throws CModelException { - boolean validInfo = false; - try { - IResource res = getResource(); - if (res != null && res.isAccessible()) { - validInfo = computeChildren(info, res); - } else { - throw newNotPresentException(); - } - } finally { - if (!validInfo) { - CModelManager.getDefault().removeInfo(this); - } - } - return validInfo; - } - - /* - * (non-Javadoc) Returns an array of non-c resources contained in the - * receiver. - * - * @see org.eclipse.cdt.core.model.ICContainer#getNonCResources() - */ - public Object[] getNonCResources() throws CModelException { - return ((CContainerInfo) getElementInfo()).getNonCResources(getResource()); - } - - protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { - ArrayList vChildren = new ArrayList(); - try { - IResource[] resources = null; - if (res instanceof IContainer) { - //System.out.println (" Resource: " + - // res.getFullPath().toOSString()); - IContainer container = (IContainer) res; - resources = container.members(false); - } - if (resources != null) { - ICProject cproject = getCProject(); - ISourceRoot sroot = getSourceRoot(); - for (int i = 0; i < resources.length; i++) { - if (sroot.isOnSourceEntry(resources[i])) { - // Check for Valid C Element only. - ICElement celement = computeChild(resources[i], cproject); - if (celement != null) { - vChildren.add(celement); - } - } - } - } - } catch (CoreException e) { - //System.out.println (e); - //CPlugin.log (e); - //e.printStackTrace(); - throw new CModelException(e); - } - info.setChildren(vChildren); - if (info instanceof CContainerInfo) { - ((CContainerInfo) info).setNonCResources(null); - } - return true; - } - - protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException { - ICElement celement = null; - switch (res.getType()) { - case IResource.FILE : - { - IFile file = (IFile) res; - if (CoreModel.isTranslationUnit(file)) { - celement = new TranslationUnit(this, file); - } else if (cproject.isOnOutputEntry(file)) { - IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file); - if (bin != null) { - if (bin.getType() == IBinaryFile.ARCHIVE) { - celement = new Archive(this, file, (IBinaryArchive)bin); - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - vlib.addChild(celement); - } else { - celement = new Binary(this, file, (IBinaryObject)bin); - if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) { - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - vbin.addChild(celement); - } - } - } - } - break; - } - case IResource.FOLDER : - celement = new CContainer(this, res); - break; - } - return celement; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java deleted file mode 100644 index a48beb479a7..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainerInfo.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.ArrayList; - -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; - -/** - */ -public class CContainerInfo extends OpenableInfo { - - Object[] nonCResources = null; - - /** - * Constructs a new C Model Info - */ - protected CContainerInfo(CElement element) { - super(element); - } - - /** - * @param container - * @return - */ - public Object[] getNonCResources(IResource res) { - if (nonCResources != null) - return nonCResources; - - ArrayList notChildren = new ArrayList(); - ICElement celement = getElement(); - ICProject cproject = celement.getCProject(); - // move back to the sourceroot. - while (! (celement instanceof ISourceRoot) && celement != null) { - celement = celement.getParent(); - } - ISourceRoot root = null; - if (celement instanceof ISourceRoot) { - root = (ISourceRoot)celement; - } else { - return new Object[0]; // should not be. assert - } - - try { - IResource[] resources = null; - if (res instanceof IContainer) { - IContainer container = (IContainer)res; - resources = container.members(false); - } - - IPathEntry[] entries = cproject.getResolvedPathEntries(); - if (resources != null) { - for (int i = 0; i < resources.length; i++) { - IResource member = resources[i]; - switch(member.getType()) { - case IResource.FOLDER: { - // Check if the folder is not itself a sourceEntry. - IPath resourcePath = member.getFullPath(); - if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)) { - continue; - } - break; - } - case IResource.FILE: { - String filename = member.getName(); - if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) && - root.isOnSourceEntry(member)) { - continue; - } else { - if (root.isOnSourceEntry(member)) { - if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) { - continue; - } - } - } - break; - } - } - notChildren.add(member); - } - } - } catch (CoreException e) { - //System.out.println (e); - //CPlugin.log (e); - //e.printStackTrace(); - } - setNonCResources(notChildren.toArray()); - return nonCResources; - } - - /** - * @param container - * @return - */ - public void setNonCResources(Object[] resources) { - nonCResources = resources; - } - - private static boolean isSourceEntry(IPath resourcePath, IPathEntry[] entries) { - for (int k = 0; k < entries.length; k++) { - IPathEntry entry = entries[k]; - if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) { - IPath sourcePath = entry.getPath(); - if (resourcePath.equals(sourcePath)) { - return true; - } - } - } - return false; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java deleted file mode 100644 index a6db20a0936..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ /dev/null @@ -1,496 +0,0 @@ -package org.eclipse.cdt.internal.core.model; -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementVisitor; -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.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.PlatformObject; - -public abstract class CElement extends PlatformObject implements ICElement { - - protected static final CElement[] NO_ELEMENTS = new CElement[0]; - protected int fType; - - protected ICElement fParent; - - protected String fName; - - protected int fStartPos; - protected int fLength; - protected int fIdStartPos; - protected int fIdLength; - protected int fStartLine; - protected int fEndLine; - - protected CElement(ICElement parent, String name, int type) { - fParent= parent; - fName= name; - fType= type; - } - - // setters - - public void setElementType (int type) { - fType= type; - } - - public void setElementName(String name) { - fName = name; - } - - public void setParent (ICElement parent) { - fParent = parent; - } - - // getters - - public int getElementType() { - return fType; - } - - public String getElementName() { - return fName; - } - - public ICElement getParent() { - return fParent; - } - - public IPath getPath() { - IResource res = getUnderlyingResource(); - if (res != null) - return res.getFullPath(); - return new Path(getElementName()); - } - - public boolean exists() { - try { - return getElementInfo() != null; - } catch (CModelException e) { - // Do not log it, it will fil the .log alarming the user. - //CCorePlugin.log(e); - return false; - } - } - - /** - * Returns the element that is located at the given source offset - * in this element. This is a helper method for <code>ITranslationUnit#getElementAtOffset</code>, - * and only works on compilation units and types. The offset given is - * known to be within this element's source range already, and if no finer - * grained element is found at the offset, this element is returned. - */ - protected ICElement getSourceElementAtOffset(int offset) throws CModelException { - if (this instanceof ISourceReference && this instanceof Parent) { - ICElement[] children = ((Parent)this).getChildren(); - for (int i = 0; i < children.length; i++) { - ICElement aChild = children[i]; - if (aChild instanceof ISourceReference) { - ISourceReference child = (ISourceReference) children[i]; - ISourceRange range = child.getSourceRange(); - int startPos = range.getStartPos(); - int endPos = startPos + range.getLength(); - if (offset < endPos && offset >= startPos) { - if (child instanceof Parent) { - return ((Parent)child).getSourceElementAtOffset(offset); - } else { - return (ICElement)child; - } - } - } - } - } else { - // should not happen - //Assert.isTrue(false); - } - return this; - } - - /** - * Returns the elements that are located at the given source offset - * in this element. This is a helper method for <code>ITranslationUnit#getElementAtOffset</code>, - * and only works on compilation units and types. The offset given is - * known to be within this element's source range already, and if no finer - * grained element is found at the offset, this element is returned. - */ - protected ICElement[] getSourceElementsAtOffset(int offset) throws CModelException { - if (this instanceof ISourceReference && this instanceof Parent) { - ArrayList list = new ArrayList(); - ICElement[] children = ((Parent)this).getChildren(); - for (int i = 0; i < children.length; i++) { - ICElement aChild = children[i]; - if (aChild instanceof ISourceReference) { - ISourceReference child = (ISourceReference) children[i]; - ISourceRange range = child.getSourceRange(); - int startPos = range.getStartPos(); - int endPos = startPos + range.getLength(); - if (offset < endPos && offset >= startPos) { - if (child instanceof Parent) { - ICElement[] elements = ((Parent)child).getSourceElementsAtOffset(offset); - list.addAll(Arrays.asList(elements)); - } - list.add(child); - } - } - } - children = new ICElement[list.size()]; - list.toArray(children); - return children; - } else { - // should not happen - //Assert.isTrue(false); - } - return new ICElement[]{this}; - } - - public boolean isReadOnly () { - IResource r = getUnderlyingResource(); - if (r != null) { - return r.isReadOnly(); - } - return false; - } - - public boolean isStructureKnown() throws CModelException { - return getElementInfo().isStructureKnown(); - } - - public ICModel getCModel () { - ICElement current = this; - do { - if (current instanceof ICModel) return (ICModel) current; - } while ((current = current.getParent()) != null); - return null; - } - - public ICProject getCProject() { - ICElement current = this; - do { - if (current instanceof ICProject) return (ICProject) current; - } while ((current = current.getParent()) != null); - return null; - } - - protected void addChild(ICElement e) throws CModelException { - } - - public void setPos(int startPos, int length) { - fStartPos = startPos; - fLength = length; - } - - public int getStartPos() { - return fStartPos; - } - - public int getLength() { - return fLength; - } - - public void setIdPos(int startPos, int length) { - fIdStartPos= startPos; - fIdLength= length; - } - - public int getIdStartPos() { - return fIdStartPos; - } - - public int getIdLength() { - return fIdLength; - } - - public int getStartLine() { - return fStartLine; - } - - public int getEndLine() { - return fEndLine; - } - - public void setLines(int startLine, int endLine) { - fStartLine = startLine; - fEndLine = endLine; - } - - public IResource getUnderlyingResource() { - IResource res = getResource(); - if (res == null) { - ICElement p = getParent(); - if (p != null) { - res = p.getUnderlyingResource(); - } - } - return res; - } - - public abstract IResource getResource() ; - - protected abstract CElementInfo createElementInfo(); - - /** - * Tests if an element has the same name, type and an equal parent. - */ - public boolean equals (Object o) { - if (this == o) - return true; - if (o instanceof CElement) { - CElement other = (CElement) o; - if( fName == null || other.fName == null ) - return false; - if( fName.length() == 0 || other.fName.length() == 0 ) - return false; - if (fType != other.fType) - return false; - if (fName.equals(other.fName)) { - if (fParent != null && fParent.equals(other.fParent)) { - return true; - } - if (fParent == null && other.fParent == null) - return true; - } - } - return false; - } - - public CElementInfo getElementInfo() throws CModelException { - return getElementInfo(null); - } - - public CElementInfo getElementInfo (IProgressMonitor monitor) throws CModelException { - CModelManager manager = CModelManager.getDefault(); - CElementInfo info = (CElementInfo)manager.getInfo(this); - if (info != null) { - return info; - } - info = createElementInfo(); - openWhenClosed(info, monitor); - return info; - } - - public String toString() { - return getElementName(); - } - - public String toDebugString() { - return getElementName() + " " + getTypeString(getElementType()); //$NON-NLS-1$ - } - - // util - public static String getTypeString(int type) { - switch (type) { - case C_MODEL: - return "CMODEL"; //$NON-NLS-1$ - case C_PROJECT: - return "CPROJECT"; //$NON-NLS-1$ - case C_CCONTAINER: - return "CCONTAINER"; //$NON-NLS-1$ - case C_UNIT: - return "TRANSLATION_UNIT"; //$NON-NLS-1$ - case C_FUNCTION: - return "C_FUNCTION"; //$NON-NLS-1$ - case C_FUNCTION_DECLARATION: - return "C_FUNCTION_DECLARATION"; //$NON-NLS-1$ - case C_VARIABLE: - return "C_VARIABLE"; //$NON-NLS-1$ - case C_VARIABLE_DECLARATION: - return "C_VARIABLE_DECLARATION"; //$NON-NLS-1$ - case C_INCLUDE: - return "C_INCLUDE"; //$NON-NLS-1$ - case C_MACRO: - return "C_MACRO"; //$NON-NLS-1$ - case C_STRUCT: - return "C_STRUCT"; //$NON-NLS-1$ - case C_CLASS: - return "C_CLASS"; //$NON-NLS-1$ - case C_UNION: - return "C_UNION"; //$NON-NLS-1$ - case C_FIELD: - return "C_FIELD"; //$NON-NLS-1$ - case C_METHOD: - return "C_METHOD"; //$NON-NLS-1$ - default: - return "UNKNOWN"; //$NON-NLS-1$ - } - } - - /** - * Runs a C Model Operation - */ - protected void runOperation(CModelOperation operation, IProgressMonitor monitor) throws CModelException { - CModelManager.getDefault().runOperation(operation, monitor); - } - - /** - * Close the C Element - * @throws CModelException - */ - public void close() throws CModelException { - CModelManager.getDefault().releaseCElement(this); - } - - /** - * This element is being closed. Do any necessary cleanup. - */ - protected void closing(Object info) throws CModelException { - } - - /** - * This element has just been opened. Do any necessary setup. - */ - protected void opening(Object info) { - } - - /** - * Return the first instance of IOpenable in the parent - * hierarchy of this element. - * - * <p>Subclasses that are not IOpenable's must override this method. - */ - public IOpenable getOpenableParent() { - if (fParent instanceof IOpenable) { - return (IOpenable)fParent; - } - return null; - } - - /** - * Builds this element's structure and properties in the given - * info object, based on this element's current contents (i.e. buffer - * contents if this element has an open buffer, or resource contents - * if this element does not have an open buffer). Children - * are placed in the given newElements table (note, this element - * has already been placed in the newElements table). Returns true - * if successful, or false if an error is encountered while determining - * the structure of this element. - */ - protected abstract void generateInfos(Object info, Map newElements, IProgressMonitor monitor) throws CModelException; - - /** - * Open a <code>IOpenable</code> that is known to be closed (no check for - * <code>isOpen()</code>). - */ - protected void openWhenClosed(CElementInfo info, IProgressMonitor pm) throws CModelException { - CModelManager manager = CModelManager.getDefault(); - boolean hadTemporaryCache = manager.hasTemporaryCache(); - try { - HashMap newElements = manager.getTemporaryCache(); - generateInfos(info, newElements, pm); - if (info == null) { - info = (CElementInfo)newElements.get(this); - } - if (info == null) { // a source ref element could not be opened - // close any buffer that was opened for the openable parent - Iterator iterator = newElements.keySet().iterator(); - while (iterator.hasNext()) { - ICElement element = (ICElement)iterator.next(); - if (element instanceof Openable) { - ((Openable)element).closeBuffer(); - } - } - throw newNotPresentException(); - } - if (!hadTemporaryCache) { - manager.putInfos(this, newElements); - } - - } finally { - if (!hadTemporaryCache) { - manager.resetTemporaryCache(); - } - } - } - - - /** - * @see ICElement - */ - public ICElement getAncestor(int ancestorType) { - ICElement element = this; - while (element != null) { - if (element.getElementType() == ancestorType) { - return element; - } - element= element.getParent(); - } - return null; - } - - /** - * Returns true if this element is an ancestor of the given element, - * otherwise false. - */ - public boolean isAncestorOf(ICElement e) { - ICElement parent= e.getParent(); - while (parent != null && !parent.equals(this)) { - parent= parent.getParent(); - } - return parent != null; - } - - /** - * Creates and returns and not present exception for this element. - */ - protected CModelException newNotPresentException() { - return new CModelException(new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this)); - } - - /** - * Returns the hash code for this Java element. By default, - * the hash code for an element is a combination of its name - * and parent's hash code. Elements with other requirements must - * override this method. - */ - // CHECKPOINT: making not equal objects seem equal - // What elements should override this? - public int hashCode() { - if (fParent == null) return super.hashCode(); - return Util.combineHashCodes(fName.hashCode(), fParent.hashCode()); - } - - /* - * Test to see if two objects are identical - * Subclasses should override accordingly - */ - public boolean isIdentical( CElement otherElement){ - return this.equals(otherElement); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#accept(org.eclipse.cdt.core.model.ICElementVisitor) - */ - public void accept(ICElementVisitor visitor) throws CoreException { - // Visit me, return right away if the visitor doesn't want to visit my children - if (!visitor.visit(this)) - return; - - // If I am a Parent, visit my children - if (this instanceof IParent) { - ICElement [] children = ((IParent)this).getChildren(); - for (int i = 0; i < children.length; ++i) - children[i].accept(visitor); - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java deleted file mode 100644 index 10c1916d91f..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java +++ /dev/null @@ -1,760 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -import java.util.ArrayList; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.core.resources.IResourceDelta; - - -/** - * @see ICElementDelta - */ -public class CElementDelta implements ICElementDelta { - /** - * The element that this delta describes the change to. - * @see #getElement() - */ - protected ICElement fChangedElement; - - /** - * @see #getKind() - */ - private int fKind = 0; - - /** - * @see #getFlags() - */ - private int fChangeFlags = 0; - - /** - * @see #getMovedFromHandle() - */ - protected ICElement fMovedFromHandle = null; - - /** - * @see #getMovedToHandle() - */ - protected ICElement fMovedToHandle = null; - - /** - * Collection of resource deltas that correspond to non c resources deltas. - */ - protected IResourceDelta[] resourceDeltas = null; - - /** - * Counter of resource deltas - */ - protected int resourceDeltasCounter; - - /** - * Empty array of ICElementDelta - */ - protected static ICElementDelta[] fgEmptyDelta= new ICElementDelta[] {}; - - /** - * @see #getAffectedChildren() - */ - protected ICElementDelta[] fAffectedChildren = fgEmptyDelta; - - /** - * Creates the root delta. To create the nested delta - * hierarchies use the following convenience methods. The root - * delta can be created at any level (i.e. project, folder). - * <ul> - * <li><code>added(ICElement)</code> - * <li><code>changed(ICElement)</code> - * <li><code>moved(ICElement, ICElement)</code> - * <li><code>removed(ICElement)</code> - * <li><code>renamed(ICElement, ICElement)</code> - * </ul> - */ - public CElementDelta(ICElement element) { - super(); - fChangedElement = element; - } - - /** - * Adds the child delta to the collection of affected children. If the - * child is already in the collection, walk down the hierarchy. - */ - protected void addAffectedChild(CElementDelta child) { - switch (fKind) { - case ADDED: - case REMOVED: - // no need to add a child if this parent is added or removed - return; - case CHANGED: - fChangeFlags |= F_CHILDREN; - break; - default: - fKind = CHANGED; - fChangeFlags |= F_CHILDREN; - } - - // if a child delta is added to a translation unit delta or below, - // it's a fine grained delta - if (!(fChangedElement.getElementType() >= ICElement.C_UNIT)) { - fineGrained(); - } - - if (fAffectedChildren.length == 0) { - fAffectedChildren = new ICElementDelta[] {child}; - return; - } - - // Check if we already have the delta. - ICElementDelta existingChild = null; - int existingChildIndex = -1; - for (int i = 0; i < fAffectedChildren.length; i++) { - // handle case of two jars that can be equals but not in the same project - if (equalsAndSameParent(fAffectedChildren[i].getElement(), child.getElement())) { - existingChild = fAffectedChildren[i]; - existingChildIndex = i; - break; - } - } - - if (existingChild == null) { //new affected child - fAffectedChildren= growAndAddToArray(fAffectedChildren, child); - } else { - switch (existingChild.getKind()) { - case ADDED: - switch (child.getKind()) { - // child was added then added -> it is added - case ADDED: - // child was added then changed -> it is added - case CHANGED: - return; - - // child was added then removed -> noop - case REMOVED: - fAffectedChildren = removeAndShrinkArray(fAffectedChildren, existingChildIndex); - return; - } - break; - case REMOVED: - switch (child.getKind()) { - // child was removed then added -> it is changed - case ADDED: - child.fKind = CHANGED; - fAffectedChildren[existingChildIndex] = child; - return; - - // child was removed then changed -> it is removed - case CHANGED: - // child was removed then removed -> it is removed - case REMOVED: - return; - } - break; - case CHANGED: - switch (child.getKind()) { - // child was changed then added -> it is added - case ADDED: - // child was changed then removed -> it is removed - case REMOVED: - fAffectedChildren[existingChildIndex] = child; - return; - - // child was changed then changed -> it is changed - case CHANGED: - ICElementDelta[] children = child.getAffectedChildren(); - for (int i = 0; i < children.length; i++) { - CElementDelta childsChild = (CElementDelta) children[i]; - ((CElementDelta) existingChild).addAffectedChild(childsChild); - } - // add the non-c resource deltas if needed - // note that the child delta always takes - // precedence over this existing child delta - // as non-c resource deltas are always - // created last (by the DeltaProcessor) - IResourceDelta[] resDeltas = child.getResourceDeltas(); - if (resDeltas != null) { - ((CElementDelta)existingChild).resourceDeltas = resDeltas; - ((CElementDelta)existingChild).resourceDeltasCounter = child.resourceDeltasCounter; - } - return; - } - break; - default: - // unknown -> existing child becomes the child with the existing child's flags - int flags = existingChild.getFlags(); - fAffectedChildren[existingChildIndex] = child; - child.fChangeFlags |= flags; - } - } - } - - /** - * Creates the nested deltas resulting from an add operation. - * Convenience method for creating add deltas. - * The constructor should be used to create the root delta - * and then an add operation should call this method. - */ - public void added(ICElement element) { - CElementDelta addedDelta = new CElementDelta(element); - addedDelta.fKind = ADDED; - insertDeltaTree(element, addedDelta); - } - - /** - * Adds the child delta to the collection of affected children. If the - * child is already in the collection, walk down the hierarchy. - */ - protected void addResourceDelta(IResourceDelta child) { - switch (fKind) { - case ADDED: - case REMOVED: - // no need to add a child if this parent is added or removed - return; - case CHANGED: - fChangeFlags |= F_CONTENT; - break; - default: - fKind = CHANGED; - fChangeFlags |= F_CONTENT; - } - if (resourceDeltas == null) { - resourceDeltas = new IResourceDelta[5]; - resourceDeltas[resourceDeltasCounter++] = child; - return; - } - if (resourceDeltas.length == resourceDeltasCounter) { - // need a resize - System.arraycopy(resourceDeltas, 0, (resourceDeltas = new IResourceDelta[resourceDeltasCounter * 2]), 0, resourceDeltasCounter); - } - resourceDeltas[resourceDeltasCounter++] = child; - } - - /** - * Creates the nested deltas resulting from a change operation. - * Convenience method for creating change deltas. - * The constructor should be used to create the root delta - * and then a change operation should call this method. - */ - public void changed(ICElement element, int changeFlag) { - CElementDelta changedDelta = new CElementDelta(element); - changedDelta.fKind = CHANGED; - changedDelta.fChangeFlags |= changeFlag; - insertDeltaTree(element, changedDelta); - } - - /** - * Creates the nested deltas for a closed element. - */ - public void closed(ICElement element) { - CElementDelta delta = new CElementDelta(element); - delta.fKind = CHANGED; - delta.fChangeFlags |= F_CLOSED; - insertDeltaTree(element, delta); - } - - /** - * Returns whether the two c elements are equals and have the same parent. - */ - protected boolean equalsAndSameParent(ICElement e1, ICElement e2) { - ICElement parent1; - return e1.equals(e2) && ((parent1 = e1.getParent()) != null) && parent1.equals(e2.getParent()); - } - - /** - * Creates the nested delta deltas based on the affected element - * its delta, and the root of this delta tree. Returns the root - * of the created delta tree. - */ - protected CElementDelta createDeltaTree(ICElement element, CElementDelta delta) { - CElementDelta childDelta = delta; - ArrayList ancestors= getAncestors(element); - if (ancestors == null) { - if (equalsAndSameParent(delta.getElement(), getElement())) { - // handle case of two jars that can be equals but not in the - // same project - // the element being changed is the root element - fKind= delta.fKind; - fChangeFlags = delta.fChangeFlags; - fMovedToHandle = delta.fMovedToHandle; - fMovedFromHandle = delta.fMovedFromHandle; - } else { - // the given delta is not the root or a child - illegal - //Assert.isTrue(false); - } - } else { - for (int i = 0, size = ancestors.size(); i < size; i++) { - ICElement ancestor = (ICElement) ancestors.get(i); - CElementDelta ancestorDelta = new CElementDelta(ancestor); - ancestorDelta.addAffectedChild(childDelta); - childDelta = ancestorDelta; - } - } - return childDelta; - } - - /** - * Returns the <code>CElementDelta</code> for the given element - * in the delta tree, or null, if no delta for the given element is found. - */ - protected CElementDelta find(ICElement e) { - if (equalsAndSameParent(fChangedElement, e)) { // handle case of two jars that can be equals but not in the same project - return this; - } else { - for (int i = 0; i < fAffectedChildren.length; i++) { - CElementDelta delta = ((CElementDelta)fAffectedChildren[i]).find(e); - if (delta != null) { - return delta; - } - } - } - return null; - } - - /** - * Mark this delta as a fine-grained delta. - */ - public void fineGrained() { - fChangeFlags |= F_FINE_GRAINED; - } - - /** - * @see ICElementDelta - */ - public ICElementDelta[] getAddedChildren() { - return getChildrenOfType(ADDED); - } - - /** - * @see ICElementDelta - */ - public ICElementDelta[] getAffectedChildren() { - return fAffectedChildren; - } - - /** - * Returns a collection of all the parents of this element up to (but - * not including) the root of this tree in bottom-up order. If the given - * element is not a descendant of the root of this tree, <code>null</code> - * is returned. - */ - private ArrayList getAncestors(ICElement element) { - ICElement parent = element.getParent(); - if (parent == null) { - return null; - } - ArrayList parents = new ArrayList(); - while (!parent.equals(fChangedElement)) { - parents.add(parent); - parent = parent.getParent(); - if (parent == null) { - return null; - } - } - parents.trimToSize(); - return parents; - } - - /** - * @see ICElementDelta - */ - public ICElementDelta[] getChangedChildren() { - return getChildrenOfType(CHANGED); - } - - /** - * @see ICElementDelta - */ - protected ICElementDelta[] getChildrenOfType(int type) { - int length = fAffectedChildren.length; - if (length == 0) { - return new ICElementDelta[] {}; - } - ArrayList children= new ArrayList(length); - for (int i = 0; i < length; i++) { - if (fAffectedChildren[i].getKind() == type) { - children.add(fAffectedChildren[i]); - } - } - - ICElementDelta[] childrenOfType = new ICElementDelta[children.size()]; - children.toArray(childrenOfType); - return childrenOfType; - } - - /** - * Returns the delta for a given element. Only looks below this - * delta. - */ - protected CElementDelta getDeltaFor(ICElement element) { - if (equalsAndSameParent(getElement(), element)) // handle case of two jars that can be equals but not in the same project - return this; - if (fAffectedChildren.length == 0) - return null; - int childrenCount = fAffectedChildren.length; - for (int i = 0; i < childrenCount; i++) { - CElementDelta delta = (CElementDelta)fAffectedChildren[i]; - if (equalsAndSameParent(delta.getElement(), element)) { // handle case of two jars that can be equals but not in the same project - return delta; - } else { - delta = delta.getDeltaFor(element); - if (delta != null) - return delta; - } - } - return null; - } - - /** - * @see ICElementDelta - */ - public ICElement getElement() { - return fChangedElement; - } - - /** - * @see ICElementDelta - */ - public int getFlags() { - return fChangeFlags; - } - - /** - * @see ICElementDelta - */ - public int getKind() { - return fKind; - } - - /** - * @see ICElementDelta - */ - public ICElement getMovedFromElement() { - return fMovedFromHandle; - } - - /** - * @see ICElementDelta - */ - public ICElement getMovedToElement() { - return fMovedToHandle; - } - - /** - * @see ICElementDelta - */ - public ICElementDelta[] getRemovedChildren() { - return getChildrenOfType(REMOVED); - } - - /** - * Return the collection of resource deltas. Return null if none. - */ - public IResourceDelta[] getResourceDeltas() { - if (resourceDeltas == null) - return null; - if (resourceDeltas.length != resourceDeltasCounter) { - System.arraycopy(resourceDeltas, 0, resourceDeltas = new IResourceDelta[resourceDeltasCounter], 0, resourceDeltasCounter); - } - return resourceDeltas; - } - - /** - * Adds the new element to a new array that contains all of the elements of the old array. - * Returns the new array. - */ - protected ICElementDelta[] growAndAddToArray(ICElementDelta[] array, ICElementDelta addition) { - ICElementDelta[] old = array; - array = new ICElementDelta[old.length + 1]; - System.arraycopy(old, 0, array, 0, old.length); - array[old.length] = addition; - return array; - } - - /** - * Creates the delta tree for the given element and delta, and then - * inserts the tree as an affected child of this node. - */ - protected void insertDeltaTree(ICElement element, CElementDelta delta) { - CElementDelta childDelta= createDeltaTree(element, delta); - if (!equalsAndSameParent(element, getElement())) { - addAffectedChild(childDelta); - } - } - - - /** - * Creates the nested deltas resulting from an move operation. - * Convenience method for creating the "move from" delta. - * The constructor should be used to create the root delta - * and then the move operation should call this method. - */ - public void movedFrom(ICElement movedFromElement, ICElement movedToElement) { - CElementDelta removedDelta = new CElementDelta(movedFromElement); - removedDelta.fKind = REMOVED; - removedDelta.fChangeFlags |= F_MOVED_TO; - removedDelta.fMovedToHandle = movedToElement; - insertDeltaTree(movedFromElement, removedDelta); - } - - /** - * Creates the nested deltas resulting from an move operation. - * Convenience method for creating the "move to" delta. - * The constructor should be used to create the root delta - * and then the move operation should call this method. - */ - public void movedTo(ICElement movedToElement, ICElement movedFromElement) { - CElementDelta addedDelta = new CElementDelta(movedToElement); - addedDelta.fKind = ADDED; - addedDelta.fChangeFlags |= F_MOVED_FROM; - addedDelta.fMovedFromHandle = movedFromElement; - insertDeltaTree(movedToElement, addedDelta); - } - - /** - * Creates the nested deltas for an opened element. - */ - public void opened(ICElement element) { - CElementDelta delta = new CElementDelta(element); - delta.fKind = CHANGED; - delta.fChangeFlags |= F_OPENED; - insertDeltaTree(element, delta); - } - - /** - * Removes the child delta from the collection of affected children. - */ - protected void removeAffectedChild(CElementDelta child) { - int index = -1; - if (fAffectedChildren != null) { - for (int i = 0; i < fAffectedChildren.length; i++) { - if (equalsAndSameParent(fAffectedChildren[i].getElement(), child.getElement())) { // handle case of two jars that can be equals but not in the same project - index = i; - break; - } - } - } - if (index >= 0) { - fAffectedChildren= removeAndShrinkArray(fAffectedChildren, index); - } - } - - /** - * Removes the element from the array. - * Returns the a new array which has shrunk. - */ - protected ICElementDelta[] removeAndShrinkArray(ICElementDelta[] old, int index) { - ICElementDelta[] array = new ICElementDelta[old.length - 1]; - if (index > 0) - System.arraycopy(old, 0, array, 0, index); - int rest = old.length - index - 1; - if (rest > 0) - System.arraycopy(old, index + 1, array, index, rest); - return array; - } - - /** - * Creates the nested deltas resulting from an delete operation. - * Convenience method for creating removed deltas. - * The constructor should be used to create the root delta - * and then the delete operation should call this method. - */ - public void removed(ICElement element) { - CElementDelta removedDelta= new CElementDelta(element); - insertDeltaTree(element, removedDelta); - CElementDelta actualDelta = getDeltaFor(element); - if (actualDelta != null) { - actualDelta.fKind = REMOVED; - actualDelta.fChangeFlags = 0; - actualDelta.fAffectedChildren = fgEmptyDelta; - } - } - - /** - * Creates the nested deltas resulting from a change operation. - * Convenience method for creating change deltas. - * The constructor should be used to create the root delta - * and then a change operation should call this method. - */ - public void binaryParserChanged(ICElement element) { - CElementDelta attachedDelta = new CElementDelta(element); - attachedDelta.fKind = CHANGED; - attachedDelta.fChangeFlags |= F_BINARY_PARSER_CHANGED; - insertDeltaTree(element, attachedDelta); - } - - /** - * Creates the nested deltas resulting from a change operation. - * Convenience method for creating change deltas. - * The constructor should be used to create the root delta - * and then a change operation should call this method. - */ - public void sourceAttached(ICElement element) { - CElementDelta attachedDelta = new CElementDelta(element); - attachedDelta.fKind = CHANGED; - attachedDelta.fChangeFlags |= F_SOURCEATTACHED; - insertDeltaTree(element, attachedDelta); - } - - /** - * Creates the nested deltas resulting from a change operation. - * Convenience method for creating change deltas. - * The constructor should be used to create the root delta - * and then a change operation should call this method. - */ - public void sourceDetached(ICElement element) { - CElementDelta detachedDelta = new CElementDelta(element); - detachedDelta.fKind = CHANGED; - detachedDelta.fChangeFlags |= F_SOURCEDETACHED; - insertDeltaTree(element, detachedDelta); - } - - /** - * Returns a string representation of this delta's - * structure suitable for debug purposes. - * - * @see toString - */ - public String toDebugString(int depth) { - StringBuffer buffer = new StringBuffer(); - for (int i= 0; i < depth; i++) { - buffer.append('\t'); - } - buffer.append(((CElement)getElement()).toDebugString()); - buffer.append(" ["); //$NON-NLS-1$ - switch (getKind()) { - case ICElementDelta.ADDED : - buffer.append('+'); - break; - case ICElementDelta.REMOVED : - buffer.append('-'); - break; - case ICElementDelta.CHANGED : - buffer.append('*'); - break; - default : - buffer.append('?'); - break; - } - buffer.append("]: {"); //$NON-NLS-1$ - int changeFlags = getFlags(); - boolean prev = false; - if ((changeFlags & ICElementDelta.F_CHILDREN) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("CHILDREN"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_CONTENT) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("CONTENT"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_MOVED_FROM) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - //buffer.append("MOVED_FROM(" + ((CElement)getMovedFromElement()).toStringWithAncestors() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_MOVED_TO) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - //buffer.append("MOVED_TO(" + ((CElement)getMovedToElement()).toStringWithAncestors() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_MODIFIERS) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("MODIFIERS CHANGED"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("CHANGED TO PATHENTRY INCLUDE"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_CHANGED_PATHENTRY_MACRO) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("CHANGED TO PATHENTRY MACRO"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_ADDED_PATHENTRY_LIBRARY) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("ADDED TO PATHENTRY LIBRARY"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("ADDED TO PATHENTRY LIBRARY"); //$NON-NLS-1$ - prev = true; - } - if ((changeFlags & ICElementDelta.F_PATHENTRY_REORDER) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("PATHENTRY REORDER"); //$NON-NLS-1$ - prev = true; - } - - //if ((changeFlags & ICElementDelta.F_SUPER_TYPES) != 0) { - // if (prev) - // buffer.append(" | "); //$NON-NLS-1$ - // buffer.append("SUPER TYPES CHANGED"); //$NON-NLS-1$ - // prev = true; - //} - if ((changeFlags & ICElementDelta.F_FINE_GRAINED) != 0) { - if (prev) - buffer.append(" | "); //$NON-NLS-1$ - buffer.append("FINE GRAINED"); //$NON-NLS-1$ - prev = true; - } - buffer.append("}"); //$NON-NLS-1$ - ICElementDelta[] children = getAffectedChildren(); - if (children != null) { - for (int i = 0; i < children.length; ++i) { - buffer.append("\n"); //$NON-NLS-1$ - buffer.append(((CElementDelta) children[i]).toDebugString(depth + 1)); - } - } - - for (int i = 0; i < resourceDeltasCounter; i++) { - buffer.append("\n");//$NON-NLS-1$ - for (int j = 0; j < depth+1; j++) { - buffer.append('\t'); - } - IResourceDelta resourceDelta = resourceDeltas[i]; - buffer.append(resourceDelta.toString()); - buffer.append("["); //$NON-NLS-1$ - switch (resourceDelta.getKind()) { - case IResourceDelta.ADDED : - buffer.append('+'); - break; - case IResourceDelta.REMOVED : - buffer.append('-'); - break; - case IResourceDelta.CHANGED : - buffer.append('*'); - break; - default : - buffer.append('?'); - break; - } - buffer.append("]"); //$NON-NLS-1$ - } - return buffer.toString(); - } - - /** - * Returns a string representation of this delta's - * structure suitable for debug purposes. - */ - public String toString() { - return toDebugString(0); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java deleted file mode 100644 index cfaa49243c3..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDeltaBuilder.java +++ /dev/null @@ -1,395 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.IParent; - -/** - * A C element delta biulder creates a C element delta on a C element between - * the version of the C element at the time the comparator was created and the - * current version of the C element. - * - * It performs this operation by locally caching the contents of - * the C element when it is created. When the method buildDeltas() is called, it - * creates a delta over the cached contents and the new contents. - * - * This class is similar to the JDT CElementDeltaBuilder class. - */ - -public class CElementDeltaBuilder { - - /** - * The c element handle - */ - ICElement cElement; - - /** - * The maximum depth in the C element children we should look into - */ - int maxDepth = Integer.MAX_VALUE; - - /** - * The old handle to info relationships - */ - Map infos; - - /** - * The old position info - */ - Map oldPositions; - - /** - * The new position info - */ - Map newPositions; - - /** - * Change delta - */ - CElementDelta delta; - - /** - * List of added elements - */ - ArrayList added; - - /** - * List of removed elements - */ - ArrayList removed; - - /** - * Doubly linked list item - */ - class ListItem { - public ICElement previous; - public ICElement next; - - public ListItem(ICElement previous, ICElement next) { - this.previous = previous; - this.next = next; - } - } -/** - * Creates a C element comparator on a C element - * looking as deep as necessary. - */ -public CElementDeltaBuilder(ICElement CElement) { - this.cElement = CElement; - this.initialize(); - this.recordElementInfo(CElement,0); -} -/** - * Creates a C element comparator on a C element - * looking only 'maxDepth' levels deep. - */ -public CElementDeltaBuilder(ICElement cElement, int maxDepth) { - this.cElement = cElement; - this.maxDepth = maxDepth; - this.initialize(); - this.recordElementInfo(cElement,0); -} -/** - * Repairs the positioning information - * after an element has been added - */ -private void added(ICElement element) { - this.added.add(element); - ListItem current = this.getNewPosition(element); - ListItem previous = null, next = null; - if (current.previous != null) - previous = this.getNewPosition(current.previous); - if (current.next != null) - next = this.getNewPosition(current.next); - if (previous != null) - previous.next = current.next; - if (next != null) - next.previous = current.previous; -} -/** - * Builds the C element deltas between the old content of the translation unit - * and its new content. - */ -public void buildDeltas() throws CModelException { - this.recordNewPositions(this.cElement, 0); - this.findAdditions(this.cElement, 0); - this.findDeletions(); - this.findChangesInPositioning(this.cElement, 0); - this.trimDelta(this.delta); -} -/** - * Finds elements which have been added or changed. - */ -private void findAdditions(ICElement newElement, int depth) throws CModelException { - CElementInfo oldInfo = this.getElementInfo(newElement); - if (oldInfo == null && depth < this.maxDepth) { - this.delta.added(newElement); - added(newElement); - } else { - this.removeElementInfo(newElement); - } - - if (depth >= this.maxDepth) { - // mark element as changed - this.delta.changed(newElement, ICElementDelta.F_CONTENT); - return; - } - - CElementInfo newInfo = null; - newInfo = ((CElement)newElement).getElementInfo(); - - this.findContentChange(oldInfo, newInfo, newElement); - - if (oldInfo != null && newElement instanceof IParent) { - - ICElement[] children = newInfo.getChildren(); - if (children != null) { - int length = children.length; - for(int i = 0; i < length; i++) { - this.findAdditions(children[i], depth + 1); - } - } - } -} -/** - * Looks for changed positioning of elements. - */ -private void findChangesInPositioning(ICElement element, int depth) throws CModelException { - if (depth >= this.maxDepth || this.added.contains(element) || this.removed.contains(element)) - return; - - if (!isPositionedCorrectly(element)) { - this.delta.changed(element, ICElementDelta.F_REORDER); - } - - if (element instanceof IParent) { - CElementInfo info = null; - info = ((CElement)element).getElementInfo(); - - ICElement[] children = info.getChildren(); - if (children != null) { - int length = children.length; - for(int i = 0; i < length; i++) { - this.findChangesInPositioning(children[i], depth + 1); - } - } - } -} -/** - * The elements are equivalent, but might have content changes. - */ -private void findContentChange(CElementInfo oldInfo, CElementInfo newInfo, ICElement newElement) { - if (oldInfo instanceof SourceManipulationInfo && newInfo instanceof SourceManipulationInfo) { - SourceManipulationInfo oldSourceInfo = (SourceManipulationInfo) oldInfo; - SourceManipulationInfo newSourceInfo = (SourceManipulationInfo) newInfo; - - if ((oldSourceInfo).getModifiers() != (newSourceInfo).getModifiers()) { - this.delta.changed(newElement, ICElementDelta.F_MODIFIERS); - } - - // The element info should be able to tell if the contents are the same. - if(!oldSourceInfo.hasSameContentsAs(newSourceInfo)){ - this.delta.changed(newElement, ICElementDelta.F_CONTENT); - } - } -} -/** - * Adds removed deltas for any handles left in the table - */ -private void findDeletions() { - Iterator iter = this.infos.keySet().iterator(); - while(iter.hasNext()) { - ICElement element = (ICElement)iter.next(); - this.delta.removed(element); - this.removed(element); - } -} -private CElementInfo getElementInfo(ICElement element) { - return (CElementInfo)this.infos.get(element); -} -private ListItem getNewPosition(ICElement element) { - return (ListItem)this.newPositions.get(element); -} -private ListItem getOldPosition(ICElement element) { - return (ListItem)this.oldPositions.get(element); -} -private void initialize() { - this.infos = new HashMap(20); - this.oldPositions = new HashMap(20); - this.newPositions = new HashMap(20); - this.putOldPosition(this.cElement, new ListItem(null, null)); - this.putNewPosition(this.cElement, new ListItem(null, null)); - this.delta = new CElementDelta(cElement); - - // if building a delta on a translation unit or below, - // it's a fine grained delta - if (cElement.getElementType() >= ICElement.C_UNIT) { - this.delta.fineGrained(); - } - - this.added = new ArrayList(5); - this.removed = new ArrayList(5); -} -/** - * Inserts position information for the elements into the new or old positions table - */ -private void insertPositions(ICElement[] elements, boolean isNew) { - int length = elements.length; - ICElement previous = null, current = null, next = (length > 0) ? elements[0] : null; - for(int i = 0; i < length; i++) { - previous = current; - current = next; - next = (i + 1 < length) ? elements[i + 1] : null; - if (isNew) { - this.putNewPosition(current, new ListItem(previous, next)); - } else { - this.putOldPosition(current, new ListItem(previous, next)); - } - } -} -/** - * Returns true if the given elements represent the an equivalent declaration. - * - * <p>NOTE: Since this comparison can be done with handle info only, - * none of the internal calls need to use the locally cached contents - * of the old translation unit. - */ -private boolean isIdentical(CElement e1, CElement e2) { - if (e1 == null ^ e2 == null) - return false; - - if (e1 == null) - return true; - - return e1.isIdentical(e2); -} -/** - * Answers true if the elements position has not changed. - * Takes into account additions so that elements following - * new elements will not appear out of place. - */ -private boolean isPositionedCorrectly(ICElement element) { - ListItem oldListItem = this.getOldPosition(element); - if (oldListItem == null) return false; - - ListItem newListItem = this.getNewPosition(element); - if (newListItem == null) return false; - - ICElement oldPrevious = oldListItem.previous; - ICElement newPrevious = newListItem.previous; - - if (oldPrevious == null) { - return newPrevious == null; - } else { - return oldPrevious.equals(newPrevious); - } -} -private void putElementInfo(ICElement element, CElementInfo info) { - this.infos.put(element, info); -} -private void putNewPosition(ICElement element, ListItem position) { - this.newPositions.put(element, position); -} -private void putOldPosition(ICElement element, ListItem position) { - this.oldPositions.put(element, position); -} -/** - * Records this elements info, and attempts - * to record the info for the children. - */ -private void recordElementInfo(ICElement element, int depth) { - if (depth >= this.maxDepth) { - return; - } - CElementInfo info = (CElementInfo)CModelManager.getDefault().getInfo(element); - if (info == null) // no longer in the C model. - return; - this.putElementInfo(element, info); - - if (element instanceof IParent) { - ICElement[] children = info.getChildren(); - if (children != null) { - insertPositions(children, false); - for(int i = 0, length = children.length; i < length; i++) - recordElementInfo(children[i], depth + 1); - } - } -} -/** - * Fills the newPositions hashtable with the new position information - */ -private void recordNewPositions(ICElement newElement, int depth) throws CModelException { - if (depth < this.maxDepth && newElement instanceof IParent) { - CElementInfo info = null; - info = ((CElement)newElement).getElementInfo(); - - ICElement[] children = info.getChildren(); - if (children != null) { - insertPositions(children, true); - for(int i = 0, length = children.length; i < length; i++) { - recordNewPositions(children[i], depth + 1); - } - } - } -} -/** - * Repairs the positioning information - * after an element has been removed - */ -private void removed(ICElement element) { - this.removed.add(element); - ListItem current = this.getOldPosition(element); - ListItem previous = null, next = null; - if (current.previous != null) - previous = this.getOldPosition(current.previous); - if (current.next != null) - next = this.getOldPosition(current.next); - if (previous != null) - previous.next = current.next; - if (next != null) - next.previous = current.previous; - -} -private void removeElementInfo(ICElement element) { - this.infos.remove(element); -} -public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("Built delta:\n"); //$NON-NLS-1$ - buffer.append(this.delta.toString()); - return buffer.toString(); -} -/** - * Trims deletion deltas to only report the highest level of deletion - */ -private void trimDelta(CElementDelta delta) { - if (delta.getKind() == ICElementDelta.REMOVED) { - ICElementDelta[] children = delta.getAffectedChildren(); - for(int i = 0, length = children.length; i < length; i++) { - delta.removeAffectedChild((CElementDelta)children[i]); - } - } else { - ICElementDelta[] children = delta.getAffectedChildren(); - for(int i = 0, length = children.length; i < length; i++) { - trimDelta((CElementDelta)children[i]); - } - } -} - -}
\ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java deleted file mode 100644 index 847fa48d14f..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.File; -import java.util.List; -import java.util.Vector; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.resources.IResource; - -/** - * Holds cached structure and properties for a C element. - * Subclassed to carry properties for specific kinds of elements. - */ -class CElementInfo { - /** - * Shared empty collection used for efficiency. - */ - static Object[] NO_NON_C_RESOURCES = new Object[] {}; - - - protected CElement element; - - /** - * Collection of handles of immediate children of this - * object. This is an empty array if this element has - * no children. - */ - private List fChildren; - - /** - * Is the structure of this element known - * @see ICElement.isStructureKnown() - */ - protected boolean fIsStructureKnown = false; - - protected long modificationStamp = 0; - - protected CElementInfo(CElement element) { - this.element = element; - // Array list starts with size = 0 - fChildren = new Vector(0); - } - - protected CElement getElement() { - return element; - } - - protected void addChild(ICElement child) { - // Do not add a check if the child is contained here - // because it causes a performance bottle neck for large files. - fChildren.add(child); - } - - protected ICElement[] getChildren() { - synchronized (fChildren) { - ICElement[] array= new ICElement[fChildren.size()]; - return (ICElement[]) fChildren.toArray( array ); - } - } - - - /** - * Returns <code>true</code> if this child is in my children collection - */ - protected boolean includesChild(ICElement child) { - if(fChildren.contains(child)) - return true; - return false; - } - - /** - * @see ICElement.isStructureKnown() - */ - protected boolean isStructureKnown() { - return fIsStructureKnown; - } - - protected void removeChild(ICElement child) { - fChildren.remove(child); - } - - protected void removeChildren () { - fChildren.clear(); - } - - protected void setChildren(List children) { - fChildren.addAll(children); - } - - protected boolean hasChildren() { - return fChildren.size() > 0; - } - - protected void setChanged() { - modificationStamp = 0; - } - - protected boolean hasChanged () { - IResource r = null; - boolean b = false; - r = getElement().getUnderlyingResource(); - if (r != null && r.exists()) { - long modif = 0; - switch(r.getType()) { - // Adding/Removing does not count as changing, in Eclipse - // Ask the underlying file system - case IResource.FOLDER: - case IResource.PROJECT: - case IResource.ROOT: - File file = r.getLocation().toFile(); - modif = file.lastModified(); - break; - - case IResource.FILE: - modif = r.getModificationStamp(); - break; - } - b = (modif != modificationStamp); - modificationStamp = modif; - } - return b; - } - - /** - * Sets whether the structure of this element known - * @see ICElement.isStructureKnown() - */ - protected void setIsStructureKnown(boolean newIsStructureKnown) { - fIsStructureKnown = newIsStructureKnown; - } - - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new Error(); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java deleted file mode 100644 index b440f88689a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -public class CFileInfo extends CElementInfo { - - /** - * Constructs a new C Model Info - */ - protected CFileInfo(CElement element) { - super(element); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java deleted file mode 100644 index 4da7e5bd1da..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModel.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModel; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IProgressMonitor; - -public class CModel extends Openable implements ICModel { - - public CModel () { - this(ResourcesPlugin.getWorkspace().getRoot()); - } - - public CModel(IWorkspaceRoot root) { - super (null, root, ICElement.C_MODEL); - } - - public boolean equals(Object o) { - if (!(o instanceof CModel)) { - return false; - } - return super.equals(o); - } - - public ICProject[] getCProjects() throws CModelException { - List list = getChildrenOfType(C_PROJECT); - ICProject[] array= new ICProject[list.size()]; - list.toArray(array); - return array; - } - - /** - * ICModel#getCProject(String) - */ - public ICProject getCProject(String name) { - IProject project = ((IWorkspaceRoot)getResource()).getProject(name); - return CModelManager.getDefault().create(project); - } - - /** - * Returns the active C project associated with the specified - * resource, or <code>null</code> if no C project yet exists - * for the resource. - * - * @exception IllegalArgumentException if the given resource - * is not one of an IProject, IFolder, or IFile. - */ - public ICProject getCProject(IResource resource) { - switch(resource.getType()){ - case IResource.FOLDER: - return new CProject(this, ((IFolder)resource).getProject()); - case IResource.FILE: - return new CProject(this, ((IFile)resource).getProject()); - case IResource.PROJECT: - return new CProject(this, (IProject)resource); - default: - throw new IllegalArgumentException("element.invalidResourceForProject"); //$NON-NLS-1$ - } - } - - /** - * Finds the given project in the list of the java model's children. - * Returns null if not found. - */ - public ICProject findCProject(IProject project) { - try { - ICProject[] projects = getOldCProjectsList(); - for (int i = 0, length = projects.length; i < length; i++) { - ICProject javaProject = projects[i]; - if (project.equals(javaProject.getProject())) { - return javaProject; - } - } - } catch (CModelException e) { - // c model doesn't exist: cannot find any project - } - return null; - } - - public IWorkspace getWorkspace() { - return getUnderlyingResource().getWorkspace(); - } - - public void copy(ICElement[] elements, ICElement[] containers, ICElement[] siblings, - String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT ) { - runOperation(new CopyResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor); - } else { - throw new CModelException (new CModelStatus()); - //runOperation(new CopyElementsOperation(elements, containers, force), elements, siblings, renamings, monitor); - } - } - - public void delete(ICElement[] elements, boolean force, IProgressMonitor monitor) - throws CModelException { - if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { - runOperation(new DeleteResourceElementsOperation(elements, force), monitor); - } else { - throw new CModelException (new CModelStatus()); - //runOperation(new DeleteElementsOperation(elements, force), monitor); - } - } - - public void move(ICElement[] elements, ICElement[] containers, ICElement[] siblings, - String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { - runOperation(new MoveResourceElementsOperation(elements, containers, replace), elements, siblings, renamings, monitor); - } else { - throw new CModelException (new CModelStatus()); - //runOperation(new MoveElementsOperation(elements, containers, force), elements, siblings, renamings, monitor); - } - } - - public void rename(ICElement[] elements, ICElement[] destinations, String[] renamings, - boolean force, IProgressMonitor monitor) throws CModelException { - if (elements != null && elements[0] != null && elements[0].getElementType() <= ICElement.C_UNIT) { - runOperation(new RenameResourceElementsOperation(elements, destinations, - renamings, force), monitor); - } else { - throw new CModelException (new CModelStatus()); - //runOperation(new RenameElementsOperation(elements, containers, renamings, force), monitor); - } - } - - /** - * Configures and runs the <code>MultiOperation</code>. - */ - protected void runOperation(MultiOperation op, ICElement[] elements, ICElement[] siblings, String[] renamings, IProgressMonitor monitor) throws CModelException { - op.setRenamings(renamings); - if (siblings != null) { - for (int i = 0; i < elements.length; i++) { - op.setInsertBefore(elements[i], siblings[i]); - } - } - runOperation(op, monitor); - } - - protected CElementInfo createElementInfo () { - return new CModelInfo(this); - } - - // CHECKPOINT: Roots will return the hashcode of their resource - public int hashCode() { - return resource.hashCode(); - } - - /** - * Workaround for bug 15168 circular errors not reported - * Returns the list of java projects before resource delta processing - * has started. - */ - public ICProject[] getOldCProjectsList() throws CModelException { - CModelManager manager = CModelManager.getDefault(); - return manager.cProjectsCache == null ? - getCProjects() : - manager.cProjectsCache; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { - boolean validInfo = false; - try { - IResource res = getResource(); - if (res != null && (res instanceof IWorkspaceRoot || res.getProject().isOpen())) { - validInfo = computeChildren(info, res); - } - } finally { - if (!validInfo) { - CModelManager.getDefault().removeInfo(this); - } - } - return validInfo; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICModel#getNonCResources() - */ - public Object[] getNonCResources() throws CModelException { - return ((CModelInfo)getElementInfo()).getNonCResources(); - } - - protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { - // determine my children - IWorkspaceRoot root = (IWorkspaceRoot)getResource(); - IProject[] projects = root.getProjects(); - for (int i = 0, max = projects.length; i < max; i++) { - IProject project = projects[i]; - if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) { - ICProject cproject = new CProject(this, project); - info.addChild(cproject); - } - } - ((CModelInfo)getElementInfo()).setNonCResources(null); - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java deleted file mode 100644 index 813796c0946..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ /dev/null @@ -1,743 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001 Rational Software Corp. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - initial implementation - ******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.model.ITemplate; -import org.eclipse.cdt.core.parser.CodeReader; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IQuickParseCallback; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; -import org.eclipse.cdt.core.parser.NullLogService; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.cdt.core.parser.ast.ASTClassKind; -import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException; -import org.eclipse.cdt.core.parser.ast.ASTUtil; -import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit; -import org.eclipse.cdt.core.parser.ast.IASTDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; -import org.eclipse.cdt.core.parser.ast.IASTField; -import org.eclipse.cdt.core.parser.ast.IASTFunction; -import org.eclipse.cdt.core.parser.ast.IASTInclusion; -import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; -import org.eclipse.cdt.core.parser.ast.IASTMacro; -import org.eclipse.cdt.core.parser.ast.IASTMethod; -import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition; -import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement; -import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier; -import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner; -import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; -import org.eclipse.cdt.core.parser.ast.IASTVariable; -import org.eclipse.cdt.internal.core.parser.ParserException; -import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; - - -public class CModelBuilder { - - private org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit; - private Map newElements; - private IQuickParseCallback quickParseCallback; - private IASTCompilationUnit compilationUnit; - // indicator if the unit has parse errors - private boolean hasNoErrors = false; - - class ProblemCallback extends StructuralParseCallback { - IProblemRequestor problemRequestor; - - public ProblemCallback(IProblemRequestor requestor) { - problemRequestor = requestor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.QuickParseCallback#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) { - // Do not worry for now about problems in other files. - if (inclusionLevel == 0) { - problemRequestor.acceptProblem(problem); - } - return true; - } - } - - public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu, Map newElements) { - this.translationUnit = tu ; - this.newElements = newElements; - } - - private IASTCompilationUnit parse(boolean quickParseMode, boolean throwExceptionOnError) throws ParserException - { - IProject currentProject = null; - boolean hasCppNature = true; - String code = ""; //$NON-NLS-1$ - - // get the current project - if (translationUnit != null && translationUnit.getCProject() != null) { - currentProject = translationUnit.getCProject().getProject(); - } - // check the project's nature - if( currentProject != null ) - { - hasCppNature = CoreModel.hasCCNature(currentProject); - } - // get the code to parse - try{ - code = translationUnit.getBuffer().getContents(); - } catch (CModelException e) { - - } - - final IProblemRequestor problemRequestor = translationUnit.getProblemRequestor(); - // use quick or structural parse mode - ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE; - if (problemRequestor == null) { - quickParseCallback = (quickParseMode) ? ParserFactory.createQuickParseCallback() : - ParserFactory.createStructuralParseCallback(); - } else { - quickParseCallback = new ProblemCallback(problemRequestor); - } - - // pick the language - ParserLanguage language; - if (hasCppNature) { - language = ParserLanguage.CPP; - } else { - // for C project try to guess. - language = translationUnit.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C; - } - - // create the parser - IParser parser = null; - try - { - - IScannerInfo scanInfo = new ScannerInfo(); - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject); - if (provider != null){ - IScannerInfo buildScanInfo = null; - IResource res = translationUnit.getResource(); - if (res != null) { - buildScanInfo = provider.getScannerInformation(res); - } - // Technically we should not do this. But the managed scanner providers - // may rely on this behaviour i.e. only provide scannerInfo for projects - if (buildScanInfo == null) { - buildScanInfo = provider.getScannerInformation(currentProject); - } - if (buildScanInfo != null){ - scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths()); - } - } - - CodeReader reader = - translationUnit.getUnderlyingResource() != null - ? new CodeReader(translationUnit.getUnderlyingResource().getLocation().toOSString(), code.toCharArray()) - : new CodeReader(code.toCharArray()); - parser = ParserFactory.createParser( - ParserFactory.createScanner( - reader, - scanInfo, - mode, - language, - quickParseCallback, - quickParseMode ? new NullLogService() : ParserUtil.getScannerLogService(), null) - ,quickParseCallback, - mode, - language, - ParserUtil.getParserLogService() ); - } - catch( ParserFactoryError pfe ) - { - throw new ParserException( CCorePlugin.getResourceString("CModelBuilder.Parser_Construction_Failure")); //$NON-NLS-1$ - } - // call parse - if (problemRequestor != null) { - problemRequestor.beginReporting(); - } - hasNoErrors = parser.parse(); - if (problemRequestor != null) { - problemRequestor.endReporting(); - } - if( (!hasNoErrors) && throwExceptionOnError ) - throw new ParserException(CCorePlugin.getResourceString("CModelBuilder.Parse_Failure")); //$NON-NLS-1$ - return quickParseCallback.getCompilationUnit(); - } - - - public Map parse(boolean quickParseMode) throws Exception { - long startTime = System.currentTimeMillis(); - try - { - compilationUnit = parse(quickParseMode, true); - } - - catch( ParserException e ) - { - Util.debugLog( "Parse Exception in CModelBuilder", IDebugLogConstants.MODEL ); //$NON-NLS-1$ - //e.printStackTrace(); - } - Util.debugLog("CModel parsing: "+ ( System.currentTimeMillis() - startTime ) + "ms", IDebugLogConstants.MODEL); //$NON-NLS-1$ //$NON-NLS-2$ - - startTime = System.currentTimeMillis(); - try - { - generateModelElements(); - // important to know if the unit has parse errors or not - translationUnit.getElementInfo().setIsStructureKnown(hasNoErrors && quickParseCallback.hasNoProblems()); - } - catch( NullPointerException npe ) - { - Util.debugLog( "NullPointer exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$ - } - - // For the debuglog to take place, you have to call - // Util.setDebugging(true); - // Or set debug to true in the core plugin preference - Util.debugLog("CModel building: "+ ( System.currentTimeMillis() - startTime ) + "ms", IDebugLogConstants.MODEL); //$NON-NLS-1$ //$NON-NLS-2$ - return this.newElements; - - } - - private void generateModelElements() throws CModelException{ - Iterator i = quickParseCallback.iterateOffsetableElements(); - while (i.hasNext()){ - IASTOffsetableElement offsetable = (IASTOffsetableElement)i.next(); - if(offsetable instanceof IASTInclusion){ - createInclusion(translationUnit, (IASTInclusion) offsetable); - } - else if(offsetable instanceof IASTMacro){ - createMacro(translationUnit, (IASTMacro) offsetable); - }else if(offsetable instanceof IASTDeclaration){ - try{ - generateModelElements (translationUnit, (IASTDeclaration) offsetable); - } catch(ASTNotImplementedException e){ - } - } - } - } - - private void generateModelElements (Parent parent, IASTDeclaration declaration) throws CModelException, ASTNotImplementedException - { - if(declaration instanceof IASTNamespaceDefinition ) { - generateModelElements(parent, (IASTNamespaceDefinition) declaration); - } - - if(declaration instanceof IASTAbstractTypeSpecifierDeclaration ) { - generateModelElements(parent, (IASTAbstractTypeSpecifierDeclaration) declaration); - } - - if(declaration instanceof IASTTemplateDeclaration ) { - generateModelElements(parent, (IASTTemplateDeclaration) declaration); - } - - if(declaration instanceof IASTTypedefDeclaration ) { - generateModelElements(parent, (IASTTypedefDeclaration) declaration); - } - - if(declaration instanceof IASTLinkageSpecification) { - generateModelElements(parent, (IASTLinkageSpecification)declaration); - } - createSimpleElement(parent, declaration, false); - } - - private void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws CModelException, ASTNotImplementedException{ - // IASTNamespaceDefinition - IParent namespace = createNamespace(parent, declaration); - Iterator nsDecls = declaration.getDeclarations(); - while (nsDecls.hasNext()){ - IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next(); - generateModelElements((Parent)namespace, subNsDeclaration); - } - } - - private void generateModelElements (Parent parent, IASTLinkageSpecification declaration) throws CModelException, ASTNotImplementedException{ - // IASTLinkageSpecification - Iterator nsDecls = declaration.getDeclarations(); - while (nsDecls.hasNext()){ - IASTDeclaration subNsDeclaration = (IASTDeclaration) nsDecls.next(); - generateModelElements(parent, subNsDeclaration); - } - } - - private void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws CModelException, ASTNotImplementedException - { - // IASTAbstractTypeSpecifierDeclaration - CElement element = createAbstractElement(parent, abstractDeclaration, false); - } - - private void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws CModelException, ASTNotImplementedException - { - // Template Declaration - IASTDeclaration declaration = templateDeclaration.getOwnedDeclaration(); - if(declaration instanceof IASTAbstractTypeSpecifierDeclaration){ - IASTAbstractTypeSpecifierDeclaration abstractDeclaration = (IASTAbstractTypeSpecifierDeclaration)declaration ; - CElement element = createAbstractElement(parent, abstractDeclaration , true); - if(element != null){ - // set the element position - element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); - element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() ); - // set the template parameters - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - ITemplate classTemplate = (ITemplate) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } - } else if (declaration instanceof IASTClassSpecifier){ - // special case for Structural parse - IASTClassSpecifier classSpecifier = (IASTClassSpecifier)declaration ; - CElement element = createClassSpecifierElement(parent, classSpecifier , true); - if(element != null){ - // set the element position - element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); - element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() ); - // set the template parameters - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - ITemplate classTemplate = (ITemplate) element; - classTemplate.setTemplateParameterTypes(parameterTypes); - } - } - ITemplate template = null; - template = (ITemplate) createSimpleElement(parent, declaration, true); - - if(template != null){ - CElement element = (CElement)template; - // set the element position - element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset()); - element.setLines( templateDeclaration.getStartingLine(), templateDeclaration.getEndingLine() ); - // set the template parameters - String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration); - template.setTemplateParameterTypes(parameterTypes); - } - } - - private void generateModelElements (Parent parent, IASTTypedefDeclaration declaration) throws CModelException, ASTNotImplementedException - { - TypeDef typeDef = createTypeDef(parent, declaration); - IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator(); - CElement element = createAbstractElement(parent, abstractDeclaration, false); - } - - private CElement createClassSpecifierElement(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate)throws ASTNotImplementedException, CModelException{ - CElement element = null; - IParent classElement = createClass(parent, classSpecifier, isTemplate); - element = (CElement) classElement; - - // create the sub declarations - Iterator j = classSpecifier.getDeclarations(); - while (j.hasNext()){ - IASTDeclaration subDeclaration = (IASTDeclaration)j.next(); - generateModelElements((Parent)classElement, subDeclaration); - } // end while j - return element; - } - - private CElement createAbstractElement(Parent parent, IASTTypeSpecifierOwner abstractDeclaration, boolean isTemplate)throws ASTNotImplementedException, CModelException{ - CElement element = null; - if(abstractDeclaration != null){ - IASTTypeSpecifier typeSpec = abstractDeclaration.getTypeSpecifier(); - // IASTEnumerationSpecifier - if ( typeSpec instanceof IASTEnumerationSpecifier){ - IASTEnumerationSpecifier enumSpecifier = (IASTEnumerationSpecifier) typeSpec; - IParent enumElement = createEnumeration (parent, enumSpecifier); - element = (CElement) enumElement; - } - // IASTClassSpecifier - else if (typeSpec instanceof IASTClassSpecifier){ - IASTClassSpecifier classSpecifier = (IASTClassSpecifier) typeSpec; - element = createClassSpecifierElement (parent, classSpecifier, isTemplate); - } else if (typeSpec instanceof IASTElaboratedTypeSpecifier){ - // This is not a model element, so we don't create anything here. - // However, do we need to do anything else? - } - } - return element; - } - - private CElement createSimpleElement(Parent parent, IASTDeclaration declaration, boolean isTemplate)throws CModelException, ASTNotImplementedException{ - - CElement element = null; - if (declaration instanceof IASTVariable) - { - element = createVariableSpecification(parent, (IASTVariable)declaration, isTemplate); - } - // function or method - else if(declaration instanceof IASTFunction ) - { - element = createFunctionSpecification(parent, (IASTFunction)declaration, isTemplate); - } - return element; - } - - private Include createInclusion(Parent parent, IASTInclusion inclusion) throws CModelException{ - // create element - Include element = new Include(parent, inclusion.getName(), !inclusion.isLocal()); - element.setFullPathName(inclusion.getFullFileName()); - // add to parent - parent.addChild(element); - // set position - element.setIdPos(inclusion.getNameOffset(), inclusion.getNameEndOffset() - inclusion.getNameOffset()); - element.setPos(inclusion.getStartingOffset(), inclusion.getEndingOffset() - inclusion.getStartingOffset()); - element.setLines( inclusion.getStartingLine(), inclusion.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Macro createMacro(Parent parent, IASTMacro macro) throws CModelException{ - // create element - org.eclipse.cdt.internal.core.model.Macro element = new Macro(parent, macro.getName()); - // add to parent - parent.addChild(element); - // set position - element.setIdPos(macro.getNameOffset(), macro.getNameEndOffset() - macro.getNameOffset()); - element.setPos(macro.getStartingOffset(), macro.getEndingOffset() - macro.getStartingOffset()); - element.setLines( macro.getStartingLine(), macro.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - - } - - private Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef) throws CModelException{ - // create element - String type = "namespace"; //$NON-NLS-1$ - String nsName = (nsDef.getName() == null ) - ? "" //$NON-NLS-1$ - : nsDef.getName().toString(); - Namespace element = new Namespace (parent, nsName ); - // add to parent - parent.addChild(element); - element.setIdPos(nsDef.getNameOffset(), - (nsName.length() == 0) ? type.length() : (nsDef.getNameEndOffset() - nsDef.getNameOffset())); - element.setPos(nsDef.getStartingOffset(), nsDef.getEndingOffset() - nsDef.getStartingOffset()); - element.setLines( nsDef.getStartingLine(), nsDef.getEndingLine() ); - element.setTypeName(type); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Enumeration createEnumeration(Parent parent, IASTEnumerationSpecifier enumSpecifier) throws CModelException{ - // create element - String type = "enum"; //$NON-NLS-1$ - String enumName = (enumSpecifier.getName() == null ) - ? "" //$NON-NLS-1$ - : enumSpecifier.getName().toString(); - Enumeration element = new Enumeration (parent, enumName ); - // add to parent - parent.addChild(element); - Iterator i = enumSpecifier.getEnumerators(); - while (i.hasNext()){ - // create sub element - IASTEnumerator enumDef = (IASTEnumerator) i.next(); - createEnumerator(element, enumDef); - } - // set enumeration position - element.setIdPos(enumSpecifier.getNameOffset(), - (enumName.length() == 0) ? type.length() : (enumSpecifier.getNameEndOffset() - enumSpecifier.getNameOffset() )); - element.setPos(enumSpecifier.getStartingOffset(), enumSpecifier.getEndingOffset() - enumSpecifier.getStartingOffset()); - element.setLines( enumSpecifier.getStartingLine(), enumSpecifier.getEndingLine() ); - element.setTypeName(type); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Enumerator createEnumerator(Parent enum, IASTEnumerator enumDef) throws CModelException{ - Enumerator element = new Enumerator (enum, enumDef.getName().toString()); - IASTExpression initialValue = enumDef.getInitialValue(); - if(initialValue != null){ - element.setConstantExpression( ASTUtil.getExpressionString( initialValue ) ); - } - // add to parent - enum.addChild(element); - // set enumerator position - element.setIdPos(enumDef.getStartingOffset(), (enumDef.getNameEndOffset() - enumDef.getNameOffset())); - element.setPos(enumDef.getStartingOffset(), enumDef.getEndingOffset() - enumDef.getStartingOffset()); - element.setLines( enumDef.getStartingLine(), enumDef.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private Structure createClass(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate) throws CModelException{ - // create element - String className = ""; //$NON-NLS-1$ - String type = ""; //$NON-NLS-1$ - int kind = ICElement.C_CLASS; - ASTClassKind classkind = classSpecifier.getClassKind(); - if(classkind == ASTClassKind.CLASS){ - if(!isTemplate) - kind = ICElement.C_CLASS; - else - kind = ICElement.C_TEMPLATE_CLASS; - type = "class"; //$NON-NLS-1$ - className = (classSpecifier.getName() == null ) - ? "" //$NON-NLS-1$ - : classSpecifier.getName().toString(); - } - if(classkind == ASTClassKind.STRUCT){ - if(!isTemplate) - kind = ICElement.C_STRUCT; - else - kind = ICElement.C_TEMPLATE_STRUCT; - type = "struct"; //$NON-NLS-1$ - className = (classSpecifier.getName() == null ) - ? "" //$NON-NLS-1$ - : classSpecifier.getName().toString(); - } - if(classkind == ASTClassKind.UNION){ - if(!isTemplate) - kind = ICElement.C_UNION; - else - kind = ICElement.C_TEMPLATE_UNION; - type = "union"; //$NON-NLS-1$ - className = (classSpecifier.getName() == null ) - ? "" //$NON-NLS-1$ - : classSpecifier.getName().toString(); - } - - Structure element; - if(!isTemplate){ - Structure classElement = new Structure( parent, kind, className ); - element = classElement; - } else { - StructureTemplate classTemplate = new StructureTemplate( parent, kind, className ); - element = classTemplate; - } - - // store super classes names - Iterator baseClauses = classSpecifier.getBaseClauses(); - while (baseClauses.hasNext()){ - IASTBaseSpecifier baseSpec = (IASTBaseSpecifier)baseClauses.next(); - element.addSuperClass(baseSpec.getParentClassName(), baseSpec.getAccess()); - } - - // add to parent - parent.addChild(element); - // set element position - element.setIdPos( classSpecifier.getNameOffset(), - (className.length() == 0) ? type.length() : (classSpecifier.getNameEndOffset() - classSpecifier.getNameOffset() )); - element.setTypeName( type ); - if(!isTemplate){ - // set the element position - element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getEndingOffset() - classSpecifier.getStartingOffset()); - } - element.setLines( classSpecifier.getStartingLine(), classSpecifier.getEndingLine() ); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private TypeDef createTypeDef(Parent parent, IASTTypedefDeclaration typeDefDeclaration) throws CModelException{ - // create the element - String name = typeDefDeclaration.getName(); - - TypeDef element = new TypeDef( parent, name ); - - StringBuffer typeName = new StringBuffer(ASTUtil.getType(typeDefDeclaration.getAbstractDeclarator())); - element.setTypeName(typeName.toString()); - - // add to parent - parent.addChild(element); - - // set positions - element.setIdPos(typeDefDeclaration.getNameOffset(), (typeDefDeclaration.getNameEndOffset() - typeDefDeclaration.getNameOffset())); - element.setPos(typeDefDeclaration.getStartingOffset(), typeDefDeclaration.getEndingOffset() - typeDefDeclaration.getStartingOffset()); - element.setLines( typeDefDeclaration.getStartingLine(), typeDefDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws CModelException, ASTNotImplementedException - { - String variableName = varDeclaration.getName(); - if((variableName == null) || (variableName.length() <= 0)){ - // something is wrong, skip this element - return null; - } - - IASTAbstractDeclaration abstractDeclaration = varDeclaration.getAbstractDeclaration(); - CElement abstractElement = createAbstractElement (parent, abstractDeclaration , isTemplate); - - VariableDeclaration element = null; - if(varDeclaration instanceof IASTField){ - IASTField fieldDeclaration = (IASTField) varDeclaration; - // field - Field newElement = new Field( parent, variableName); - newElement.setMutable(fieldDeclaration.isMutable()); - newElement.setVisibility(fieldDeclaration.getVisiblity()); - element = newElement; - } - else { - if(isTemplate){ - // variable - VariableTemplate newElement = new VariableTemplate( parent, variableName ); - element = newElement; - }else { - if(varDeclaration.isExtern()){ - // variableDeclaration - VariableDeclaration newElement = new VariableDeclaration( parent, variableName ); - element = newElement; - } - else { - // variable - Variable newElement = new Variable( parent, variableName ); - element = newElement; - } - } - } - element.setTypeName ( ASTUtil.getType(varDeclaration.getAbstractDeclaration()) ); - element.setConst(varDeclaration.getAbstractDeclaration().isConst()); - element.setVolatile(varDeclaration.getAbstractDeclaration().isVolatile()); - element.setStatic(varDeclaration.isStatic()); - // add to parent - parent.addChild( element ); - - // set position - element.setIdPos( varDeclaration.getNameOffset(), (varDeclaration.getNameEndOffset() - varDeclaration.getNameOffset()) ); - if(!isTemplate){ - // set element position - element.setPos(varDeclaration.getStartingOffset(), varDeclaration.getEndingOffset() - varDeclaration.getStartingOffset()); - } - element.setLines( varDeclaration.getStartingLine(), varDeclaration.getEndingLine() ); - this.newElements.put(element, element.getElementInfo()); - return element; - } - - private FunctionDeclaration createFunctionSpecification(Parent parent, IASTFunction functionDeclaration, boolean isTemplate) throws CModelException - { - String name = functionDeclaration.getName(); - if ((name == null) || (name.length() <= 0)) { - // Something is wrong, skip this element - return null; - } - - // get parameters types - String[] parameterTypes = ASTUtil.getFunctionParameterTypes(functionDeclaration); - - FunctionDeclaration element = null; - - if( functionDeclaration instanceof IASTMethod ) - { - IASTMethod methodDeclaration = (IASTMethod) functionDeclaration; - MethodDeclaration methodElement = null; - if (methodDeclaration.hasFunctionBody()) - { - // method - if(!isTemplate){ - Method newElement = new Method( parent, name ); - methodElement = newElement; - }else { - MethodTemplate newElement = new MethodTemplate(parent, name); - methodElement = newElement; - } - } - else - { - // method declaration - if(!isTemplate){ - MethodDeclaration newElement = new MethodDeclaration( parent, name ); - methodElement = newElement; - }else { - MethodTemplate newElement = new MethodTemplate(parent, name); - methodElement = newElement; - } - - } - methodElement.setParameterTypes(parameterTypes); - methodElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) ); - methodElement.setStatic(functionDeclaration.isStatic()); - - // Common settings for method declaration - methodElement.setVisibility(methodDeclaration.getVisiblity()); - methodElement.setVolatile(methodDeclaration.isVolatile()); - methodElement.setConst(methodDeclaration.isConst()); - methodElement.setVirtual(methodDeclaration.isVirtual()); - methodElement.setPureVirtual(methodDeclaration.isPureVirtual()); - methodElement.setInline(methodDeclaration.isInline()); - methodElement.setFriend(methodDeclaration.isFriend()); - methodElement.setConstructor(methodDeclaration.isConstructor()); - methodElement.setDestructor(methodDeclaration.isDestructor()); - element = methodElement; - } - else // instance of IASTFunction - { - FunctionDeclaration functionElement = null; - if (functionDeclaration.hasFunctionBody()) - { - // function - if(!isTemplate){ - Function newElement = new Function( parent, name ); - functionElement = newElement; - } else { - FunctionTemplate newElement = new FunctionTemplate( parent, name ); - functionElement = newElement; - } - } - else - { - // functionDeclaration - if(!isTemplate){ - FunctionDeclaration newElement = new FunctionDeclaration( parent, name ); - functionElement = newElement; - } else { - FunctionTemplate newElement = new FunctionTemplate( parent, name ); - functionElement = newElement; - } - } - functionElement.setParameterTypes(parameterTypes); - functionElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) ); - functionElement.setStatic(functionDeclaration.isStatic()); - element = functionElement; - } - // add to parent - parent.addChild( element ); - - // hook up the offsets - element.setIdPos( functionDeclaration.getNameOffset(), (functionDeclaration.getNameEndOffset() - functionDeclaration.getNameOffset()) ); - if(!isTemplate){ - // set the element position - element.setPos(functionDeclaration.getStartingOffset(), functionDeclaration.getEndingOffset() - functionDeclaration.getStartingOffset()); - } - element.setLines( functionDeclaration.getStartingLine(), functionDeclaration.getEndingLine() ); - - this.newElements.put(element, element.getElementInfo()); - return element; - } - - /** - * @return Returns the newElements. - */ - public Map getNewElements() { - return newElements; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java deleted file mode 100644 index a03ad056cd9..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelCache.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; - - -/** - * The cache of C elements to their respective info. - * - * This class is similar to the JDT CModelCache class. - */ -public class CModelCache { - public static final int PROJ_CACHE_SIZE = 50; - public static final int FOLDER_CACHE_SIZE = 500; - public static final int FILE_CACHE_SIZE = 2000; - public static final int CHILDREN_CACHE_SIZE = FILE_CACHE_SIZE * 20; - - /** - * Cache of open projects and roots. - */ - protected Map projectAndRootCache; - - /** - * Cache of open containers - */ - protected Map folderCache; - - /** - * Cache of open translation unit files - */ - protected OverflowingLRUCache fileCache; - - /** - * Cache of children of C elements - */ - protected Map childrenCache; - -public CModelCache() { - this.projectAndRootCache = new HashMap(PROJ_CACHE_SIZE); - this.folderCache = new HashMap(FOLDER_CACHE_SIZE); - this.fileCache = new ElementCache(FILE_CACHE_SIZE); - this.childrenCache = new HashMap(CHILDREN_CACHE_SIZE); // average 20 children per openable -} - -public double openableFillingRatio() { - return this.fileCache.fillingRatio(); -} - -/** - * Returns the info for the element. - */ -public Object getInfo(ICElement element) { - switch (element.getElementType()) { - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - return this.projectAndRootCache.get(element); - case ICElement.C_CCONTAINER: - return this.folderCache.get(element); - case ICElement.C_ARCHIVE: - case ICElement.C_BINARY: - case ICElement.C_UNIT: - return this.fileCache.get(element); - default: - return this.childrenCache.get(element); - } -} - -/** - * Returns the info for this element without - * disturbing the cache ordering. - */ -protected Object peekAtInfo(ICElement element) { - switch (element.getElementType()) { - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - return this.projectAndRootCache.get(element); - case ICElement.C_CCONTAINER: - return this.folderCache.get(element); - case ICElement.C_ARCHIVE: - case ICElement.C_BINARY: - case ICElement.C_UNIT: - return this.fileCache.peek(element); - default: - return this.childrenCache.get(element); - } -} - -/** - * Remember the info for the element. - */ -protected void putInfo(ICElement element, Object info) { - switch (element.getElementType()) { - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - this.projectAndRootCache.put(element, info); - break; - case ICElement.C_CCONTAINER: - this.folderCache.put(element, info); - break; - case ICElement.C_ARCHIVE: - case ICElement.C_BINARY: - case ICElement.C_UNIT: - this.fileCache.put(element, info); - break; - default: - this.childrenCache.put(element, info); - } -} -/** - * Removes the info of the element from the cache. - */ -protected void removeInfo(ICElement element) { - switch (element.getElementType()) { - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - this.projectAndRootCache.remove(element); - break; - case ICElement.C_CCONTAINER: - this.folderCache.remove(element); - break; - case ICElement.C_ARCHIVE: - case ICElement.C_BINARY: - case ICElement.C_UNIT: - this.fileCache.remove(element); - break; - default: - this.childrenCache.remove(element); - } -} - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java deleted file mode 100644 index 2476a0ba3ab..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelInfo.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * @see ICModel - */ -public class CModelInfo extends OpenableInfo { - - Object[] nonCResources = null; - - /** - * Constructs a new C Model Info - */ - protected CModelInfo(CElement element) { - super(element); - } - - /** - * Compute the non-C resources contained in this C project. - */ - private Object[] computeNonCResources() { - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - int length = projects.length; - Object[] nonCProjects = null; - int index = 0; - for (int i = 0; i < length; i++) { - IProject project = projects[i]; - if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) { - if (nonCProjects == null) { - nonCProjects = new Object[length]; - } - nonCProjects[index++] = project; - } - } - if (index == 0) { - return NO_NON_C_RESOURCES; - } - if (index < length) { - System.arraycopy(nonCProjects, 0, nonCProjects = new Object[index], 0, index); - } - return nonCProjects; - } - - /** - * Returns an array of non-C resources contained in the receiver. - */ - Object[] getNonCResources() { - if (nonCResources == null) { - nonCResources = computeNonCResources(); - } - return nonCResources; - } - - /** - * @return - */ - public void setNonCResources(Object[] resources) { - nonCResources = resources; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java deleted file mode 100644 index a2c6a4d5b9a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ /dev/null @@ -1,1080 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.BinaryParserConfig; -import org.eclipse.cdt.core.CCProjectNature; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.CDescriptorEvent; -import org.eclipse.cdt.core.CProjectNature; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.cdt.core.ICDescriptor; -import org.eclipse.cdt.core.ICDescriptorListener; -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ElementChangedEvent; -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICModel; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IElementChangedListener; -import org.eclipse.cdt.core.model.IIncludeReference; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.Platform; - -public class CModelManager implements IResourceChangeListener, ICDescriptorListener { - - public static boolean VERBOSE = false; - - /** - * Unique handle onto the CModel - */ - final CModel cModel = new CModel(); - - public static HashSet OptionNames = new HashSet(20); - - public static final int DEFAULT_CHANGE_EVENT = 0; // must not collide with ElementChangedEvent event masks - - /** - * Used to convert <code>IResourceDelta</code>s into <code>ICElementDelta</code>s. - */ - protected DeltaProcessor fDeltaProcessor = new DeltaProcessor(); - - /** - * Queue of deltas created explicily by the C Model that - * have yet to be fired. - */ - List fCModelDeltas = Collections.synchronizedList(new ArrayList()); - - /** - * Queue of reconcile deltas on working copies that have yet to be fired. - * This is a table form IWorkingCopy to IJavaElementDelta - */ - HashMap reconcileDeltas = new HashMap(); - - /** - * Turns delta firing on/off. By default it is on. - */ - protected boolean fFire = true; - - /** - * Collection of listeners for C element deltas - */ - protected List fElementChangedListeners = Collections.synchronizedList(new ArrayList()); - - /** - * A map from ITranslationUnit to IWorkingCopy of the shared working copies. - */ - public Map sharedWorkingCopies = new HashMap(); - /** - * Set of elements which are out of sync with their buffers. - */ - protected Map elementsOutOfSynchWithBuffers = new HashMap(11); - - /* - * Temporary cache of newly opened elements - */ - private ThreadLocal temporaryCache = new ThreadLocal(); - - /** - * Infos cache. - */ - protected CModelCache cache = new CModelCache(); - - /** - * This is a cache of the projects before any project addition/deletion has started. - */ - public ICProject[] cProjectsCache; - - /** - * The list of started BinaryRunners on projects. - */ - private HashMap binaryRunners = new HashMap(); - - /** - * Map of the binary parser for each project. - */ - private HashMap binaryParsersMap = new HashMap(); - - /** - * The lis of the SourceMappers on projects. - */ - private HashMap sourceMappers = new HashMap(); - - public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0]; - - static CModelManager factory = null; - - private CModelManager() { - } - - public static CModelManager getDefault() { - if (factory == null) { - factory = new CModelManager(); - - // Register to the workspace; - ResourcesPlugin.getWorkspace().addResourceChangeListener(factory, - IResourceChangeEvent.POST_CHANGE - | IResourceChangeEvent.PRE_DELETE - | IResourceChangeEvent.PRE_CLOSE); - - // Register the Core Model on the Descriptor - // Manager, it needs to know about changes. - CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(factory); - } - return factory; - } - - /** - * Returns the CModel for the given workspace, creating - * it if it does not yet exist. - */ - public ICModel getCModel(IWorkspaceRoot root) { - return getCModel(); - } - - public CModel getCModel() { - return cModel; - } - - public ICElement create (IPath path) { - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - // Assume it is fullpath relative to workspace - IResource res = root.findMember(path); - if (res == null) { - IPath rootPath = root.getLocation(); - if (path.equals(rootPath)) { - return getCModel(root); - } - res = root.getContainerForLocation(path); - if (res == null || !res.exists()) { - res = root.getFileForLocation(path); - } - if (res != null && !res.exists()) { - res = null; - } - } - // TODO: for extenal resources ?? - return create(res, null); - } - - public ICElement create (IResource resource, ICProject cproject) { - if (resource == null) { - return null; - } - - int type = resource.getType(); - switch (type) { - case IResource.PROJECT : - return create((IProject)resource); - case IResource.FILE : - return create((IFile)resource, cproject); - case IResource.FOLDER : - return create((IFolder)resource, cproject); - case IResource.ROOT : - return getCModel((IWorkspaceRoot)resource); - default : - return null; - } - } - - public ICProject create(IProject project) { - if (project == null) { - return null; - } - return cModel.getCProject(project); - } - - public ICContainer create(IFolder folder, ICProject cproject) { - if (folder == null) { - return null; - } - if (cproject == null) { - cproject = create(folder.getProject()); - } - ICContainer celement = null; - IPath resourcePath = folder.getFullPath(); - try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - IPath rootPath = root.getPath(); - if (rootPath.equals(resourcePath)) { - celement = root; - break; // We are done. - } else if (root.isOnSourceEntry(folder)) { - IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - String[] segments = path.segments(); - ICContainer cfolder = root; - for (int j = 0; j < segments.length; j++) { - cfolder = cfolder.getCContainer(segments[j]); - } - celement = cfolder; - } - } - } catch (CModelException e) { - // - } - return celement; - } - - public ICElement create(IFile file, ICProject cproject) { - if (file == null) { - return null; - } - if (cproject == null) { - cproject = create(file.getProject()); - } - boolean checkIfBinary = false; - ICElement celement = null; - try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - if (root.isOnSourceEntry(file)) { - IPath rootPath = root.getPath(); - IPath resourcePath = file.getFullPath(); - IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - String fileName = path.lastSegment(); - path = path.removeLastSegments(1); - String[] segments = path.segments(); - ICContainer cfolder = root; - for (int j = 0; j < segments.length; j++) { - cfolder = cfolder.getCContainer(segments[j]); - } - - if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) { - celement = cfolder.getTranslationUnit(fileName); - } else if (cproject.isOnOutputEntry(file)) { - IBinaryFile bin = createBinaryFile(file); - if (bin != null) { - if (bin.getType() == IBinaryFile.ARCHIVE) { - celement = new Archive(cfolder, file, (IBinaryArchive)bin); - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - vlib.addChild(celement); - } else { - celement = new Binary(cfolder, file, (IBinaryObject)bin); - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - vbin.addChild(celement); - } - } - checkIfBinary = true; - } - break; - } - } - - // try in the outputEntry and save in the container - // But do not create an ICElement since they are not in the Model per say - if (celement == null && !checkIfBinary && cproject.isOnOutputEntry(file)) { - IBinaryFile bin = createBinaryFile(file); - if (bin != null) { - if (bin.getType() == IBinaryFile.ARCHIVE) { - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - celement = new Archive(vlib, file, (IBinaryArchive)bin); - vlib.addChild(celement); - } else { - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - celement = new Binary(vbin, file, (IBinaryObject)bin); - vbin.addChild(celement); - } - } - } - } catch (CModelException e) { - // - } - return celement; - } - - public ICElement create(IFile file, IBinaryFile bin, ICProject cproject) { - if (file == null) { - return null; - } - if (bin == null) { - return create(file, cproject); - } - if (cproject == null) { - cproject = create(file.getProject()); - } - ICElement celement = null; - try { - ISourceRoot[] roots = cproject.getAllSourceRoots(); - for (int i = 0; i < roots.length; ++i) { - ISourceRoot root = roots[i]; - if (root.isOnSourceEntry(file)) { - IPath rootPath = root.getPath(); - IPath resourcePath = file.getFullPath(); - IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); - path = path.removeLastSegments(1); - String[] segments = path.segments(); - ICContainer cfolder = root; - for (int j = 0; j < segments.length; j++) { - cfolder = cfolder.getCContainer(segments[j]); - } - - if (bin.getType() == IBinaryFile.ARCHIVE) { - celement = new Archive(cfolder, file, (IBinaryArchive)bin); - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - vlib.addChild(celement); - } else { - celement = new Binary(cfolder, file, (IBinaryObject)bin); - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - vbin.addChild(celement); - } - break; - } - } - - // try in the outputEntry and save in the container - // But do not create a ICElement since they are not in the Model per say - if (celement == null) { - if (bin.getType() == IBinaryFile.ARCHIVE) { - ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); - celement = new Archive(vlib, file, (IBinaryArchive)bin); - vlib.addChild(celement); - } else { - BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); - celement = new Binary(vbin, file, (IBinaryObject)bin); - vbin.addChild(celement); - } - } - } catch (CModelException e) { - // - } - return celement; - } - - public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) { - if (path == null || cproject == null) { - return null; - } - if (path.isAbsolute()) { - File file = path.toFile(); - if (file == null || !file.isFile()) { - return null; - } - try { - IIncludeReference[] includeReferences = cproject.getIncludeReferences(); - for (int i = 0; i < includeReferences.length; i++) { - if (includeReferences[i].isOnIncludeEntry(path)) { - return new ExternalTranslationUnit(includeReferences[i], path); - } - } - } catch (CModelException e) { - } - } else { - try { - IIncludeReference[] includeReferences = cproject.getIncludeReferences(); - for (int i = 0; i < includeReferences.length; i++) { - IPath includePath = includeReferences[i].getPath().append(path); - File file = includePath.toFile(); - if (file != null && file.isFile()) { - return new ExternalTranslationUnit(includeReferences[i], includePath); - } - } - } catch (CModelException e) { - } - } - return null; - } - - public void releaseCElement(ICElement celement) { - - // Guard. - if (celement == null) - return; - -//System.out.println("RELEASE " + celement.getElementName()); - - // Remove from the containers. - if (celement instanceof IParent) { - CElementInfo info = (CElementInfo)peekAtInfo(celement); - if (info != null) { - ICElement[] children = info.getChildren(); - for (int i = 0; i < children.length; i++) { - releaseCElement(children[i]); - } - } - - // Make sure any object specifics not part of the children be destroy - // For example the CProject needs to destroy the BinaryContainer and ArchiveContainer - if (celement instanceof CElement) { - try { - ((CElement)celement).closing(info); - } catch (CModelException e) { - // - } - } - - // If an entire folder was deleted we need to update the - // BinaryContainer/ArchiveContainer also. - if (celement.getElementType() == ICElement.C_CCONTAINER) { - ICProject cproject = celement.getCProject(); - CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject); - ArrayList list = new ArrayList(5); - if (pinfo != null && pinfo.vBin != null) { - if (peekAtInfo(pinfo.vBin) != null) { - try { - ICElement[] bins = pinfo.vBin.getChildren(); - for (int i = 0; i < bins.length; i++) { - if (celement.getPath().isPrefixOf(bins[i].getPath())) { - //pinfo.vBin.removeChild(bins[i]); - list.add(bins[i]); - } - } - } catch (CModelException e) { - // .. - } - } - } - if (pinfo != null && pinfo.vLib != null) { - if (peekAtInfo(pinfo.vLib) != null) { - try { - ICElement[] ars = pinfo.vLib.getChildren(); - for (int i = 0; i < ars.length; i++) { - if (celement.getPath().isPrefixOf(ars[i].getPath())) { - //pinfo.vLib.removeChild(ars[i]); - list.add(ars[i]); - } - } - } catch (CModelException e) { - // .. - } - } - } - // release any binary/archive that was in the path - for (int i = 0; i < list.size(); i++) { - ICElement b = (ICElement)list.get(i); - releaseCElement(b); - } - } - } - - // Remove the child from the parent list. - //Parent parent = (Parent)celement.getParent(); - //if (parent != null && peekAtInfo(parent) != null) { - // parent.removeChild(celement); - //} - - removeInfo(celement); - } - - public BinaryParserConfig[] getBinaryParser(IProject project) { - try { - BinaryParserConfig[] parsers = (BinaryParserConfig[])binaryParsersMap.get(project); - if (parsers == null) { - parsers = CCorePlugin.getDefault().getBinaryParserConfigs(project); - } - if (parsers != null) { - binaryParsersMap.put(project, parsers); - return parsers; - } - } catch (CoreException e) { - } - IBinaryParser nullParser = new NullBinaryParser(); - BinaryParserConfig config = new BinaryParserConfig(nullParser, ""); //$NON-NLS-1$ - BinaryParserConfig[] configs = new BinaryParserConfig[] {config}; - return configs; - } - - public IBinaryFile createBinaryFile(IFile file) { - BinaryParserConfig[] parsers = getBinaryParser(file.getProject()); - int hints = 0; - for (int i = 0; i < parsers.length; i++) { - IBinaryParser parser = parsers[i].getBinaryParser(); - if (parser.getHintBufferSize() > hints) { - hints = parser.getHintBufferSize(); - } - } - byte[] bytes = new byte[hints]; - if (hints > 0) { - try { - InputStream is = file.getContents(); - int count = is.read(bytes); - is.close(); - if (count > 0 && count < bytes.length) { - byte[] array = new byte[count]; - System.arraycopy(bytes, 0, array, 0, count); - bytes = array; - } - } catch (CoreException e) { - return null; - } catch (IOException e) { - return null; - } - } - - IPath location = file.getLocation(); - - for (int i = 0; i < parsers.length; i++) { - try { - IBinaryFile bin = parsers[i].getBinaryParser().getBinary(bytes, location); - if (bin != null) { - return bin; - } - } catch (IOException e) { - // - } - } - return null; - } - - /** - * TODO: this is a temporary hack until, the CDescriptor manager is - * in place and could fire deltas of Parser change. - */ - public void resetBinaryParser(IProject project) { - if (project != null) { - ICProject cproject = create(project); - if (cproject != null) { - // Let the function remove the children - // but it has the side of effect of removing the CProject also - // so we have to recall create again. - try { - cproject.close(); - } catch (CModelException e) { - e.printStackTrace(); - } - binaryParsersMap.remove(project); - - // Fired and ICElementDelta.PARSER_CHANGED - CElementDelta delta = new CElementDelta(getCModel()); - delta.binaryParserChanged(cproject); - registerCModelDelta(delta); - fire(ElementChangedEvent.POST_CHANGE); - } - } - } - - public BinaryRunner getBinaryRunner(ICProject project, boolean start) { - BinaryRunner runner = null; - synchronized(binaryRunners) { - runner = (BinaryRunner)binaryRunners.get(project.getProject()); - if (runner == null) { - runner = new BinaryRunner(project.getProject()); - binaryRunners.put(project.getProject(), runner); - if (start) { - runner.start(); - } - } - } - return runner; - } - - public void removeBinaryRunner(ICProject cproject) { - removeBinaryRunner(cproject.getProject()); - } - - public void removeBinaryRunner(IProject project) { - BinaryRunner runner = (BinaryRunner) binaryRunners.remove(project); - if (runner != null) { - runner.stop(); - } - } - - public SourceMapper getSourceMapper(ICProject cProject) { - SourceMapper mapper = null; - synchronized(sourceMappers) { - mapper = (SourceMapper) sourceMappers.get(cProject); - if (mapper == null) { - mapper = new SourceMapper(cProject); - sourceMappers.put(cProject, mapper); - } - } - return mapper; - } - /** - * addElementChangedListener method comment. - */ - public void addElementChangedListener(IElementChangedListener listener) { - synchronized(fElementChangedListeners) { - if (!fElementChangedListeners.contains(listener)) { - fElementChangedListeners.add(listener); - } - } - } - - /** - * removeElementChangedListener method comment. - */ - public void removeElementChangedListener(IElementChangedListener listener) { - synchronized(fElementChangedListeners) { - int i = fElementChangedListeners.indexOf(listener); - if (i != -1) { - fElementChangedListeners.remove(i); - } - } - } - - /** - * Registers the given delta with this manager. This API is to be - * used to registerd deltas that are created explicitly by the C - * Model. Deltas created as translations of <code>IResourceDeltas</code> - * are to be registered with <code>#registerResourceDelta</code>. - */ - public void registerCModelDelta(ICElementDelta delta) { - fCModelDeltas.add(delta); - } - - /** - * Notifies this C Model Manager that some resource changes have happened - * on the platform, and that the C Model should update any required - * internal structures such that its elements remain consistent. - * Translates <code>IResourceDeltas</code> into <code>ICElementDeltas</code>. - * - * @see IResourceDelta - * @see IResource - */ - public void resourceChanged(IResourceChangeEvent event) { - - if (event.getSource() instanceof IWorkspace) { - IResourceDelta delta = event.getDelta(); - IResource resource = event.getResource(); - switch(event.getType()){ - case IResourceChangeEvent.PRE_DELETE : - try{ - if (resource.getType() == IResource.PROJECT && - ( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) || - ((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){ - this.deleting((IProject) resource);} - }catch (CoreException e){ - } - break; - - case IResourceChangeEvent.POST_CHANGE : - try { - if (delta != null) { - ICElementDelta[] translatedDeltas = fDeltaProcessor.processResourceDelta(delta); - if (translatedDeltas.length > 0) { - for (int i= 0; i < translatedDeltas.length; i++) { - registerCModelDelta(translatedDeltas[i]); - } - } - fire(ElementChangedEvent.POST_CHANGE); - } - } catch (Exception e) { - e.printStackTrace(); - } - break; - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent) - */ - public void descriptorChanged(CDescriptorEvent event) { - int flags = event.getFlags(); - if ((flags & CDescriptorEvent.EXTENSION_CHANGED) != 0) { - ICDescriptor cdesc = event.getDescriptor(); - if (cdesc != null) { - IProject project = cdesc.getProject(); - try { - String[] newIds = CCorePlugin.getDefault().getBinaryParserIds(project); - BinaryParserConfig[] currentConfigs = getBinaryParser(project); - // anything added/removed - if (newIds.length != currentConfigs.length) { - resetBinaryParser(project); - } else { // may reorder - for (int i = 0; i < newIds.length; i++) { - String id = newIds[i]; - if (!id.equals(currentConfigs[i].getId())) { - resetBinaryParser(project); - break; - } - } - } - } catch (CoreException e) { - // - } - } - } - } - - public void fire(int eventType) { - fire(null, eventType); - } - - /** - * Fire C Model deltas, flushing them after the fact. - * If the firing mode has been turned off, this has no effect. - */ - public void fire(ICElementDelta customDeltas, int eventType) { - if (fFire) { - ICElementDelta deltaToNotify; - if (customDeltas == null) { - deltaToNotify = mergeDeltas(this.fCModelDeltas); - } else { - deltaToNotify = customDeltas; - } - - IElementChangedListener[] listeners; - int listenerCount; - int [] listenerMask; - // Notification - synchronized(fElementChangedListeners) { - listeners = new IElementChangedListener[fElementChangedListeners.size()]; - fElementChangedListeners.toArray(listeners); - listenerCount = listeners.length; - listenerMask = null; - } - - switch (eventType) { - case DEFAULT_CHANGE_EVENT: - firePreAutoBuildDelta(deltaToNotify, listeners, listenerMask, listenerCount); - firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount); - fireReconcileDelta(listeners, listenerMask, listenerCount); - break; - case ElementChangedEvent.PRE_AUTO_BUILD: - firePreAutoBuildDelta(deltaToNotify, listeners, listenerMask, listenerCount); - break; - case ElementChangedEvent.POST_CHANGE: - firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount); - fireReconcileDelta(listeners, listenerMask, listenerCount); - break; - case ElementChangedEvent.POST_RECONCILE: - fireReconcileDelta(listeners, listenerMask, listenerCount); - break; - } - } - } - - private void firePreAutoBuildDelta(ICElementDelta deltaToNotify, - IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { - - if (VERBOSE) { - System.out.println("FIRING PRE_AUTO_BUILD Delta ["+Thread.currentThread()+"]:"); //$NON-NLS-1$//$NON-NLS-2$ - System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ - } - if (deltaToNotify != null) { - notifyListeners(deltaToNotify, ElementChangedEvent.PRE_AUTO_BUILD, listeners, listenerMask, listenerCount); - } - } - - private void firePostChangeDelta(ICElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { - - // post change deltas - if (VERBOSE){ - System.out.println("FIRING POST_CHANGE Delta ["+Thread.currentThread()+"]:"); //$NON-NLS-1$//$NON-NLS-2$ - System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ - } - if (deltaToNotify != null) { - // flush now so as to keep listener reactions to post their own deltas for subsequent iteration - this.flush(); - notifyListeners(deltaToNotify, ElementChangedEvent.POST_CHANGE, listeners, listenerMask, listenerCount); - } - } - - private void fireReconcileDelta(IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { - ICElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas.values()); - if (VERBOSE){ - System.out.println("FIRING POST_RECONCILE Delta ["+Thread.currentThread()+"]:"); //$NON-NLS-1$//$NON-NLS-2$ - System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ - } - if (deltaToNotify != null) { - // flush now so as to keep listener reactions to post their own deltas for subsequent iteration - this.reconcileDeltas = new HashMap(); - notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount); - } - } - - public void notifyListeners(ICElementDelta deltaToNotify, int eventType, - IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { - - final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType); - for (int i= 0; i < listenerCount; i++) { - if (listenerMask == null || (listenerMask[i] & eventType) != 0) { - final IElementChangedListener listener = listeners[i]; - long start = -1; - if (VERBOSE) { - System.out.print("Listener #" + (i+1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$ - start = System.currentTimeMillis(); - } - // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - //CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$ - CCorePlugin.log(exception); - } - public void run() throws Exception { - listener.elementChanged(extraEvent); - } - }); - if (VERBOSE) { - System.out.println(" -> " + (System.currentTimeMillis()-start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } - } - - /** - * Flushes all deltas without firing them. - */ - protected void flush() { - fCModelDeltas.clear(); - } - - private ICElementDelta mergeDeltas(Collection deltas) { - - synchronized(deltas) { - if (deltas.size() == 0) - return null; - if (deltas.size() == 1) - return (ICElementDelta)deltas.iterator().next(); - if (deltas.size() <= 1) - return null; - - Iterator iterator = deltas.iterator(); - ICElement cRoot = getCModel(); - CElementDelta rootDelta = new CElementDelta(cRoot); - boolean insertedTree = false; - while (iterator.hasNext()) { - CElementDelta delta = (CElementDelta)iterator.next(); - ICElement element = delta.getElement(); - if (cRoot.equals(element)) { - ICElementDelta[] children = delta.getAffectedChildren(); - for (int j = 0; j < children.length; j++) { - CElementDelta projectDelta = (CElementDelta) children[j]; - rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta); - insertedTree = true; - } - } else { - rootDelta.insertDeltaTree(element, delta); - insertedTree = true; - } - } - if (insertedTree) { - return rootDelta; - } else { - return null; - } - } - } - - /** - * Runs a C Model Operation - */ - public void runOperation(CModelOperation operation, IProgressMonitor monitor) throws CModelException { - boolean hadAwaitingDeltas = !fCModelDeltas.isEmpty(); - try { - if (operation.isReadOnly()) { - operation.run(monitor); - } else { - // use IWorkspace.run(...) to ensure that a build will be done in autobuild mode - getCModel().getUnderlyingResource().getWorkspace() - .run(operation, operation.getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor); - } - } catch (CoreException ce) { - if (ce instanceof CModelException) { - throw (CModelException)ce; - } else { - if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) { - Throwable e= ce.getStatus().getException(); - if (e instanceof CModelException) { - throw (CModelException) e; - } - } - throw new CModelException(ce); - } - } finally { -// fire only if there were no awaiting deltas (if there were, they would come from a resource modifying operation) -// and the operation has not modified any resource - if (!hadAwaitingDeltas && !operation.hasModifiedResource()) { - fire(ElementChangedEvent.POST_CHANGE); - } // else deltas are fired while processing the resource delta - } - } - - /** - * Returns the set of elements which are out of synch with their buffers. - */ - protected Map getElementsOutOfSynchWithBuffers() { - return this.elementsOutOfSynchWithBuffers; - } - - /** - * Returns the info for the element. - */ - public synchronized Object getInfo(ICElement element) { - HashMap tempCache = (HashMap)this.temporaryCache.get(); - if (tempCache != null) { - Object result = tempCache.get(element); - if (result != null) { - return result; - } - } - return this.cache.getInfo(element); - } - - /** - * Returns the info for this element without - * disturbing the cache ordering. - */ - protected synchronized Object peekAtInfo(ICElement element) { - HashMap tempCache = (HashMap)this.temporaryCache.get(); - if (tempCache != null) { - Object result = tempCache.get(element); - if (result != null) { - return result; - } - } - return this.cache.peekAtInfo(element); - } - - /* - * Puts the infos in the given map (keys are ICElements and values are CElementInfos) - * in the C model cache in an atomic way. - * First checks that the info for the opened element (or one of its ancestors) has not been - * added to the cache. If it is the case, another thread has opened the element (or one of - * its ancestors). So returns without updating the cache. - */ - protected synchronized void putInfos(ICElement openedElement, Map newElements) { - // remove children - Object existingInfo = this.cache.peekAtInfo(openedElement); - if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) { - ICElement[] children = ((CElementInfo)existingInfo).getChildren(); - for (int i = 0, size = children.length; i < size; ++i) { - CElement child = (CElement) children[i]; - try { - child.close(); - } catch (CModelException e) { - // ignore - } - } - } - - Iterator iterator = newElements.keySet().iterator(); - while (iterator.hasNext()) { - ICElement element = (ICElement)iterator.next(); - Object info = newElements.get(element); - this.cache.putInfo(element, info); - } - } - - /** - * Removes all cached info from the C Model, including all children, - * but does not close this element. - */ - protected synchronized void removeChildrenInfo(ICElement openedElement) { - // remove children - Object existingInfo = this.cache.peekAtInfo(openedElement); - if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) { - ICElement[] children = ((CElementInfo)existingInfo).getChildren(); - for (int i = 0, size = children.length; i < size; ++i) { - CElement child = (CElement) children[i]; - try { - child.close(); - } catch (CModelException e) { - // ignore - } - } - } - } - - /** - * Removes the info of this model element. - */ - protected synchronized void removeInfo(ICElement element) { - this.cache.removeInfo(element); - } - - /* - * Returns the temporary cache for newly opened elements for the current thread. - * Creates it if not already created. - */ - public HashMap getTemporaryCache() { - HashMap result = (HashMap)this.temporaryCache.get(); - if (result == null) { - result = new HashMap(); - this.temporaryCache.set(result); - } - return result; - } - - /* - * Returns whether there is a temporary cache for the current thread. - */ - public boolean hasTemporaryCache() { - return this.temporaryCache.get() != null; - } - - /* - * Resets the temporary cache for newly created elements to null. - */ - public void resetTemporaryCache() { - this.temporaryCache.set(null); - } - - /** - * - */ - public void startup() { - // Do any initialization. - } - - /** - * - */ - public void shutdown() { - if (this.fDeltaProcessor.indexManager != null){ // no more indexing - this.fDeltaProcessor.indexManager.shutdown(); - } - - // Do any shutdown of services. - ResourcesPlugin.getWorkspace().removeResourceChangeListener(factory); - - BinaryRunner[] runners = (BinaryRunner[])binaryRunners.values().toArray(new BinaryRunner[0]); - for (int i = 0; i < runners.length; i++) { - runners[i].stop(); - } - } - - public IndexManager getIndexManager() { - return this.fDeltaProcessor.indexManager; - } - - public void deleting(IProject project){ - // discard all indexing jobs for this project - this.getIndexManager().discardJobs(project.getName()); - removeBinaryRunner(project); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java deleted file mode 100644 index b855bca5edb..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java +++ /dev/null @@ -1,599 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -import java.io.InputStream; -import java.util.HashMap; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ElementChangedEvent; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICModel; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; - -/** - * Defines behavior common to all C Model operations - */ -public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMonitor { - /** - * The elements this operation operates on, - * or <code>null</code> if this operation - * does not operate on specific elements. - */ - protected ICElement[] fElementsToProcess; - - /** - * The parent elements this operation operates with - * or <code>null</code> if this operation - * does not operate with specific parent elements. - */ - protected ICElement[] fParentElements; - - /** - * An empty collection of <code>ICElement</code>s - the common - * empty result if no elements are created, or if this - * operation is not actually executed. - */ - protected static ICElement[] fgEmptyResult= new ICElement[] {}; - - /** - * Collection of <code>ICElementDelta</code>s created by this operation. - * This collection starts out <code>null</code> and becomes an - * array of <code>ICElementDelta</code>s if the operation creates any - * deltas. This collection is registered with the C Model notification - * manager if the operation completes successfully. - */ - protected ICElementDelta[] fDeltas= null; - - /** - * The elements created by this operation - empty - * until the operation actually creates elements. - */ - protected ICElement[] fResultElements= fgEmptyResult; - - /** - * The progress monitor passed into this operation - */ - protected IProgressMonitor fMonitor= null; - - /** - * A flag indicating whether this operation is nested. - */ - protected boolean fNested = false; - - /** - * Conflict resolution policy - by default do not force (fail on a conflict). - */ - protected boolean fForce= false; - - /* - * Whether the operation has modified resources, and thus whether resource - * delta notifcation will happen. - */ - protected boolean hasModifiedResource = false; - - protected CModelOperation() { - } - /** - * A common constructor for all C Model operations. - */ - protected CModelOperation(ICElement[] elements) { - fElementsToProcess = elements; - } - - /** - * Common constructor for all C Model operations. - */ - protected CModelOperation(ICElement[] elementsToProcess, ICElement[] parentElements) { - fElementsToProcess = elementsToProcess; - fParentElements= parentElements; - } - - /** - * A common constructor for all C Model operations. - */ - protected CModelOperation(ICElement[] elementsToProcess, ICElement[] parentElements, boolean force) { - fElementsToProcess = elementsToProcess; - fParentElements= parentElements; - fForce= force; - } - - /** - * A common constructor for all C Model operations. - */ - protected CModelOperation(ICElement[] elements, boolean force) { - fElementsToProcess = elements; - fForce= force; - } - - /** - * Common constructor for all C Model operations. - */ - protected CModelOperation(ICElement element) { - fElementsToProcess = new ICElement[]{element}; - } - - /** - * A common constructor for all C Model operations. - */ - protected CModelOperation(ICElement element, boolean force) { - fElementsToProcess = new ICElement[]{element}; - fForce= force; - } - - /** - * Adds the given delta to the collection of deltas - * that this operation has created. These deltas are - * automatically registered with the C Model Manager - * when the operation completes. - */ - protected void addDelta(ICElementDelta delta) { - if (fDeltas == null) { - fDeltas= new ICElementDelta[] {delta}; - } else { - ICElementDelta[] copy= new ICElementDelta[fDeltas.length + 1]; - System.arraycopy(fDeltas, 0, copy, 0, fDeltas.length); - copy[fDeltas.length]= delta; - fDeltas= copy; - } - } - - /* - * Registers the given reconcile delta with the Java Model Manager. - */ - protected void addReconcileDelta(IWorkingCopy workingCopy, ICElementDelta delta) { - HashMap reconcileDeltas = CModelManager.getDefault().reconcileDeltas; - CElementDelta previousDelta = (CElementDelta)reconcileDeltas.get(workingCopy); - if (previousDelta != null) { - ICElementDelta[] children = delta.getAffectedChildren(); - for (int i = 0, length = children.length; i < length; i++) { - CElementDelta child = (CElementDelta)children[i]; - previousDelta.insertDeltaTree(child.getElement(), child); - } - } else { - reconcileDeltas.put(workingCopy, delta); - } - } - - /* - * Deregister the reconcile delta for the given working copy - */ - protected void removeReconcileDelta(IWorkingCopy workingCopy) { - CModelManager.getDefault().reconcileDeltas.remove(workingCopy); - } - - /** - * @see IProgressMonitor - */ - public void beginTask(String name, int totalWork) { - if (fMonitor != null) { - fMonitor.beginTask(name, totalWork); - } - } - - /** - * Checks with the progress monitor to see whether this operation - * should be canceled. An operation should regularly call this method - * during its operation so that the user can cancel it. - * - * @exception OperationCanceledException if cancelling the operation has been requested - * @see IProgressMonitor#isCanceled - */ - protected void checkCanceled() { - if (isCanceled()) { - throw new OperationCanceledException("operation.cancelled"); //$NON-NLS-1$ - } - } - - /** - * Common code used to verify the elements this operation is processing. - * @see CModelOperation#verify() - */ - protected ICModelStatus commonVerify() { - if (fElementsToProcess == null || fElementsToProcess.length == 0) { - return new CModelStatus(ICModelStatusConstants.NO_ELEMENTS_TO_PROCESS); - } - for (int i = 0; i < fElementsToProcess.length; i++) { - if (fElementsToProcess[i] == null) { - return new CModelStatus(ICModelStatusConstants.NO_ELEMENTS_TO_PROCESS); - } - } - return CModelStatus.VERIFIED_OK; - } - - /** - * Convenience method to copy resources - */ - protected void copyResources(IResource[] resources, IPath destinationPath) throws CModelException { - IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length); - IWorkspace workspace = resources[0].getWorkspace(); - try { - workspace.copy(resources, destinationPath, false, subProgressMonitor); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * Convenience method to create a file - */ - protected void createFile(IContainer folder, String name, InputStream contents, boolean force) throws CModelException { - IFile file= folder.getFile(new Path(name)); - try { - file.create(contents, force, getSubProgressMonitor(1)); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * Convenience method to create a folder - */ - protected void createFolder(IContainer parentFolder, String name, boolean force) throws CModelException { - IFolder folder= parentFolder.getFolder(new Path(name)); - try { - // we should use true to create the file locally. Only VCM should use tru/false - folder.create(force, true, getSubProgressMonitor(1)); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * Convenience method to delete a resource - */ - protected void deleteResource(IResource resource, boolean force) throws CModelException { - try { - resource.delete(force, getSubProgressMonitor(1)); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * Convenience method to delete resources - */ - protected void deleteResources(IResource[] resources, boolean force) throws CModelException { - if (resources == null || resources.length == 0) return; - IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length); - IWorkspace workspace = resources[0].getWorkspace(); - try { - workspace.delete(resources, force, subProgressMonitor); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * @see IProgressMonitor - */ - public void done() { - if (fMonitor != null) { - fMonitor.done(); - } - } - - /** - * Verifies the operation can proceed and executes the operation. - * Subclasses should override <code>#verify</code> and - * <code>executeOperation</code> to implement the specific operation behavior. - * - * @exception CModelException The operation has failed. - */ - protected void execute() throws CModelException { - ICModelStatus status= verify(); - if (status.isOK()) { - executeOperation(); - } else { - throw new CModelException(status); - } - } - - /** - * Convenience method to run an operation within this operation - */ - public void executeNestedOperation(CModelOperation operation, int subWorkAmount) throws CModelException { - IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount); - // fix for 1FW7IKC, part (1) - try { - operation.setNested(true); - operation.run(subProgressMonitor); - if (operation.hasModifiedResource()) { - this.hasModifiedResource = true; - } - //accumulate the nested operation deltas - if (operation.fDeltas != null) { - for (int i = 0; i < operation.fDeltas.length; i++) { - addDelta(operation.fDeltas[i]); - } - } - } catch (CoreException ce) { - if (ce instanceof CModelException) { - throw (CModelException)ce; - } else { - // translate the core exception to a c model exception - if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) { - Throwable e = ce.getStatus().getException(); - if (e instanceof CModelException) { - throw (CModelException) e; - } - } - throw new CModelException(ce); - } - } - } - - /** - * Performs the operation specific behavior. Subclasses must override. - */ - protected abstract void executeOperation() throws CModelException; - - /** - * Returns the elements to which this operation applies, - * or <code>null</code> if not applicable. - */ - protected ICElement[] getElementsToProcess() { - return fElementsToProcess; - } - - /** - * Returns the element to which this operation applies, - * or <code>null</code> if not applicable. - */ - protected ICElement getElementToProcess() { - if (fElementsToProcess == null || fElementsToProcess.length == 0) { - return null; - } - return fElementsToProcess[0]; - } - - /** - * Returns the C Model this operation is operating in. - */ - public ICModel getCModel() { - if (fElementsToProcess == null || fElementsToProcess.length == 0) { - return getParentElement().getCModel(); - } else { - return fElementsToProcess[0].getCModel(); - } - } - - /** - * Returns the parent element to which this operation applies, - * or <code>null</code> if not applicable. - */ - protected ICElement getParentElement() { - if (fParentElements == null || fParentElements.length == 0) { - return null; - } - return fParentElements[0]; - } - - /** - * Returns the parent elements to which this operation applies, - * or <code>null</code> if not applicable. - */ - protected ICElement[] getParentElements() { - return fParentElements; - } - - /** - * Returns the elements created by this operation. - */ - public ICElement[] getResultElements() { - return fResultElements; - } - - /** - * Returns the scheduling rule for this operation (i.e. the resource that needs to be locked - * while this operation is running. - * Subclasses can override. - */ - public ISchedulingRule getSchedulingRule() { - return ResourcesPlugin.getWorkspace().getRoot(); - } - - /** - * Creates and returns a subprogress monitor if appropriate. - */ - protected IProgressMonitor getSubProgressMonitor(int workAmount) { - IProgressMonitor sub = null; - if (fMonitor != null) { - sub = new SubProgressMonitor(fMonitor, workAmount, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); - } - return sub; - } - - /** - * Returns the <code>IWorkspace</code> this operation is working in, or - * <code>null</code> if this operation has no elements to process. - */ - protected IWorkspace getWorkspace() { - if (fElementsToProcess != null && fElementsToProcess.length > 0) { - ICProject project = fElementsToProcess[0].getCProject(); - if (project != null) { - return project.getCModel().getWorkspace(); - } - } - return null; - } - - /** - * Returns whether this operation has performed any resource modifications. - * Returns false if this operation has not been executed yet. - */ - public boolean hasModifiedResource() { - return !this.isReadOnly() && this.hasModifiedResource; - } - - public void internalWorked(double work) { - if (fMonitor != null) { - fMonitor.internalWorked(work); - } - } - - /** - * @see IProgressMonitor - */ - public boolean isCanceled() { - if (fMonitor != null) { - return fMonitor.isCanceled(); - } - return false; - } - - /** - * Returns <code>true</code> if this operation performs no resource modifications, - * otherwise <code>false</code>. Subclasses must override. - */ - public boolean isReadOnly() { - return false; - } - - /** - * Convenience method to move resources - */ - protected void moveResources(IResource[] resources, IPath destinationPath) throws CModelException { - IProgressMonitor subProgressMonitor = null; - if (fMonitor != null) { - subProgressMonitor = new SubProgressMonitor(fMonitor, resources.length, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK); - } - IWorkspace workspace = resources[0].getWorkspace(); - try { - workspace.move(resources, destinationPath, false, subProgressMonitor); - this.hasModifiedResource = true; - } catch (CoreException e) { - throw new CModelException(e); - } - } - - /** - * Creates and returns a new <code>ICElementDelta</code> - * on the C Model. - */ - public CElementDelta newCElementDelta() { - return new CElementDelta(getCModel()); - } - - /** - * Registers any deltas this operation created, with the - * C Model manager. - */ - protected void registerDeltas() { - if (fDeltas != null && !fNested) { - // hook to ensure working copies remain consistent - //makeWorkingCopiesConsistent(fDeltas); - CModelManager manager= CModelManager.getDefault(); - for (int i= 0; i < fDeltas.length; i++) { - manager.registerCModelDelta(fDeltas[i]); - } - } - } - - /** - * Main entry point for C Model operations. Executes this operation - * and registers any deltas created. - * - * @see IWorkspaceRunnable - * @exception CoreException if the operation fails - */ - public void run(IProgressMonitor monitor) throws CoreException { - CModelManager manager= CModelManager.getDefault(); - int previousDeltaCount = manager.fCModelDeltas.size(); - try { - fMonitor = monitor; - execute(); - } finally { - registerDeltas(); - // Fire if we change somethings - if ((manager.fCModelDeltas.size() > previousDeltaCount || !manager.reconcileDeltas.isEmpty()) - && !this.hasModifiedResource()) { - manager.fire(ElementChangedEvent.POST_CHANGE); - } - } - } - - /** - * @see IProgressMonitor - */ - public void setCanceled(boolean b) { - if (fMonitor != null) { - fMonitor.setCanceled(b); - } - } - - /** - * Sets whether this operation is nested or not. - * @see CreateElementInCUOperation#checkCanceled - */ - protected void setNested(boolean nested) { - fNested = nested; - } - - /** - * @see IProgressMonitor - */ - public void setTaskName(String name) { - if (fMonitor != null) { - fMonitor.setTaskName(name); - } - } - - /** - * @see IProgressMonitor - */ - public void subTask(String name) { - if (fMonitor != null) { - fMonitor.subTask(name); - } - } - /** - * Returns a status indicating if there is any known reason - * this operation will fail. Operations are verified before they - * are run. - * - * Subclasses must override if they have any conditions to verify - * before this operation executes. - * - * @see ICModelStatus - */ - protected ICModelStatus verify() { - return commonVerify(); - } - - /** - * @see IProgressMonitor - */ - public void worked(int work) { - if (fMonitor != null) { - fMonitor.worked(work); - checkCanceled(); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java deleted file mode 100644 index 9b225342016..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java +++ /dev/null @@ -1,416 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; - -/** - * @see ICModelStatus - */ - -public class CModelStatus extends Status implements ICModelStatus, ICModelStatusConstants, IResourceStatus { - - /** - * The elements related to the failure, or <code>null</code> - * if no elements are involved. - */ - protected ICElement[] fElements; - protected final static ICElement[] EmptyElement = new ICElement[] {}; - /** - * The path related to the failure, or <code>null</code> - * if no path is involved. - */ - protected IPath fPath; - /** - * The <code>String</code> related to the failure, or <code>null</code> - * if no <code>String</code> is involved. - */ - protected String fString; - protected final static String EMPTY_STRING = ""; //$NON-NLS-1$ - - /** - * Empty children - */ - protected final static IStatus[] fgEmptyChildren = new IStatus[] {}; - protected IStatus[] fChildren= fgEmptyChildren; - protected final static String DEFAULT_STRING= "CModelStatus"; //$NON-NLS-1$; - - /** - * Singleton OK object - */ - public static final ICModelStatus VERIFIED_OK = new CModelStatus(OK, OK, org.eclipse.cdt.internal.core.Util.bind("status.OK")); //$NON-NLS-1$ - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus() { - // no code for an multi-status - this(0); - } - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus(int code) { - this(code, CElement.NO_ELEMENTS); - } - - /** - * Constructs an C model status with the given corresponding - * elements. - */ - public CModelStatus(int code, ICElement[] elements) { - super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); - fElements = elements; - fPath= Path.EMPTY; - } - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus(int code, String string) { - this(ERROR, code, string); - } - - public CModelStatus(int severity, int code, String string) { - super(severity, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); - fElements = CElement.NO_ELEMENTS; - fPath= Path.EMPTY; - fString = string; - } - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus(int code, IPath path) { - super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, null); - fElements = CElement.NO_ELEMENTS; - fPath= path; - } - - /** - * Constructs an C model status with the given corresponding - * element. - */ - public CModelStatus(int code, ICElement element) { - this(code, new ICElement[]{element}); - } - - /** - * Constructs an C model status with the given corresponding - * element and string - */ - public CModelStatus(int code, ICElement element, String string) { - this(code, new ICElement[]{element}); - fString= string; - } - - public CModelStatus(int code, ICElement element, IPath path) { - this(code, new ICElement[]{element}); - fPath = path; - } - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus(CoreException coreException) { - this(CORE_EXCEPTION, coreException); - } - - /** - * Constructs an C model status with no corresponding elements. - */ - public CModelStatus(int code, Throwable throwable) { - super(ERROR, CCorePlugin.PLUGIN_ID, code, DEFAULT_STRING, throwable); - fElements = CElement.NO_ELEMENTS; - fPath = Path.EMPTY; - } - - protected int getBits() { - int severity = 1 << (getCode() % 100 / 33); - int category = 1 << ((getCode() / 100) + 3); - return severity | category; - } - - /** - * @see IStatus - */ - public IStatus[] getChildren() { - return fChildren; - } - - /** - * @see ICModelStatus - */ - public ICElement[] getElements() { - return fElements; - } - - /** - * Returns the message that is relevant to the code of this status. - */ - public String getMessage() { - Throwable exception = getException(); - if (exception == null) { - switch (getCode()) { - case CORE_EXCEPTION : - return CoreModelMessages.getFormattedString("status.coreException"); //$NON-NLS-1$ - - - case DEVICE_PATH: - return CoreModelMessages.getFormattedString("status.cannotUseDeviceOnPath", getPath().toString()); //$NON-NLS-1$ - - case PARSER_EXCEPTION: - return CoreModelMessages.getFormattedString("status.ParserError"); //$NON-NLS-1$ - - case ELEMENT_DOES_NOT_EXIST: - return CoreModelMessages.getFormattedString("element.doesNotExist", getFirstElementName()); //$NON-NLS-1$ - - case EVALUATION_ERROR: - return CoreModelMessages.getFormattedString("status.evaluationError", getString()); //$NON-NLS-1$ - - case INDEX_OUT_OF_BOUNDS: - return CoreModelMessages.getFormattedString("status.indexOutOfBounds"); //$NON-NLS-1$ - - case INVALID_CONTENTS: - return CoreModelMessages.getFormattedString("status.invalidContents"); //$NON-NLS-1$ - - case INVALID_DESTINATION: - return CoreModelMessages.getFormattedString("status.invalidDestination", getFirstElementName()); //$NON-NLS-1$ - - case INVALID_ELEMENT_TYPES: - StringBuffer buff= new StringBuffer(CoreModelMessages.getFormattedString("operation.notSupported")); //$NON-NLS-1$ - for (int i = 0; i < fElements.length; i++) { - if (i > 0) { - buff.append(", "); //$NON-NLS-1$ - } - buff.append((fElements[i]).toString()); - } - return buff.toString(); - - case INVALID_NAME: - return CoreModelMessages.getFormattedString("status.invalidName", getString()); //$NON-NLS-1$ - - case INVALID_PATH: - if (fString != null) { - return fString; - } else { - return CoreModelMessages.getFormattedString("status.invalidPath", getPath() == null ? "null" : getPath().toString()); //$NON-NLS-1$ //$NON-NLS-2$ - } - - case INVALID_PROJECT: - return CoreModelMessages.getFormattedString("status.invalidProject", getString()); //$NON-NLS-1$ - - case INVALID_RESOURCE: - return CoreModelMessages.getFormattedString("status.invalidResource", getString()); //$NON-NLS-1$ - - case INVALID_RESOURCE_TYPE: - return CoreModelMessages.getFormattedString("status.invalidResourceType", getString()); //$NON-NLS-1$ - - case INVALID_SIBLING: - if (fString != null) { - return CoreModelMessages.getFormattedString("status.invalidSibling", getString()); //$NON-NLS-1$ - } else { - return CoreModelMessages.getFormattedString("status.invalidSibling", getFirstElementName()); //$NON-NLS-1$ - } - - case IO_EXCEPTION: - return CoreModelMessages.getFormattedString("status.IOException"); //$NON-NLS-1$ - - case NAME_COLLISION: - StringBuffer sb = new StringBuffer(); - if (fElements != null && fElements.length > 0) { - ICElement element = fElements[0]; - sb.append(element.getElementName()).append(' '); - } - if (fString != null) { - return fString; - } else { - return CoreModelMessages.getFormattedString("status.nameCollision", sb.toString()); //$NON-NLS-1$ //$NON-NLS-2$ - } - - case NO_ELEMENTS_TO_PROCESS: - return CoreModelMessages.getFormattedString("operation.needElements"); //$NON-NLS-1$ - - case NULL_NAME: - return CoreModelMessages.getFormattedString("operation.needName"); //$NON-NLS-1$ - - case NULL_PATH: - return CoreModelMessages.getFormattedString("operation.needPath"); //$NON-NLS-1$ - - case NULL_STRING: - return CoreModelMessages.getFormattedString("operation.needString"); //$NON-NLS-1$ - - case PATH_OUTSIDE_PROJECT: - return CoreModelMessages.getFormattedString("operation.pathOutsideProject", new String[]{getString(), getFirstElementName()}); //$NON-NLS-1$ - - case READ_ONLY: - return CoreModelMessages.getFormattedString("status.readOnly", getFirstElementName()); //$NON-NLS-1$ - - case RELATIVE_PATH: - return CoreModelMessages.getFormattedString("operation.needAbsolutePath", getPath().toString()); //$NON-NLS-1$ - - case UPDATE_CONFLICT: - return CoreModelMessages.getFormattedString("status.updateConflict"); //$NON-NLS-1$ - - case NO_LOCAL_CONTENTS : - return CoreModelMessages.getFormattedString("status.noLocalContents", getPath().toString()); //$NON-NLS-1$ - - case INVALID_CONTAINER_ENTRY: - return CoreModelMessages.getFormattedString("pathentry.invalidContainer", new String[] {getString(), getFirstElementName()}); //$NON-NLS-1$ - - case VARIABLE_PATH_UNBOUND: - return CoreModelMessages.getFormattedString("pathentry.unboundVariablePath", - new String[] {getPath().makeRelative().toString(), getFirstElementName()}); //$NON-NLS-1$ - - case PATHENTRY_CYCLE: - return CoreModelMessages.getFormattedString("pathentry.cycle", getFirstElementName()); //$NON-NLS-1$ - - //case DISABLED_CP_EXCLUSION_PATTERNS: - //case DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS: - - } - return getString(); - } else { - String message = exception.getMessage(); - if (message != null) { - return message; - } else { - return exception.toString(); - } - } - } - - /** - * @see IOperationStatus - */ - public IPath getPath() { - if (fPath == null) { - return Path.EMPTY; - } - return fPath; - } - - /** - * @see IStatus - */ - public int getSeverity() { - if (fChildren == fgEmptyChildren) return super.getSeverity(); - int severity = -1; - for (int i = 0, max = fChildren.length; i < max; i++) { - int childrenSeverity = fChildren[i].getSeverity(); - if (childrenSeverity > severity) { - severity = childrenSeverity; - } - } - return severity; - } - - /** - * @see ICModelStatus - */ - public String getString() { - if (fString == null) { - return EMPTY_STRING; - } - return fString; - } - - public String getFirstElementName() { - if (fElements != null && fElements.length > 0) { - return fElements[0].getElementName(); - } - return EMPTY_STRING; - } - - /** - * @see ICModelStatus - */ - public boolean doesNotExist() { - return getCode() == ELEMENT_DOES_NOT_EXIST; - } - - /** - * @see IStatus - */ - public boolean isMultiStatus() { - return fChildren != fgEmptyChildren; - } - - /** - * @see ICModelStatus - */ - public boolean isOK() { - return getCode() == OK; - } - - /** - * @see IStatus#matches - */ - public boolean matches(int mask) { - if (! isMultiStatus()) { - return matches(this, mask); - } else { - for (int i = 0, max = fChildren.length; i < max; i++) { - if (matches((CModelStatus) fChildren[i], mask)) - return true; - } - return false; - } - } - - /** - * Helper for matches(int). - */ - protected boolean matches(CModelStatus status, int mask) { - int severityMask = mask & 0x7; - int categoryMask = mask & ~0x7; - int bits = status.getBits(); - return ((severityMask == 0) || (bits & severityMask) != 0) && ((categoryMask == 0) || (bits & categoryMask) != 0); - } - - /** - * Creates and returns a new <code>ICModelStatus</code> that is a - * a multi-status status. - * - * @see IStatus#.isMultiStatus() - */ - public static ICModelStatus newMultiStatus(ICModelStatus[] children) { - CModelStatus jms = new CModelStatus(); - jms.fChildren = children; - return jms; - } - - /** - * Returns a printable representation of this exception for debugging - * purposes. - */ - public String toString() { - if (this == VERIFIED_OK){ - return "CModelStatus[OK]"; //$NON-NLS-1$ - } - StringBuffer buffer = new StringBuffer(); - buffer.append("C Model Status ["); //$NON-NLS-1$ - buffer.append(getMessage()); - buffer.append("]"); //$NON-NLS-1$ - return buffer.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java deleted file mode 100644 index 47a5a26f196..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java +++ /dev/null @@ -1,662 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.cdt.core.BinaryParserConfig; -import org.eclipse.cdt.core.CCProjectNature; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.CProjectNature; -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.cdt.core.model.IIncludeReference; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.cdt.core.model.IOutputEntry; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.QualifiedName; - -public class CProject extends Openable implements ICProject { - - private static final String CUSTOM_DEFAULT_OPTION_VALUE = "#\r\n\r#custom-non-empty-default-value#\r\n\r#"; //$NON-NLS-1$ - - public CProject(ICElement parent, IProject project) { - super(parent, project, CElement.C_PROJECT); - } - - public IBinaryContainer getBinaryContainer() throws CModelException { - return ((CProjectInfo) getElementInfo()).getBinaryContainer(); - } - - public IArchiveContainer getArchiveContainer() throws CModelException { - return ((CProjectInfo) getElementInfo()).getArchiveContainer(); - } - - public IProject getProject() { - return getUnderlyingResource().getProject(); - } - - public ICElement findElement(IPath path) throws CModelException { - ICElement celem = null; - if (path.isAbsolute()) { - celem = CModelManager.getDefault().create(path); - } else { - IProject project = getProject(); - if (project != null) { - IPath p = project.getFullPath().append(path); - celem = CModelManager.getDefault().create(p); - } - } - if (celem == null) { - CModelStatus status = new CModelStatus(ICModelStatusConstants.INVALID_PATH, path); - throw new CModelException(status); - } - return celem; - } - - public static boolean hasCNature(IProject p) { - try { - return p.hasNature(CProjectNature.C_NATURE_ID); - } catch (CoreException e) { - //throws exception if the project is not open. - } - return false; - } - - public static boolean hasCCNature(IProject p) { - try { - return p.hasNature(CCProjectNature.CC_NATURE_ID); - } catch (CoreException e) { - //throws exception if the project is not open. - } - return false; - } - - private boolean isCProject() { - return hasCNature(getProject()) || hasCCNature(getProject()); - } - - /** - * Returns true if this handle represents the same C project - * as the given handle. Two handles represent the same - * project if they are identical or if they represent a project with - * the same underlying resource and occurrence counts. - * - * @see CElement#equals(Object) - */ - public boolean equals(Object o) { - - if (this == o) - return true; - - if (!(o instanceof CProject)) - return false; - - CProject other = (CProject) o; - return getProject().equals(other.getProject()); - } - - protected CElementInfo createElementInfo() { - return new CProjectInfo(this); - } - - // CHECKPOINT: CProjects will return the hash code of their underlying IProject - public int hashCode() { - return getProject().hashCode(); - } - - public IIncludeReference[] getIncludeReferences() throws CModelException { - CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(this); - IIncludeReference[] incRefs = null; - if (pinfo != null) { - incRefs = pinfo.incReferences; - } - if (incRefs == null) { - IPathEntry[] entries = getResolvedPathEntries(); - ArrayList list = new ArrayList(entries.length); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { - IIncludeEntry entry = (IIncludeEntry) entries[i]; - IIncludeReference inc = new IncludeReference(this, entry); - if (inc != null) { - list.add(inc); - } - } - } - incRefs = (IIncludeReference[]) list.toArray(new IIncludeReference[0]); - if (pinfo != null) { - pinfo.incReferences = incRefs; - } - } - return incRefs; - } - - public ILibraryReference[] getLibraryReferences() throws CModelException { - CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(this); - ILibraryReference[] libRefs = null; - if (pinfo != null) { - libRefs = pinfo.libReferences; - } - - if (libRefs == null) { - BinaryParserConfig[] binConfigs = CModelManager.getDefault().getBinaryParser(getProject()); - IPathEntry[] entries = getResolvedPathEntries(); - ArrayList list = new ArrayList(entries.length); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) { - ILibraryEntry entry = (ILibraryEntry) entries[i]; - ILibraryReference lib = getLibraryReference(this, binConfigs, entry); - if (lib != null) { - list.add(lib); - } - } - } - libRefs = (ILibraryReference[]) list.toArray(new ILibraryReference[0]); - if (pinfo != null) { - pinfo.libReferences = libRefs; - } - } - return libRefs; - } - - private static ILibraryReference getLibraryReference(ICProject cproject, BinaryParserConfig[] binConfigs, ILibraryEntry entry) { - if (binConfigs == null) { - binConfigs = CModelManager.getDefault().getBinaryParser(cproject.getProject()); - } - ILibraryReference lib = null; - if (binConfigs != null) { - for (int i = 0; i < binConfigs.length; i++) { - IBinaryFile bin; - try { - bin = binConfigs[i].getBinaryParser().getBinary(entry.getFullLibraryPath()); - if (bin != null) { - if (bin.getType() == IBinaryFile.ARCHIVE) { - lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); - } else if (bin instanceof IBinaryObject){ - lib = new LibraryReferenceShared(cproject, entry, (IBinaryObject)bin); - } - break; - } - } catch (IOException e1) { - } - } - } - if (lib == null) { - lib = new LibraryReference(cproject, entry); - } - return lib; - } - - /** - * @see ICProject#getRequiredProjectNames() - */ - public String[] getRequiredProjectNames() throws CModelException { - return projectPrerequisites(getResolvedPathEntries()); - } - - public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException { - return PathEntryManager.getDefault().projectPrerequisites(entries); - } - - - /** - * @see org.eclipse.cdt.core.model.ICProject#getOption(String, boolean) - */ - public String getOption(String optionName, boolean inheritCCoreOptions) { - - if (CModelManager.OptionNames.contains(optionName)) { - Preferences preferences = getPreferences(); - - if (preferences == null || preferences.isDefault(optionName)) { - return inheritCCoreOptions ? CCorePlugin.getOption(optionName) : null; - } - - return preferences.getString(optionName).trim(); - } - - return null; - } - - /** - * @see org.eclipse.cdt.core.model.ICProject#getOptions(boolean) - */ - public Map getOptions(boolean inheritCCoreOptions) { - // initialize to the defaults from CCorePlugin options pool - Map options = inheritCCoreOptions ? CCorePlugin.getOptions() : new HashMap(5); - - Preferences preferences = getPreferences(); - if (preferences == null) - return options; - HashSet optionNames = CModelManager.OptionNames; - - // get preferences set to their default - if (inheritCCoreOptions) { - String[] defaultPropertyNames = preferences.defaultPropertyNames(); - for (int i = 0; i < defaultPropertyNames.length; i++) { - String propertyName = defaultPropertyNames[i]; - if (optionNames.contains(propertyName)) { - options.put(propertyName, preferences.getDefaultString(propertyName).trim()); - } - } - } - // get custom preferences not set to their default - String[] propertyNames = preferences.propertyNames(); - for (int i = 0; i < propertyNames.length; i++) { - String propertyName = propertyNames[i]; - if (optionNames.contains(propertyName)) { - options.put(propertyName, preferences.getString(propertyName).trim()); - } - } - return options; - } - - /** - * @see org.eclipse.cdt.core.model.ICProject#setOption(java.lang.String, java.lang.String) - */ - public void setOption(String optionName, String optionValue) { - if (!CModelManager.OptionNames.contains(optionName)) - return; // unrecognized option - - Preferences preferences = getPreferences(); - preferences.setDefault(optionName, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251) - preferences.setValue(optionName, optionValue); - - savePreferences(preferences); - } - - /** - * @see org.eclipse.cdt.core.model.ICProject#setOptions(Map) - */ - public void setOptions(Map newOptions) { - Preferences preferences = new Preferences(); - setPreferences(preferences); // always reset (26255) - - if (newOptions != null) { - Iterator keys = newOptions.keySet().iterator(); - - while (keys.hasNext()) { - String key = (String) keys.next(); - if (!CModelManager.OptionNames.contains(key)) - continue; // unrecognized option - - // no filtering for encoding (custom encoding for project is allowed) - String value = (String) newOptions.get(key); - preferences.setDefault(key, CUSTOM_DEFAULT_OPTION_VALUE); // empty string isn't the default (26251) - preferences.setValue(key, value); - } - } - - // persist options - savePreferences(preferences); - } - - /** - * Returns the project custom preference pool. - * Project preferences may include custom encoding. - */ - private Preferences getPreferences() { - if (!(isCProject())) { - return null; - } - Preferences preferences = new Preferences(); - Iterator iter = CModelManager.OptionNames.iterator(); - - while (iter.hasNext()) { - String qualifiedName = (String) iter.next(); - String dequalifiedName = qualifiedName.substring(CCorePlugin.PLUGIN_ID.length() + 1); - String value = null; - - try { - value = resource.getPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName)); - } catch (CoreException e) { - } - - if (value != null) - preferences.setValue(qualifiedName, value); - } - - return preferences; - } - - /** - * Save project custom preferences to persistent properties - */ - private void savePreferences(Preferences preferences) { - if (preferences == null) - return; - if (!isCProject()) { - return; // ignore - } - Iterator iter = CModelManager.OptionNames.iterator(); - - while (iter.hasNext()) { - String qualifiedName = (String) iter.next(); - String dequalifiedName = qualifiedName.substring(CCorePlugin.PLUGIN_ID.length() + 1); - String value = null; - - try { - value = preferences.getString(qualifiedName); - - if (value != null && !value.equals(preferences.getDefaultString(qualifiedName))) { - resource.setPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName), value); - } else { - resource.setPersistentProperty(new QualifiedName(CCorePlugin.PLUGIN_ID, dequalifiedName), null); - } - } catch (CoreException e) { - } - } - } - - /* - * Set cached preferences, no preferences are saved, only info is updated - */ - private void setPreferences(Preferences preferences) { - if (!isCProject()) { - return; // ignore - } - // Do nothing - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#getResolvedCPathEntries() - */ - public IPathEntry[] getResolvedPathEntries() throws CModelException { - return CoreModel.getResolvedPathEntries(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#getRawCPathEntries() - */ - public IPathEntry[] getRawPathEntries() throws CModelException { - return CoreModel.getRawPathEntries(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#setRawCPathEntries(org.eclipse.cdt.core.model.IPathEntry[], org.eclipse.core.runtime.IProgressMonitor) - */ - public void setRawPathEntries(IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { - CoreModel.setRawPathEntries(this, newEntries, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#getSourceRoot(org.eclipse.cdt.core.model.ISourceEntry) - */ - public ISourceRoot getSourceRoot(ISourceEntry entry) throws CModelException { - IPath p = getPath(); - IPath sp = entry.getPath(); - if (p.isPrefixOf(sp)) { - int count = sp.matchingFirstSegments(p); - sp = sp.removeFirstSegments(count); - IResource res = null; - if (sp.isEmpty()) { - res = getProject(); - } else { - res = getProject().findMember(sp); - } - if (res != null) { - return new SourceRoot(this, res, entry); - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#getSourceRoots() - */ - public ISourceRoot[] getSourceRoots() throws CModelException { - Object[] children; - int length; - - children = getChildren(); - length = children.length; - ISourceRoot[] roots = new ISourceRoot[length]; - System.arraycopy(children, 0, roots, 0, length); - - return roots; - } - - /** - * - * @return - * @throws CModelException - */ - public ISourceRoot[] getAllSourceRoots() throws CModelException { - CProjectInfo pinfo = (CProjectInfo)CModelManager.getDefault().peekAtInfo(this); - ISourceRoot[] roots = null; - if (pinfo != null) { - if (pinfo.sourceRoots != null) { - roots = pinfo.sourceRoots; - } else { - roots = pinfo.sourceRoots = (ISourceRoot[])computeSourceRoots().toArray(new ISourceRoot[computeSourceRoots().size()]); - } - } else { - roots = (ISourceRoot[])computeSourceRoots().toArray(new ISourceRoot[computeSourceRoots().size()]); - } - return roots; - } - - public IOutputEntry[] getOutputEntries() throws CModelException { - CProjectInfo pinfo = (CProjectInfo) CModelManager.getDefault().peekAtInfo(this); - IOutputEntry[] outs = null; - if (pinfo != null) { - if (pinfo.outputEntries != null) { - outs = pinfo.outputEntries; - } else { - IPathEntry[] entries = getResolvedPathEntries(); - outs = pinfo.outputEntries = getOutputEntries(entries); - } - } else { - IPathEntry[] entries = getResolvedPathEntries(); - outs = getOutputEntries(entries); - } - return outs; - } - - /** - * - */ - public IOutputEntry[] getOutputEntries(IPathEntry[] entries) throws CModelException { - ArrayList list = new ArrayList(entries.length); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry .CDT_OUTPUT) { - list.add(entries[i]); - } - } - IOutputEntry[] outputs = new IOutputEntry[list.size()]; - list.toArray(outputs); - return outputs; - } - - /** - * - */ - public boolean isOnOutputEntry(IResource resource) { - IPath path = resource.getFullPath(); - - // ensure that folders are only excluded if all of their children are excluded - if (resource.getType() == IResource.FOLDER || resource.getType() == IResource.PROJECT) { - path = path.append("*"); //$NON-NLS-1$ - } - - try { - IOutputEntry[] entries = getOutputEntries(); - for (int i = 0; i < entries.length; i++) { - boolean on = isOnOutputEntry(entries[i], path); - if (on) { - return on; - } - } - } catch (CModelException e) { - // - } - return false; - } - - private boolean isOnOutputEntry(IOutputEntry entry, IPath path) { - if (entry.getPath().isPrefixOf(path) && !CoreModelUtil.isExcluded(path, entry.fullExclusionPatternChars())) { - return true; - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, - Map newElements, IResource underlyingResource) - throws CModelException { - boolean validInfo = false; - try { - IResource res = getResource(); - if (res != null && res.isAccessible()) { - validInfo = computeSourceRoots(info, res); - } else { - throw newNotPresentException(); - } - } finally { - if (!validInfo) { - CModelManager.getDefault().removeInfo(this); - } - } - return validInfo; - } - - protected List computeSourceRoots() throws CModelException { - IPathEntry[] entries = getResolvedPathEntries(); - ArrayList list = new ArrayList(entries.length); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { - ISourceEntry sourceEntry = (ISourceEntry)entries[i]; - ISourceRoot root = getSourceRoot(sourceEntry); - if (root != null) { - list.add(root); - } - } - } - return list; - } - - protected boolean computeSourceRoots(OpenableInfo info, IResource res) throws CModelException { - info.setChildren(computeSourceRoots()); - if (info instanceof CProjectInfo) { - CProjectInfo pinfo = (CProjectInfo)info; - pinfo.setNonCResources(null); - } - - return true; - } - - /* - * @see ICProject - */ - public boolean isOnSourceRoot(ICElement element) { - try { - ISourceRoot[] roots = getSourceRoots(); - for (int i = 0; i < roots.length; i++) { - if (roots[i].isOnSourceEntry(element)) { - return true; - } - } - } catch (CModelException e) { - // .. - } - return false; - } - - /* - * @see ICProject - */ - public boolean isOnSourceRoot(IResource resource) { - try { - ISourceRoot[] roots = getSourceRoots(); - for (int i = 0; i < roots.length; i++) { - if (roots[i].isOnSourceEntry(resource)) { - return true; - } - } - } catch (CModelException e) { - // - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - if (!isCProject()) { - return false; - } - return super.exists(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICProject#getNonCResources() - */ - public Object[] getNonCResources() throws CModelException { - return ((CProjectInfo) getElementInfo()).getNonCResources(getResource()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#closing(java.lang.Object) - */ - protected void closing(Object info) throws CModelException { - if (info instanceof CProjectInfo) { - CProjectInfo pinfo = (CProjectInfo)info; - if (pinfo.vBin != null) { - pinfo.vBin.close(); - } - if (pinfo.vLib != null) { - pinfo.vLib.close(); - } - pinfo.resetCaches(); - CModelManager.getDefault().removeBinaryRunner(this); - } - super.closing(info); - } - - /* - * Resets this project's caches - */ - public void resetCaches() { - CProjectInfo pinfo = (CProjectInfo) CModelManager.getDefault().peekAtInfo(this); - if (pinfo != null){ - pinfo.resetCaches(); - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java deleted file mode 100644 index c4d985e7d29..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IIncludeReference; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.cdt.core.model.IOutputEntry; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; - -/** - * Info for ICProject. - */ - -class CProjectInfo extends OpenableInfo { - - BinaryContainer vBin; - ArchiveContainer vLib; - ILibraryReference[] libReferences; - IIncludeReference[] incReferences; - ISourceRoot[] sourceRoots; - IOutputEntry[] outputEntries; - - Object[] nonCResources = null; - - /** - */ - public CProjectInfo(CElement element) { - super(element); - vBin = null; - vLib = null; - } - - synchronized public IBinaryContainer getBinaryContainer() { - if (vBin == null) { - vBin = new BinaryContainer((CProject)getElement()); - } - return vBin; - } - - synchronized public IArchiveContainer getArchiveContainer() { - if (vLib == null) { - vLib = new ArchiveContainer((CProject)getElement()); - } - return vLib; - } - - /** - * @return - */ - public Object[] getNonCResources(IResource res) { - if (nonCResources != null) - return nonCResources; - - // determine if src == project - boolean srcIsProject = false; - IPathEntry[] entries = null; - ICProject cproject = getElement().getCProject(); - IPath projectPath = cproject.getProject().getFullPath(); - char[][] exclusionPatterns = null; - try { - entries = cproject.getResolvedPathEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) { - ISourceEntry entry = (ISourceEntry)entries[i]; - if (projectPath.equals(entry.getPath())) { - srcIsProject = true; - exclusionPatterns = entry.fullExclusionPatternChars(); - break; - } - } - } - } catch (CModelException e) { - // ignore - } - - ArrayList notChildren = new ArrayList(); - try { - IResource[] resources = null; - if (res instanceof IContainer) { - IContainer container = (IContainer)res; - resources = container.members(false); - } - - if (resources != null) { - for (int i = 0; i < resources.length; i++) { - IResource member = resources[i]; - switch(member.getType()) { - case IResource.FILE: { - String filename = member.getName(); - if (srcIsProject) { - if (CoreModel.isValidTranslationUnitName(cproject.getProject(), filename) - && !CoreModelUtil.isExcluded(member, exclusionPatterns)) { - continue; - } else if (!CoreModelUtil.isExcluded(member, exclusionPatterns)) { - Object o = CModelManager.getDefault().createBinaryFile((IFile)member); - if (o != null) { - continue; - } - } - } - break; - } - case IResource.FOLDER: { - if (srcIsProject && !CoreModelUtil.isExcluded(member, exclusionPatterns)) { - continue; - } - } - } - notChildren.add(member); - } - } - } catch (CoreException e) { - //System.out.println (e); - //CPlugin.log (e); - //e.printStackTrace(); - } - setNonCResources(notChildren.toArray()); - return nonCResources; - } - - /** - * @param container - * @return - */ - public void setNonCResources(Object[] resources) { - nonCResources = resources; - } - - /* - * Reset the source roots and other caches - */ - public void resetCaches() { - if (libReferences != null) { - for (int i = 0; i < libReferences.length; i++) { - try { - ((CElement)libReferences[i]).close(); - } catch (CModelException e) { - // - } - } - } - if (incReferences != null) { - for (int i = 0; i < incReferences.length; i++) { - try { - ((CElement)incReferences[i]).close(); - } catch (CModelException e) { - // - } - } - } - sourceRoots = null; - outputEntries = null; - setNonCResources(null); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java deleted file mode 100644 index 6ea25a80ed9..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CommitWorkingCopyOperation.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -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.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.jobs.ISchedulingRule; - -/** - * Commits the contents of a working copy translation unit to its original - * element and resource, bringing the C Model up-to-date with the current - * contents of the working copy. - * - * <p>It is possible that the contents of the - * original resource have changed since the working copy was created, - * in which case there is an update conflict. This operation allows - * for two settings to resolve conflict set by the <code>fForce</code> flag:<ul> - * <li>force flag is <code>false</code> - in this case a <code>CModelException</code> - * is thrown</li> - * <li>force flag is <code>true</code> - in this case the contents of - * the working copy are applied to the underlying resource even though - * the working copy was created before a subsequent change in the - * resource</li> - * </ul> - * - * <p>The default conflict resolution setting is the force flag is <code>false</code> - * - * A CModelOperation exception is thrown either if the commit could not be - * performed. - * - * This class is similar to the JDT CommitWorkingCopyOperation class. - */ - -public class CommitWorkingCopyOperation extends CModelOperation { - /** - * Constructs an operation to commit the contents of a working copy - * to its original translation unit. - */ - - public CommitWorkingCopyOperation(ITranslationUnit element, boolean force) { - super(new ICElement[] {element}, force); - } - - public ISchedulingRule getSchedulingRule() { - IResource resource = getElementToProcess().getResource(); - IWorkspace workspace = resource.getWorkspace(); - if (resource.exists()) { - return workspace.getRuleFactory().modifyRule(resource); - } else { - return workspace.getRuleFactory().createRule(resource); - } - } - - /** - * @see org.eclipse.cdt.internal.core.model.CModelOperation#executeOperation() - */ - protected void executeOperation() throws CModelException { - try { - beginTask("workingCopy.commit", 2); //$NON-NLS-1$ - WorkingCopy copy = (WorkingCopy)getElementToProcess(); - ITranslationUnit original = copy.getOriginalElement(); - - - // creates the delta builder (this remembers the content of the cu) - if (!original.isOpen()) { - // force opening so that the delta builder can get the old info - original.open(null); - } - CElementDeltaBuilder deltaBuilder = new CElementDeltaBuilder(original); - - // save the cu - IBuffer originalBuffer = original.getBuffer(); - if (originalBuffer == null) return; - char[] originalContents = originalBuffer.getCharacters(); - boolean hasSaved = false; - try { - IBuffer copyBuffer = copy.getBuffer(); - if (copyBuffer == null) return; - originalBuffer.setContents(copyBuffer.getCharacters()); - original.save(fMonitor, fForce); - this.hasModifiedResource = true; - hasSaved = true; - } finally { - if (!hasSaved){ - // restore original buffer contents since something went wrong - originalBuffer.setContents(originalContents); - } - } - // make sure working copy is in sync - copy.updateTimeStamp((TranslationUnit)original); - copy.makeConsistent(this); - worked(1); - - if (deltaBuilder != null) { - // build the deltas - deltaBuilder.buildDeltas(); - - // add the deltas to the list of deltas created during this operation - if (deltaBuilder.delta != null) { - addDelta(deltaBuilder.delta); - } - } - worked(1); - } finally { - done(); - } - } - /** - * Possible failures: <ul> - * <li>INVALID_ELEMENT_TYPES - the Translation unit supplied to this - * operation is not a working copy - * <li>ELEMENT_NOT_PRESENT - the Translation unit the working copy is - * based on no longer exists. - * <li>UPDATE_CONFLICT - the original Translation unit has changed since - * the working copy was created and the operation specifies no force - * </ul> - */ - - public ICModelStatus verify() { - - IWorkingCopy wc = (IWorkingCopy) getElementToProcess(); - if (!wc.isWorkingCopy()) { - return new CModelStatus(ICModelStatusConstants.INVALID_ELEMENT_TYPES, wc); - } - - ITranslationUnit original= 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; - - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java deleted file mode 100644 index 38c203568f2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContainerEntry.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IContainerEntry; -import org.eclipse.core.runtime.IPath; - -public class ContainerEntry extends PathEntry implements IContainerEntry { - - public ContainerEntry(IPath path, boolean isExported) { - super(IContainerEntry.CDT_CONTAINER, path, isExported); - } - - public boolean equals(Object obj) { - if (obj instanceof IContainerEntry) { - IContainerEntry container = (IContainerEntry)obj; - if (!super.equals(container)) { - return false; - } - if (path == null) { - if (container.getPath() != null) { - return false; - } - } else { - if (!path.equals(container.getPath())) { - return false; - } - } - return true; - } - return super.equals(obj); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java deleted file mode 100644 index b5d214fcc4d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java +++ /dev/null @@ -1,214 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.IParent; - -/** - * This operation copies/moves a collection of elements from their current - * container to a new container, optionally renaming the - * elements. - * <p>Notes:<ul> - * <li>If there is already an element with the same name in - * the new container, the operation either overwrites or aborts, - * depending on the collision policy setting. The default setting is - * abort. - * - * <li>When constructors are copied to a type, the constructors - * are automatically renamed to the name of the destination - * type. - * - * <li>When main types are renamed (move within the same parent), - * the compilation unit and constructors are automatically renamed - * - * <li>The collection of elements being copied must all share the - * same type of container (for example, must all be type members). - * - * <li>The elements are inserted in the new container in the order given. - * - * <li>The elements can be positioned in the new container - see #setInsertBefore. - * By default, the elements are inserted based on the default positions as specified in - * the creation operation for that element type. - * - * <li>This operation can be used to copy and rename elements within - * the same container. - * - * <li>This operation only copies elements contained within compilation units. - * </ul> - * - */ -public class CopyElementsOperation extends MultiOperation { - - //private Map fSources = new HashMap(); - - /** - * When executed, this operation will copy the given elements to the - * given containers. The elements and destination containers must be in - * the correct order. If there is > 1 destination, the number of destinations - * must be the same as the number of elements being copied/moved/renamed. - */ - public CopyElementsOperation(ICElement[] elementsToCopy, ICElement[] destContainers, boolean force) { - super(elementsToCopy, destContainers, force); - } - - /** - * When executed, this operation will copy the given elements to the - * given container. - */ - public CopyElementsOperation(ICElement[] elementsToCopy, ICElement destContainer, boolean force) { - this(elementsToCopy, new ICElement[]{destContainer}, force); - } - - /** - * Returns the <code>String</code> to use as the main task name - * for progress monitoring. - */ - protected String getMainTaskName() { - return "operation.copyElementProgress"; //$NON-NLS-1$ - } - - /** - * Returns the nested operation to use for processing this element - */ - protected CModelOperation getNestedOperation(ICElement element) { - //ICElement dest = getDestinationParent(element); - switch (element.getElementType()) { - //case ICElement.C_INCLUDE: - // return new CreateIncludeOperation(element, dest); - //case ICElement.C_FUNCTION_DECLARATION : - // return new CreateFunctionDeclarationOperation(element, dest); - //case ICElement.C_FUNCTION : - // return new CreateFunctionOperation(element, dest); - //case ICElement.C_STRUCTURE : - // return new CreateStructureOperation(element, dest, fForce); - //case ICElement.C_METHOD : - // return new CreateMethodOperation(element, dest, fForce); - //case ICElement.C_FIELD : - // return new CreateFieldOperation(element, dest, fForce); - //case ICElement.C_VARIABLE: - // return new CreateVariableOperation(element, dest); - default : - return null; - } - } - - /** - * Copy/move the element from the source to destination, renaming - * the elements as specified, honoring the collision policy. - * - * @exception CModelException if the operation is unable to - * be completed - */ - protected void processElement(ICElement element) throws CModelException { - CModelOperation op = getNestedOperation(element); - if (op == null) { - return; - } - boolean isInTUOperation = op instanceof CreateElementInTUOperation; - if (isInTUOperation) { - CreateElementInTUOperation inTUop = (CreateElementInTUOperation)op; - ICElement sibling = (ICElement) fInsertBeforeElements.get(element); - if (sibling != null) { - (inTUop).setRelativePosition(sibling, CreateElementInTUOperation.INSERT_BEFORE); - } else if (isRename()) { - ICElement anchor = resolveRenameAnchor(element); - if (anchor != null) { - inTUop.setRelativePosition(anchor, CreateElementInTUOperation.INSERT_AFTER); // insert after so that the anchor is found before when deleted below - } - } - String newName = getNewNameFor(element); - if (newName != null) { - inTUop.setAlteredName(newName); - } - } - executeNestedOperation(op, 1); - - //if (isInTUOperation && isMove()) { - // DeleteElementsOperation deleteOp = new DeleteElementsOperation(new ICElement[] { element }, fForce); - // executeNestedOperation(deleteOp, 1); - //} - } - - /** - * Returns the anchor used for positioning in the destination for - * the element being renamed. For renaming, if no anchor has - * explicitly been provided, the element is anchored in the same position. - */ - private ICElement resolveRenameAnchor(ICElement element) throws CModelException { - IParent parent = (IParent) element.getParent(); - ICElement[] children = parent.getChildren(); - for (int i = 0; i < children.length; i++) { - ICElement child = children[i]; - if (child.equals(element)) { - return child; - } - } - return null; - } - - /** - * Possible failures: - * <ul> - * <li>NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation - * <li>INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation - * does not match the number of elements that were supplied. - * </ul> - */ - protected ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - if (fRenamingsList != null && fRenamingsList.length != fElementsToProcess.length) { - return new CModelStatus(ICModelStatusConstants.INDEX_OUT_OF_BOUNDS); - } - return CModelStatus.VERIFIED_OK; - } - - /** - * @see MultiOperation - * - * Possible failure codes: - * <ul> - * - * <li>ELEMENT_DOES_NOT_EXIST - <code>element</code> or its specified destination is - * is <code>null</code> or does not exist. If a <code>null</code> element is - * supplied, no element is provided in the status, otherwise, the non-existant element - * is supplied in the status. - * <li>INVALID_ELEMENT_TYPES - <code>element</code> is not contained within a compilation unit. - * This operation only operates on elements contained within compilation units. - * <li>READ_ONLY - <code>element</code> is read only. - * <li>INVALID_DESTINATION - The destination parent specified for <code>element</code> - * is of an incompatible type. The destination for a package declaration or import declaration must - * be a compilation unit; the destination for a type must be a type or compilation - * unit; the destinaion for any type member (other than a type) must be a type. When - * this error occurs, the element provided in the operation status is the <code>element</code>. - * <li>INVALID_NAME - the new name for <code>element</code> does not have valid syntax. - * In this case the element and name are provided in the status. - - * </ul> - */ - protected void verify(ICElement element) throws CModelException { - if (element == null || !element.exists()) - error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element); - - if (element.getElementType() < ICElement.C_UNIT) - error(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element); - - if (element.isReadOnly()) - error(ICModelStatusConstants.READ_ONLY, element); - - ICElement dest = getDestinationParent(element); - verifyDestination(element, dest); - verifySibling(element, dest); - if (fRenamingsList != null) { - verifyRenaming(element); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java deleted file mode 100644 index 2c1d405b9ca..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyResourceElementsOperation.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; - -/** - * This operation copies/moves/renames a collection of resources from their current - * container to a new container, optionally renaming the - * elements. - * <p>Notes:<ul> - * <li>If there is already an resource with the same name in - * the new container, the operation either overwrites or aborts, - * depending on the collision policy setting. The default setting is - * abort. - * - * <li>The collection of elements being copied must all share the - * same type of container. - * - * <li>This operation can be used to copy and rename elements within - * the same container. - * - * <li>This operation only copies translation units. - * </ul> - * - */ -public class CopyResourceElementsOperation extends MultiOperation { - - /** - * The list of new resources created during this operation. - */ - protected ArrayList fCreatedElements; - - /** - * Table specifying deltas for elements being - * copied/moved/renamed. Keyed by elements' project(s), and - * values are the corresponding deltas. - */ - protected Map fDeltasPerProject= new HashMap(1); - - public CopyResourceElementsOperation(ICElement[] src, ICElement[] dst, boolean force) { - super(src, dst, force); - } - - /** - * Returns the <code>CElementDelta</code> for <code>cProject</code>, - * creating it and putting it in <code>fDeltasPerProject</code> if - * it does not exist yet. - */ - private CElementDelta getDeltaFor(ICProject cProject) { - CElementDelta delta = (CElementDelta) fDeltasPerProject.get(cProject); - if (delta == null) { - delta = new CElementDelta(cProject); - fDeltasPerProject.put(cProject, delta); - } - return delta; - } - - /** - * @see MultiOperation - */ - protected String getMainTaskName() { - return "operation.copyResourceProgress"; //$NON-NLS-1$ - } - - /** - * Sets the deltas to register the changes resulting from this operation - * for this source element and its destination. - * If the operation is a cross project operation<ul> - * <li>On a copy, the delta should be rooted in the dest project - * <li>On a move, two deltas are generated<ul> - * <li>one rooted in the source project - * <li>one rooted in the destination project</ul></ul> - * If the operation is rooted in a single project, the delta is rooted in that project - * - */ - protected void prepareDeltas(ICElement sourceElement, ICElement destinationElement) { - ICProject destProject = destinationElement.getCProject(); - if (isMove()) { - ICProject sourceProject = sourceElement.getCProject(); - getDeltaFor(sourceProject).movedFrom(sourceElement, destinationElement); - getDeltaFor(destProject).movedTo(destinationElement, sourceElement); - } else { - getDeltaFor(destProject).added(destinationElement); - } - } - - /** - * Process all of the changed deltas generated by this operation. - */ - protected void processDeltas() { - for (Iterator deltas = this.fDeltasPerProject.values().iterator(); deltas.hasNext();){ - addDelta((ICElementDelta) deltas.next()); - } - } - - /** - * Copies/moves a compilation unit with the name <code>newName</code> - * to the destination package.<br> - * The package statement in the compilation unit is updated if necessary. - * The main type of the compilation unit is renamed if necessary. - * - * @exception JavaModelException if the operation is unable to - * complete - */ - private void processResource(ICElement source, ICElement dest) throws CModelException { - String newName = getNewNameFor(source); - String destName = (newName != null) ? newName : source.getElementName(); - - // copy resource - IFile sourceResource = (IFile)source.getResource(); - // can be an IFolder or an IProject - IContainer destFolder = (IContainer)dest.getResource(); - IFile destFile = destFolder.getFile(new Path(destName)); - if (!destFile.equals(sourceResource)) { - try { - if (destFile.exists()) { - if (fForce) { - // we can remove it - deleteResource(destFile, false); - } else { - // abort - throw new CModelException(new CModelStatus(ICModelStatusConstants.NAME_COLLISION)); - } - } - if (this.isMove()) { - sourceResource.move(destFile.getFullPath(), fForce, true, getSubProgressMonitor(1)); - } else { - sourceResource.copy(destFile.getFullPath(), fForce, getSubProgressMonitor(1)); - } - this.hasModifiedResource = true; - } catch (CModelException e) { - throw e; - } catch (CoreException e) { - throw new CModelException(e); - } - - // update new resource content - - // register the correct change deltas - ICElement cdest = CModelManager.getDefault().create(destFile, null); - prepareDeltas(source, cdest); - fCreatedElements.add(cdest); - //if (newName != null) { - //the main type has been renamed - //String oldName = source.getElementName(); - //oldName = oldName.substring(0, oldName.length() - 5); - //String nName = newName; - //nName = nName.substring(0, nName.length() - 5); - //prepareDeltas(source.getType(oldName), cdest.getType(nName)); - //} - } else { - if (!fForce) { - throw new CModelException(new CModelStatus(ICModelStatusConstants.NAME_COLLISION)); - } - // update new resource content - // in case we do a saveas on the same resource we have to simply update the contents - // see http://dev.eclipse.org/bugs/show_bug.cgi?id=9351 - } - } - - /** - * @see MultiOperation - * This method delegates to <code>processResource</code> or - * <code>processPackageFragmentResource</code>, depending on the type of - * <code>element</code>. - */ - protected void processElement(ICElement element) throws CModelException { - ICElement dest = getDestinationParent(element); - if (element.getElementType() <= ICElement.C_UNIT) { - processResource(element, dest); - //fCreatedElements.add(dest.getCompilationUnit(element.getElementName())); - } else { - throw new CModelException(new CModelStatus(ICModelStatusConstants.INVALID_ELEMENT_TYPES, element)); - } - } - - /** - * @see MultiOperation - * Overridden to allow special processing of <code>CElementDelta</code>s - * and <code>fResultElements</code>. - */ - protected void processElements() throws CModelException { - fCreatedElements = new ArrayList(fElementsToProcess.length); - try { - super.processElements(); - } catch (CModelException cme) { - throw cme; - } finally { - fResultElements = new ICElement[fCreatedElements.size()]; - fCreatedElements.toArray(fResultElements); - processDeltas(); - } - } - - /** - * Possible failures: - * <ul> - * <li>NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation - * <li>INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation - * does not match the number of elements that were supplied. - * </ul> - */ - protected ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - - if (fRenamingsList != null && fRenamingsList.length != fElementsToProcess.length) { - return new CModelStatus(ICModelStatusConstants.INDEX_OUT_OF_BOUNDS); - } - return CModelStatus.VERIFIED_OK; - } - - /** - * @see MultiOperation - */ - protected void verify(ICElement element) throws CModelException { - if (element == null || !element.exists()) - error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, element); - - if (element.isReadOnly() && (isRename() || isMove())) - error(ICModelStatusConstants.READ_ONLY, element); - - CElement dest = (CElement) getDestinationParent(element); - verifyDestination(element, dest); - if (fRenamings != null) { - verifyRenaming(element); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java deleted file mode 100644 index 6ceaaf2d176..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - - -/** - * CoreModelMessages - * - */ -public class CoreModelMessages { - private static final String RESOURCE_BUNDLE= "org.eclipse.cdt.internal.core.model.CoreModelMessages"; //$NON-NLS-1$ - private static ResourceBundle fgResourceBundle; - static { - try { - fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); - } catch (MissingResourceException x) { - fgResourceBundle = null; - } - } - - private CoreModelMessages() { - } - - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } catch (NullPointerException e) { - return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Gets a string from the resource bundle and formats it with the argument - * - * @param key the string used to get the bundle value, must not be null - */ - public static String getFormattedString(String key) { - return getString(key); - } - - - /** - * Gets a string from the resource bundle and formats it with the argument - * - * @param key the string used to get the bundle value, must not be null - */ - public static String getFormattedString(String key, Object arg) { - return MessageFormat.format(getString(key), new Object[] { arg }); - } - - /** - * Gets a string from the resource bundle and formats it with arguments - */ - public static String getFormattedString(String key, Object[] args) { - return MessageFormat.format(getString(key), args); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties deleted file mode 100644 index 35239de6b92..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties +++ /dev/null @@ -1,70 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-v10.html -# -# Contributors: -# QNX Software Systems - Initial API and implementation -############################################################################### - -### CoreModel messages. - -### Core model operations -operation.needElements = Operation requires one or more elements. -operation.needName = Operation requires a name. -operation.needPath = Operation requires a path. -operation.needAbsolutePath = Operation requires an absolute path. Relative path specified was: ''{0}'' -operation.needString = Operation requires a String. -operation.notSupported = Operation not supported for specified element type(s): -operation.cancelled = Operation cancelled. -operation.nullContainer = Container cannot be null. -operation.nullName = Name cannot be null. -operation.copyElementProgress = Copying elements... -operation.moveElementProgress = Moving elements... -operation.renameElementProgress = Renaming elements... -operation.copyResourceProgress = Copying resources... -operation.moveResourceProgress = Moving resources... -operation.renameResourceProgress = Renaming resources... -operation.createUnitProgress = Creating a compilation unit... -operation.createFieldProgress = Creating a field... -operation.createImportsProgress = Creating imports... -operation.createInitializerProgress = Creating an initializer... -operation.createMethodProgress = Creating a method... -operation.createPackageProgress = Creating a package declaration... -operation.createPackageFragmentProgress = Creating package fragment(s)... -operation.createTypeProgress = Creating a type... -operation.deleteElementProgress = Deleting elements... -operation.deleteResourceProgress = Deleting resources... -operation.cannotRenameDefaultPackage = Default package cannot be renamed. -operation.pathOutsideProject = Path ''{0}'' must denote location inside project {1} -operation.sortelements = Sorting elements... - -### working copy -workingCopy.commit = Committing working copy... - -### status -status.cannotUseDeviceOnPath = Operation requires a path with no device. Path specified was: {0} -status.coreException = Core exception. -status.defaultPackageReadOnly = Default package is read-only. -status.evaluationError = Evaluation error: {0}. -status.JDOMError = JDOM error. -status.IOException = I/O exception. -status.indexOutOfBounds = Index out of bounds. -status.invalidContents = Invalid contents specified. -status.invalidDestination = Invalid destination: ''{0}''. -status.invalidName = Invalid name specified: {0}. -status.invalidPackage = Invalid package: {0}. -status.invalidPath = Invalid path: ''{0}''. -status.invalidProject = Invalid project: {0}. -status.invalidResource = Invalid resource: {0}. -status.invalidResourceType = Invalid resource type for {0}. -status.invalidSibling = Invalid sibling: {0}. -status.nameCollision = {0} already exists in target. -status.noLocalContents = Cannot find local contents for resource: {0} -status.OK = OK -status.readOnly = {0} is read-only. -status.targetException = Target exception. -status.updateConflict = Update conflict. - diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java deleted file mode 100644 index 94a6e581a91..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateElementInTUOperation.java +++ /dev/null @@ -1,429 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -import org.eclipse.cdt.core.model.*; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; - -/** - * <p>This abstract class implements behavior common to <code>CreateElementInCUOperations</code>. - * To create a compilation unit, or an element contained in a compilation unit, the - * source code for the entire compilation unit is updated and saved. - * - * <p>The element being created can be positioned relative to an existing - * element in the compilation unit via the methods <code>#createAfter</code> - * and <code>#createBefore</code>. By default, the new element is positioned - * as the last child of its parent element. - * - */ -public abstract class CreateElementInTUOperation extends CModelOperation { - - /** - * A constant meaning to position the new element - * as the last child of its parent element. - */ - protected static final int INSERT_LAST = 1; - - /** - * A constant meaning to position the new element - * after the element defined by <code>fAnchorElement</code>. - */ - protected static final int INSERT_AFTER = 2; - - /** - * A constant meaning to position the new element - * before the element defined by <code>fAnchorElement</code>. - */ - protected static final int INSERT_BEFORE = 3; - - /** - * One of the position constants, describing where - * to position the newly created element. - */ - protected int fInsertionPolicy = INSERT_LAST; - - /** - * The element that is being created. - */ - protected ISourceReference fCreatedElement = null; - - /** - * The element that the newly created element is - * positioned relative to, as described by - * <code>fInsertPosition</code>, or <code>null</code> - * if the newly created element will be positioned - * last. - */ - protected ICElement fAnchorElement = null; - - /** - * A flag indicating whether creation of a new element occurred. - * A request for creating a duplicate element would request in this - * flag being set to <code>false</code>. Ensures that no deltas are generated - * when creation does not occur. - */ - protected boolean fCreationOccurred = true; - - /** - * The position of the element that is being created. - */ - protected int fInsertionPosition = -1; - - /** - * The number of characters the new element replaces, - * or 0 if the new element is inserted, - * or -1 if the new element is append to the end of the CU. - */ - protected int fReplacementLength = -1; - - /** - * Constructs an operation that creates a C Language Element with - * the specified parent, contained within a translation unit. - */ - public CreateElementInTUOperation(ICElement parentElement) { - super(null, new ICElement[]{parentElement}); - initializeDefaultPosition(); - } - - /** - * Only allow cancelling if this operation is not nested. - */ - protected void checkCanceled() { - if (!fNested) { - super.checkCanceled(); - } - } - - /** - * Instructs this operation to position the new element after - * the given sibling, or to add the new element as the last child - * of its parent if <code>null</code>. - */ - public void createAfter(ICElement sibling) { - setRelativePosition(sibling, INSERT_AFTER); - } - - /** - * Instructs this operation to position the new element before - * the given sibling, or to add the new element as the last child - * of its parent if <code>null</code>. - */ - public void createBefore(ICElement sibling) { - setRelativePosition(sibling, INSERT_BEFORE); - } - - /** - * Execute the operation - generate new source for the compilation unit - * and save the results. - * - * @exception CModelException if the operation is unable to complete - */ - protected void executeOperation() throws CModelException { - beginTask(getMainTaskName(), getMainAmountOfWork()); - CElementDelta delta = newCElementDelta(); - ITranslationUnit unit = getTranslationUnit(); - // generateNewTranslationUnitDOM(unit); - insertElement(); - if (fCreationOccurred) { - //a change has really occurred - IBuffer buffer = unit.getBuffer(); - if (buffer == null) return; - char[] bufferContents = buffer.getCharacters(); - if (bufferContents == null) return; - //char[] elementContents = normalizeCRS(..); - char[] elementContents = fCreatedElement.getSource().toCharArray(); - //IFile file = (IFile)((ICResource)unit).getResource(); - //StringBuffer buffer = getContent(file); - switch (fReplacementLength) { - case -1 : - // element is append at the end - //buffer.append(fCreatedElement.getSource()); - buffer.append(elementContents); - break; - - case 0 : - // element is inserted - //buffer.insert(fInsertionPosition, fCreatedElement.getSource()); - buffer.replace(fInsertionPosition, 0, elementContents); - break; - - default : - // element is replacing the previous one - buffer.replace(fInsertionPosition, fReplacementLength, fCreatedElement.getSource()); - } - unit.save(null, false); - //save(buffer, file); - boolean isWorkingCopy = unit.isWorkingCopy(); - //if (isWorkingCopy) { - // this.setAttributes(...); - //} - worked(1); - fResultElements = generateResultHandles(); - if (!isWorkingCopy) { // if unit is working copy, then save will have already fired the delta - if (unit.getParent().exists()) { - for (int i = 0; i < fResultElements.length; i++) { - delta.added(fResultElements[i]); - } - addDelta(delta); - } // else unit is created outside classpath - // non-java resource delta will be notified by delta processor - } - } - done(); - } - - /** - * Creates and returns the handle for the element this operation created. - */ - protected abstract ICElement generateResultHandle(); - - /** - * Creates and returns the handles for the elements this operation created. - */ - protected ICElement[] generateResultHandles() throws CModelException { - return new ICElement[]{generateResultHandle()}; - } - - /** - * Returns the compilation unit in which the new element is being created. - */ - protected ITranslationUnit getTranslationUnit() { - return ((ISourceReference)getParentElement()).getTranslationUnit(); - } - - /** - * Returns the amount of work for the main task of this operation for - * progress reporting. - * @see executeOperation() - */ - protected int getMainAmountOfWork(){ - return 2; - } - - /** - * Returns the name of the main task of this operation for - * progress reporting. - * @see executeOperation() - */ - protected abstract String getMainTaskName(); - - /** - * Returns the elements created by this operation. - */ - public ICElement[] getResultElements() { - return fResultElements; - } - - /** - * Sets the default position in which to create the new type - * member. By default, the new element is positioned as the - * last child of the parent element in which it is created. - * Operations that require a different default position must - * override this method. - */ - protected void initializeDefaultPosition() { - } - - /** - * Inserts the given child into the given JDOM, - * based on the position settings of this operation. - * - * @see createAfter(IJavaElement) - * @see createBefore(IJavaElement); - */ - protected void insertElement() throws CModelException { - if (fInsertionPolicy != INSERT_LAST) { - ISourceRange range = ((ISourceReference)fAnchorElement).getSourceRange(); - switch (fInsertionPolicy) { - case INSERT_AFTER: - fReplacementLength = 0; - fInsertionPosition = range.getStartPos() + range.getLength(); - break; - - case INSERT_BEFORE: - fReplacementLength = 0; - fInsertionPosition = range.getStartPos(); - - default: - fReplacementLength = range.getStartPos() + range.getLength(); - fInsertionPosition = range.getStartPos(); - break; - } - return; - } - //add as the last element of the parent - fReplacementLength = -1; - } - - /** - * Sets the name of the <code>DOMNode</code> that will be used to - * create this new element. - * Used by the <code>CopyElementsOperation</code> for renaming. - * Only used for <code>CreateTypeMemberOperation</code> - */ - protected void setAlteredName(String newName) { - } - - /** - * Instructs this operation to position the new element relative - * to the given sibling, or to add the new element as the last child - * of its parent if <code>null</code>. The <code>position</code> - * must be one of the position constants. - */ - protected void setRelativePosition(ICElement sibling, int policy) throws IllegalArgumentException { - if (sibling == null) { - fAnchorElement = null; - fInsertionPolicy = INSERT_LAST; - } else { - fAnchorElement = sibling; - fInsertionPolicy = policy; - } - } - - /** - * Possible failures: <ul> - * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is - * <code>null</code>. - * <li>INVALID_NAME - no name, a name was null or not a valid - * import declaration name. - * <li>INVALID_SIBLING - the sibling provided for positioning is not valid. - * </ul> - * @see ICModelStatus - * @see CNamingConventions - */ - public ICModelStatus verify() { - if (getParentElement() == null) { - return new CModelStatus(ICModelStatusConstants.NO_ELEMENTS_TO_PROCESS); - } - if (fAnchorElement != null) { - ICElement domPresentParent = fAnchorElement.getParent(); - //if (domPresentParent.getElementType() == ICElement.IMPORT_CONTAINER) { - // domPresentParent = domPresentParent.getParent(); - //} - if (!domPresentParent.equals(getParentElement())) { - return new CModelStatus(ICModelStatusConstants.INVALID_SIBLING, fAnchorElement); - } - } - return CModelStatus.VERIFIED_OK; - } - - - StringBuffer getContent(IFile file) throws CModelException { - InputStream stream = null; - try { - stream = new BufferedInputStream(file.getContents(true)); - } catch (CoreException e) { - throw new CModelException(e); - } - try { - char [] b = getInputStreamAsCharArray(stream, -1, null); - return new StringBuffer(b.length).append(b); - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } finally { - try { - if (stream != null) - stream.close(); - } catch (IOException e) { - } - } - } - - /** - * Returns the given input stream's contents as a character array. - * If a length is specified (ie. if length != -1), only length chars - * are returned. Otherwise all chars in the stream are returned. - * Note this doesn't close the stream. - * @throws IOException if a problem occured reading the stream. - */ - public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding) - throws IOException { - InputStreamReader reader = null; - reader = encoding == null - ? new InputStreamReader(stream) - : new InputStreamReader(stream, encoding); - char[] contents; - if (length == -1) { - contents = new char[0]; - int contentsLength = 0; - int charsRead = -1; - do { - int available = stream.available(); - - // resize contents if needed - if (contentsLength + available > contents.length) { - System.arraycopy( - contents, - 0, - contents = new char[contentsLength + available], - 0, - contentsLength); - } - - // read as many chars as possible - charsRead = reader.read(contents, contentsLength, available); - - if (charsRead > 0) { - // remember length of contents - contentsLength += charsRead; - } - } while (charsRead > 0); - - // resize contents if necessary - if (contentsLength < contents.length) { - System.arraycopy( - contents, - 0, - contents = new char[contentsLength], - 0, - contentsLength); - } - } else { - contents = new char[length]; - int len = 0; - int readSize = 0; - while ((readSize != -1) && (len != length)) { - // See PR 1FMS89U - // We record first the read size. In this case len is the actual read size. - len += readSize; - readSize = reader.read(contents, len, length - len); - } - // See PR 1FMS89U - // Now we need to resize in case the default encoding used more than one byte for each - // character - if (len != length) - System.arraycopy(contents, 0, (contents = new char[len]), 0, len); - } - - return contents; - } - - void save (StringBuffer buffer, IFile file) throws CModelException { - byte[] bytes = buffer.toString().getBytes(); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - // use a platform operation to update the resource contents - try { - boolean force = true; - file.setContents(stream, force, true, null); // record history - } catch (CoreException e) { - throw new CModelException(e); - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java deleted file mode 100644 index 0ebe1dc4554..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFieldOperation.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IStructure; -import org.eclipse.cdt.core.model.ICModelStatus; -/** - * <p>This operation creates a field declaration in a type. - * - * <p>Required Attributes:<ul> - * <li>Containing Type - * <li>The source code for the declaration. No verification of the source is - * performed. - * </ul> - */ -public class CreateFieldOperation extends CreateMemberOperation { - /** - * When executed, this operation will create a field with the given name - * in the given type with the specified source. - * - * <p>By default the new field is positioned after the last existing field - * declaration, or as the first member in the type if there are no - * field declarations. - */ - public CreateFieldOperation(IStructure parentElement, String source, boolean force) { - super(parentElement, source, force); - } - - /** - * @see CreateElementInCUOperation#getMainTaskName - */ - public String getMainTaskName(){ - return "operation.createFieldProgress"; //$NON-NLS-1$ - } - - /** - * By default the new field is positioned after the last existing field - * declaration, or as the first member in the type if there are no - * field declarations. - */ - protected void initializeDefaultPosition() { - IStructure parentElement = getStructure(); - try { - ICElement[] elements = parentElement.getFields(); - if (elements != null && elements.length > 0) { - createAfter(elements[elements.length - 1]); - } else { - elements = parentElement.getChildren(); - if (elements != null && elements.length > 0) { - createBefore(elements[0]); - } - } - } catch (CModelException e) { - } - } - - /** - * @see CreateElementInCUOperation#generateResultHandle - */ - protected ICElement generateResultHandle() { - return getStructure().getField(fSource); - } - - /** - * @see CreateTypeMemberOperation#verifyNameCollision - */ - protected ICModelStatus verifyNameCollision() { - return CModelStatus.VERIFIED_OK; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFunctionDeclarationOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFunctionDeclarationOperation.java deleted file mode 100644 index d00f25c0167..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFunctionDeclarationOperation.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IInclude; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.CModelException; - -/** - * <p>This operation adds an include declaration to an existing translation unit. - * If the translation unit already includes the specified include declaration, - * the include is not generated (it does not generate duplicates). - * - * <p>Required Attributes:<ul> - * <li>Translation unit - * <li>Include name - the name of the include to add to the - * translation unit. For example: <code>"stdio.h"</code> - * </ul> - */ -public class CreateFunctionDeclarationOperation extends CreateElementInTUOperation { - - /** - * The name of the include to be created. - */ - protected String fFunction; - - /** - * When executed, this operation will add an include to the given translation unit. - */ - public CreateFunctionDeclarationOperation(String function, ITranslationUnit parentElement) { - super(parentElement); - fFunction = function; - } - - /** - * @see CreateElementInCUOperation#generateResultHandle - */ - protected ICElement generateResultHandle() { - try { - return getTranslationUnit().getElement(fFunction); - } catch (CModelException e) { - } - return null; - } - - /** - * @see CreateElementInCUOperation#getMainTaskName - */ - public String getMainTaskName(){ - return "operation.createIncludeProgress"; //$NON-NLS-1$ - } - - /** - * Sets the correct position for the new include:<ul> - * <li> after the last include - * <li> if no include, before the first type - * <li> if no type, after the package statement - * <li> and if no package statement - first thing in the CU - */ - protected void initializeDefaultPosition() { - try { - ITranslationUnit tu = getTranslationUnit(); - IInclude[] includes = tu.getIncludes(); - if (includes.length > 0) { - createAfter(includes[includes.length - 1]); - return; - } - } catch (CModelException npe) { - } - } - - /** - * Possible failures: <ul> - * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is - * <code>null</code>. - * <li>INVALID_NAME - not a valid include declaration name. - * </ul> - * @see ICModelStatus - * @see CNamingConventions - */ - public ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - //if (CConventions.validateInclude(fIncludeName).getSeverity() == IStatus.ERROR) { - // return new CModelStatus(ICModelStatusConstants.INVALID_NAME, fIncludeName); - //} - return CModelStatus.VERIFIED_OK; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateIncludeOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateIncludeOperation.java deleted file mode 100644 index e845adc9b92..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateIncludeOperation.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IInclude; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.CModelException; - -/** - * <p>This operation adds an include declaration to an existing translation unit. - * If the translation unit already includes the specified include declaration, - * the include is not generated (it does not generate duplicates). - * - * <p>Required Attributes:<ul> - * <li>Translation unit - * <li>Include name - the name of the include to add to the - * translation unit. For example: <code>"stdio.h"</code> - * </ul> - */ -public class CreateIncludeOperation extends CreateElementInTUOperation { - - /** - * The name of the include to be created. - */ - protected String fIncludeName; - - /** - * When executed, this operation will add an include to the given translation unit. - */ - public CreateIncludeOperation(String includeName, ITranslationUnit parentElement) { - super(parentElement); - fIncludeName = includeName; - } - - /** - * @see CreateElementInCUOperation#generateResultHandle - */ - protected ICElement generateResultHandle() { - return getTranslationUnit().getInclude(fIncludeName); - } - - /** - * @see CreateElementInCUOperation#getMainTaskName - */ - public String getMainTaskName(){ - return "operation.createIncludeProgress"; //$NON-NLS-1$ - } - - /** - * Sets the correct position for the new include:<ul> - * <li> after the last include - * <li> if no include, before the first type - * <li> if no type, after the package statement - * <li> and if no package statement - first thing in the CU - */ - protected void initializeDefaultPosition() { - try { - ITranslationUnit cu = getTranslationUnit(); - IInclude[] includes = cu.getIncludes(); - if (includes.length > 0) { - createAfter(includes[includes.length - 1]); - return; - } - } catch (CModelException npe) { - } - } - - /** - * Possible failures: <ul> - * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is - * <code>null</code>. - * <li>INVALID_NAME - not a valid include declaration name. - * </ul> - * @see ICModelStatus - * @see CNamingConventions - */ - public ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - //if (CConventions.validateInclude(fIncludeName).getSeverity() == IStatus.ERROR) { - // return new CModelStatus(ICModelStatusConstants.INVALID_NAME, fIncludeName); - //} - return CModelStatus.VERIFIED_OK; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMemberOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMemberOperation.java deleted file mode 100644 index ffe3e1538b0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMemberOperation.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IStructure; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; - -/** - * Implements functionality common to - * operations that create type members. - */ -public abstract class CreateMemberOperation extends CreateElementInTUOperation { - /** - * The source code for the new member. - */ - protected String fSource = null; - - /** - * The name of the <code>DOMNode</code> that may be used to - * create this new element. - * Used by the <code>CopyElementsOperation</code> for renaming - */ - protected String fAlteredName; - - /** - * When executed, this operation will create a type member - * in the given parent element with the specified source. - */ - public CreateMemberOperation(ICElement parentElement, String source, boolean force) { - super(parentElement); - fSource= source; - fForce= force; - } - - /** - * Returns the IType the member is to be created in. - */ - protected IStructure getStructure() { - return (IStructure)getParentElement(); - } - - /** - * Sets the name of the <code>DOMNode</code> that will be used to - * create this new element. - * Used by the <code>CopyElementsOperation</code> for renaming - */ - protected void setAlteredName(String newName) { - fAlteredName = newName; - } - - /** - * Possible failures: <ul> - * <li>NO_ELEMENTS_TO_PROCESS - the parent element supplied to the operation is - * <code>null</code>. - * <li>INVALID_CONTENTS - The source is <code>null</code> or has serious syntax errors. - * <li>NAME_COLLISION - A name collision occurred in the destination - * </ul> - */ - public ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - if (fSource == null) { - return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS); - } - if (!fForce) { - //check for name collisions - //if (node == null) { - // return new CModelStatus(ICModelStatusConstants.INVALID_CONTENTS); - // } - //} catch (CModelException jme) { - //} - return verifyNameCollision(); - } - - return CModelStatus.VERIFIED_OK; - } - - /** - * Verify for a name collision in the destination container. - */ - protected ICModelStatus verifyNameCollision() { - return CModelStatus.VERIFIED_OK; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMethodOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMethodOperation.java deleted file mode 100644 index 0704e206400..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateMethodOperation.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IStructure; -import org.eclipse.cdt.core.model.ICModelStatus; - -/** - * <p>This operation creates an instance method. - * - * <p>Required Attributes:<ul> - * <li>Containing type - * <li>The source code for the method. No verification of the source is - * performed. - * </ul> - */ -public class CreateMethodOperation extends CreateMemberOperation { - protected String[] fParameterTypes; - - /** - * When executed, this operation will create a method - * in the given type with the specified source. - */ - public CreateMethodOperation(IStructure parentElement, String source, boolean force) { - super(parentElement, source, force); - } - - /** - * @see CreateElementInCUOperation#generateResultHandle - */ - protected ICElement generateResultHandle() { - return getStructure().getMethod(fSource); - } - - /** - * @see CreateElementInCUOperation#getMainTaskName - */ - public String getMainTaskName(){ - return "operation.createMethodProgress"; //$NON-NLS-1$ - } - - /** - * @see CreateTypeMemberOperation#verifyNameCollision - */ - protected ICModelStatus verifyNameCollision() { - return CModelStatus.VERIFIED_OK; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java deleted file mode 100644 index 527c32a7e44..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IFile; - -/** - * CreateWorkingCopyOperation - */ -public class CreateWorkingCopyOperation extends CModelOperation { - - Map perFactoryWorkingCopies; - IBufferFactory factory; - IProblemRequestor problemRequestor; - - /* - * Creates a working copy from the given original tu and the given buffer factory. - * perFactoryWorkingCopies map is not null if the working copy is a shared working copy. - */ - public CreateWorkingCopyOperation(ITranslationUnit originalElement, Map perFactoryWorkingCopies, IBufferFactory factory, IProblemRequestor problemRequestor) { - super(new ICElement[] {originalElement}); - this.perFactoryWorkingCopies = perFactoryWorkingCopies; - this.factory = factory; - this.problemRequestor = problemRequestor; - } - protected void executeOperation() throws CModelException { - ITranslationUnit tu = getTranslationUnit(); - - WorkingCopy workingCopy = new WorkingCopy(tu.getParent(), (IFile)tu.getResource(), this.factory, this.problemRequestor); - // open the working copy now to ensure contents are that of the current state of this element - workingCopy.open(this.fMonitor); - - if (this.perFactoryWorkingCopies != null) { - this.perFactoryWorkingCopies.put(tu, workingCopy); - //if (TranslationUnit.SHARED_WC_VERBOSE) { - // System.out.println("Creating shared working copy " + workingCopy.toStringWithAncestors()); //$NON-NLS-1$ - //} - } - - // report added java delta - CElementDelta delta = new CElementDelta(this.getCModel()); - delta.added(workingCopy); - addDelta(delta); - - fResultElements = new ICElement[] {workingCopy}; - } - - /** - * Returns the translation unit this operation is working on. - */ - protected ITranslationUnit getTranslationUnit() { - return (ITranslationUnit)getElementToProcess(); - } - - /** - * @see JavaModelOperation#isReadOnly - */ - public boolean isReadOnly() { - return true; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java deleted file mode 100644 index 3f98000bc3a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DefaultPathEntryStore.java +++ /dev/null @@ -1,404 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.CDescriptorEvent; -import org.eclipse.cdt.core.ICDescriptor; -import org.eclipse.cdt.core.ICDescriptorListener; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.IMacroEntry; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.core.resources.IPathEntryStore; -import org.eclipse.cdt.core.resources.IPathEntryStoreListener; -import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.cdt.internal.core.CharOperation; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * PathEntryStore - */ -public class DefaultPathEntryStore implements IPathEntryStore, ICDescriptorListener { - - static String PATH_ENTRY = "pathentry"; //$NON-NLS-1$ - static String PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$ - static String ATTRIBUTE_KIND = "kind"; //$NON-NLS-1$ - static String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$ - static String ATTRIBUTE_BASE_PATH = "base-path"; //$NON-NLS-1$ - static String ATTRIBUTE_BASE_REF = "base-ref"; //$NON-NLS-1$ - static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$ - static String ATTRIBUTE_SOURCEPATH = "sourcepath"; //$NON-NLS-1$ - static String ATTRIBUTE_ROOTPATH = "roopath"; //$NON-NLS-1$ - static String ATTRIBUTE_PREFIXMAPPING = "prefixmapping"; //$NON-NLS-1$ - static String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$ - static String ATTRIBUTE_INCLUDE = "include"; //$NON-NLS-1$ - static String ATTRIBUTE_LIBRARY = "library"; //$NON-NLS-1$ - static String ATTRIBUTE_SYSTEM = "system"; //$NON-NLS-1$ - static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$ - static String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ - static String VALUE_TRUE = "true"; //$NON-NLS-1$ - - static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0]; - - List listeners; - IProject fProject; - - /** - * - */ - public DefaultPathEntryStore(IProject project) { - fProject = project; - listeners = Collections.synchronizedList(new ArrayList()); - // Register the Core Model on the Descriptor - // Manager, it needs to know about changes. - CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(this); - } - - public IPathEntry[] getRawPathEntries() throws CoreException { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(fProject, false); - if (cdesc != null) { - ArrayList pathEntries = new ArrayList(); - Element element = cdesc.getProjectData(PATH_ENTRY_ID); - NodeList list = element.getChildNodes(); - for (int i = 0; i < list.getLength(); i++) { - Node childNode = list.item(i); - if (childNode.getNodeType() == Node.ELEMENT_NODE) { - if (childNode.getNodeName().equals(PATH_ENTRY)) { - pathEntries.add(decodePathEntry(fProject, (Element) childNode)); - } - } - } - IPathEntry[] entries = new IPathEntry[pathEntries.size()]; - pathEntries.toArray(entries); - return entries; - } - return NO_PATHENTRIES; - } - - public void setRawPathEntries(IPathEntry[] newRawEntries) throws CoreException { - if (Arrays.equals(newRawEntries, getRawPathEntries())) { - return; - } - ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(fProject, true); - Element rootElement = descriptor.getProjectData(PATH_ENTRY_ID); - // Clear out all current children - Node child = rootElement.getFirstChild(); - while (child != null) { - rootElement.removeChild(child); - child = rootElement.getFirstChild(); - } - // Save the entries - if (newRawEntries != null && newRawEntries.length > 0) { - // Serialize the include paths - Document doc = rootElement.getOwnerDocument(); - encodePathEntries(fProject.getFullPath(), doc, rootElement, newRawEntries); - } - descriptor.saveProjectData(); - } - - static IPathEntry decodePathEntry(IProject project, Element element) throws CModelException { - IPath projectPath = project.getFullPath(); - - // kind - String kindAttr = element.getAttribute(ATTRIBUTE_KIND); - int kind = PathEntry.kindFromString(kindAttr); - - // exported flag - boolean isExported = false; - if (element.hasAttribute(ATTRIBUTE_EXPORTED)) { - isExported = element.getAttribute(ATTRIBUTE_EXPORTED).equals(VALUE_TRUE); - } - - // get path and ensure it is absolute - IPath path; - if (element.hasAttribute(ATTRIBUTE_PATH)) { - path = new Path(element.getAttribute(ATTRIBUTE_PATH)); - } else { - path = new Path(""); //$NON-NLS-1$ - } - if (!path.isAbsolute()) { - path = projectPath.append(path); - } - - // check fo the base path - IPath basePath = new Path(element.getAttribute(ATTRIBUTE_BASE_PATH)); - - // get the base ref - IPath baseRef = new Path(element.getAttribute(ATTRIBUTE_BASE_REF)); - - // exclusion patterns (optional) - String exclusion = element.getAttribute(ATTRIBUTE_EXCLUDING); - IPath[] exclusionPatterns = APathEntry.NO_EXCLUSION_PATTERNS; - if (exclusion != null && exclusion.length() > 0) { - char[][] patterns = CharOperation.splitOn('|', exclusion.toCharArray()); - int patternCount; - if ((patternCount = patterns.length) > 0) { - exclusionPatterns = new IPath[patternCount]; - for (int j = 0; j < patterns.length; j++) { - exclusionPatterns[j] = new Path(new String(patterns[j])); - } - } - } - - // recreate the entry - switch (kind) { - case IPathEntry.CDT_PROJECT : - return CoreModel.newProjectEntry(path, isExported); - case IPathEntry.CDT_LIBRARY : { - IPath libraryPath = new Path(element.getAttribute(ATTRIBUTE_LIBRARY)); - // source attachment info (optional) - IPath sourceAttachmentPath = element.hasAttribute(ATTRIBUTE_SOURCEPATH) ? new Path( - element.getAttribute(ATTRIBUTE_SOURCEPATH)) : null; - IPath sourceAttachmentRootPath = element.hasAttribute(ATTRIBUTE_ROOTPATH) ? new Path( - element.getAttribute(ATTRIBUTE_ROOTPATH)) : null; - IPath sourceAttachmentPrefixMapping = element.hasAttribute(ATTRIBUTE_PREFIXMAPPING) ? new Path( - element.getAttribute(ATTRIBUTE_PREFIXMAPPING)) : null; - - if (baseRef != null && !baseRef.isEmpty()) { - return CoreModel.newLibraryRefEntry(path, baseRef, libraryPath); - } - return CoreModel.newLibraryEntry(path, basePath, libraryPath, sourceAttachmentPath, sourceAttachmentRootPath, - sourceAttachmentPrefixMapping, isExported); - } - case IPathEntry.CDT_SOURCE : { - // must be an entry in this project or specify another - // project - String projSegment = path.segment(0); - if (projSegment != null && projSegment.equals(project.getName())) { // this - // project - return CoreModel.newSourceEntry(path, exclusionPatterns); - } else { // another project - return CoreModel.newProjectEntry(path, isExported); - } - } - case IPathEntry.CDT_OUTPUT : - return CoreModel.newOutputEntry(path, exclusionPatterns); - case IPathEntry.CDT_INCLUDE : { - // include path info - IPath includePath = new Path(element.getAttribute(ATTRIBUTE_INCLUDE)); - // isSysteminclude - boolean isSystemInclude = false; - if (element.hasAttribute(ATTRIBUTE_SYSTEM)) { - isSystemInclude = element.getAttribute(ATTRIBUTE_SYSTEM).equals(VALUE_TRUE); - } - if (baseRef != null && !baseRef.isEmpty()) { - return CoreModel.newIncludeRefEntry(path, baseRef, includePath); - } - return CoreModel.newIncludeEntry(path, basePath, includePath, isSystemInclude, exclusionPatterns, isExported); - } - case IPathEntry.CDT_MACRO : { - String macroName = element.getAttribute(ATTRIBUTE_NAME); - String macroValue = element.getAttribute(ATTRIBUTE_VALUE); - if (baseRef != null && !baseRef.isEmpty()) { - return CoreModel.newMacroRefEntry(path, baseRef, macroName); - } - return CoreModel.newMacroEntry(path, macroName, macroValue, exclusionPatterns, isExported); - } - case IPathEntry.CDT_CONTAINER : { - IPath id = new Path(element.getAttribute(ATTRIBUTE_PATH)); - return CoreModel.newContainerEntry(id, isExported); - } - default : { - ICModelStatus status = new CModelStatus(ICModelStatus.ERROR, "PathEntry: unknown kind (" + kindAttr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - throw new CModelException(status); - } - } - } - - static void encodePathEntries(IPath projectPath, Document doc, Element configRootElement, IPathEntry[] entries) { - Element element; - for (int i = 0; i < entries.length; i++) { - element = doc.createElement(PATH_ENTRY); - - configRootElement.appendChild(element); - int kind = entries[i].getEntryKind(); - // Set the kind - element.setAttribute(ATTRIBUTE_KIND, PathEntry.kindToString(kind)); - - // translate the project prefix. - IPath xmlPath = entries[i].getPath(); - if (xmlPath == null) { - xmlPath = new Path(""); //$NON-NLS-1$ - } - if (kind != IPathEntry.CDT_CONTAINER) { - // translate to project relative from absolute (unless a device path) - if (xmlPath.isAbsolute()) { - if (projectPath != null && projectPath.isPrefixOf(xmlPath)) { - if (xmlPath.segment(0).equals(projectPath.segment(0))) { - xmlPath = xmlPath.removeFirstSegments(1); - xmlPath = xmlPath.makeRelative(); - } else { - xmlPath = xmlPath.makeAbsolute(); - } - } - } - } - - // Save the path - element.setAttribute(ATTRIBUTE_PATH, xmlPath.toString()); - - // Specifics to the entries - switch(kind) { - case IPathEntry.CDT_SOURCE: - case IPathEntry.CDT_OUTPUT: - case IPathEntry.CDT_PROJECT: - case IPathEntry.CDT_CONTAINER: - break; - case IPathEntry.CDT_LIBRARY: { - ILibraryEntry lib = (ILibraryEntry) entries[i]; - IPath libraryPath = lib.getLibraryPath(); - element.setAttribute(ATTRIBUTE_LIBRARY, libraryPath.toString()); - IPath sourcePath = lib.getSourceAttachmentPath(); - if (sourcePath != null) { - // translate to project relative from absolute - if (projectPath != null && projectPath.isPrefixOf(sourcePath)) { - if (sourcePath.segment(0).equals(projectPath.segment(0))) { - sourcePath = sourcePath.removeFirstSegments(1); - sourcePath = sourcePath.makeRelative(); - } - } - element.setAttribute(ATTRIBUTE_SOURCEPATH, sourcePath.toString()); - } - if (lib.getSourceAttachmentRootPath() != null) { - element.setAttribute(ATTRIBUTE_ROOTPATH, lib.getSourceAttachmentRootPath().toString()); - } - if (lib.getSourceAttachmentPrefixMapping() != null) { - element.setAttribute(ATTRIBUTE_PREFIXMAPPING, lib.getSourceAttachmentPrefixMapping().toString()); - } - break; - } - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry include = (IIncludeEntry) entries[i]; - IPath includePath = include.getIncludePath(); - element.setAttribute(ATTRIBUTE_INCLUDE, includePath.toString()); - if (include.isSystemInclude()) { - element.setAttribute(ATTRIBUTE_SYSTEM, VALUE_TRUE); - } - break; - } - case IPathEntry.CDT_MACRO: { - IMacroEntry macro = (IMacroEntry) entries[i]; - element.setAttribute(ATTRIBUTE_NAME, macro.getMacroName()); - element.setAttribute(ATTRIBUTE_VALUE, macro.getMacroValue()); - break; - } - } - - if (entries[i] instanceof APathEntry) { - APathEntry entry = (APathEntry) entries[i]; - - // save the basePath or the baseRef - IPath basePath = entry.getBasePath(); - IPath baseRef = entry.getBaseReference(); - if (basePath != null && !basePath.isEmpty()) { - element.setAttribute(ATTRIBUTE_BASE_PATH, basePath.toString()); - } else if (baseRef != null && !baseRef.isEmpty()) { - element.setAttribute(ATTRIBUTE_BASE_REF, baseRef.toString()); - } - - // Save the exclusions attributes - IPath[] exclusionPatterns = entry.getExclusionPatterns(); - if (exclusionPatterns.length > 0) { - StringBuffer excludeRule = new StringBuffer(10); - for (int j = 0, max = exclusionPatterns.length; j < max; j++) { - if (j > 0) { - excludeRule.append('|'); - } - excludeRule.append(exclusionPatterns[j]); - } - element.setAttribute(ATTRIBUTE_EXCLUDING, excludeRule.toString()); - } - } - - // Save the export attribute - if (entries[i].isExported()) { - element.setAttribute(ATTRIBUTE_EXPORTED, VALUE_TRUE); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent) - */ - public void descriptorChanged(CDescriptorEvent event) { - if (event.getType() == CDescriptorEvent.CDTPROJECT_CHANGED) { - ICDescriptor cdesc = event.getDescriptor(); - if (cdesc != null && cdesc.getProject() == fProject){ - // Call the listeners. - fireContentChangedEvent(fProject); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.resources.IPathEntryStore#addPathEntryStoreListener(org.eclipse.cdt.core.resources.IPathEntryStoreListener) - */ - public void addPathEntryStoreListener(IPathEntryStoreListener listener) { - listeners.add(listener); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.resources.IPathEntryStore#removePathEntryStoreListener(org.eclipse.cdt.core.resources.IPathEntryStoreListener) - */ - public void removePathEntryStoreListener(IPathEntryStoreListener listener) { - listeners.remove(listener); - } - - private void fireContentChangedEvent(IProject project) { - PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, project, PathEntryStoreChangedEvent.CONTENT_CHANGED); - IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()]; - listeners.toArray(observers); - for (int i = 0; i < observers.length; i++) { - observers[i].pathEntryStoreChanged(evt); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.resources.IPathEntryStore#fireClosedChangedEvent(IProject) - */ - public void close() { - PathEntryStoreChangedEvent evt = new PathEntryStoreChangedEvent(this, fProject, PathEntryStoreChangedEvent.STORE_CLOSED); - IPathEntryStoreListener[] observers = new IPathEntryStoreListener[listeners.size()]; - listeners.toArray(observers); - for (int i = 0; i < observers.length; i++) { - observers[i].pathEntryStoreChanged(evt); - } - CCorePlugin.getDefault().getCDescriptorManager().removeDescriptorListener(this); - } - - public IProject getProject() { - return fProject; - } - - public ICExtensionReference getExtensionReference() { - return null; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java deleted file mode 100644 index 858b6d790b3..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeleteResourceElementsOperation.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; - -/** - * This operation deletes a collection of resources and all of their children. - * It does not delete resources which do not belong to the C Model - * (eg GIF files). - */ -public class DeleteResourceElementsOperation extends MultiOperation { - /** - * When executed, this operation will delete the given elements. The elements - * to delete cannot be <code>null</code> or empty, and must have a corresponding - * resource. - */ - protected DeleteResourceElementsOperation(ICElement[] elementsToProcess, boolean force) { - super(elementsToProcess, force); - } - - /** - * @see MultiOperation - */ - protected String getMainTaskName() { - return "operation.deleteResourceProgress"; //$NON-NLS-1$ - } - - /** - * @see MultiOperation. This method delegate to <code>deleteResource</code> or - * <code>deletePackageFragment</code> depending on the type of <code>element</code>. - */ - protected void processElement(ICElement element) throws CModelException { - deleteResource(element.getResource(), fForce); - } - - /** - * @see MultiOperation - */ - protected void verify(ICElement element) throws CModelException { - if (element == null || !element.exists()) - error(CModelStatus.ELEMENT_DOES_NOT_EXIST, element); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java deleted file mode 100644 index 7733a65940d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java +++ /dev/null @@ -1,636 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IArchiveContainer; -import org.eclipse.cdt.core.model.IBinaryContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.IPath; - -/** - * This class is used by <code>CModelManager</code> to convert - * <code>IResourceDelta</code>s into <code>ICElementDelta</code>s. - * It also does some processing on the <code>CElement</code>s involved - * (e.g. closing them or updating classpaths). - */ -public class DeltaProcessor { - - /** - * The <code>CElementDelta</code> corresponding to the <code>IResourceDelta</code> being translated. - */ - protected CElementDelta fCurrentDelta; - - protected IndexManager indexManager = new IndexManager(); - - /* The C element that was last created (see createElement(IResource). - * This is used as a stack of C elements (using getParent() to pop it, and - * using the various get*(...) to push it. */ - ICElement currentElement; - - static final ICElementDelta[] NO_DELTA = new ICElementDelta[0]; - - public static boolean VERBOSE = false; - - // Hold on the element bein renamed. - ICElement movedFromElement = null; - - /** - * Creates the create corresponding to this resource. - * Returns null if none was found. - */ - protected ICElement createElement(IResource resource) { - if (resource == null) { - return null; - } - - CModelManager manager = CModelManager.getDefault(); - - boolean shouldProcess = true; - - // Check for C nature or if the was a CNature - if (!(resource instanceof IWorkspaceRoot)) { - IProject project = resource.getProject(); - if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) { - shouldProcess = false; - CModel root = manager.getCModel(); - CModelInfo rootInfo = (CModelInfo)manager.peekAtInfo(root); - if (rootInfo != null) { - ICElement[] celements = rootInfo.getChildren(); - for (int i = 0; i < celements.length; i++) { - IResource r = celements[i].getResource(); - if (project.equals(r)) { - shouldProcess = true; - } - } - } - } - } - - if (!shouldProcess) { - return null; - } - - ICElement celement = manager.create(resource, null); - - // BUG 36424: - // The Binary may only be visible in the BinaryContainers - try { - if (celement == null && resource.getType() == IResource.FILE) { - ICElement[] children; - ICProject cproj = manager.create(resource.getProject()); - if (cproj != null && cproj.isOpen()) { - IBinaryContainer bin = cproj.getBinaryContainer(); - if (bin.isOpen()) { - children = ((CElement)bin).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); - if (resource.equals(res)) { - celement = children[i]; - break; - } - } - } - } - } - // BUG 36424: - // The Archive may only be visible in the ArchiveContainers - if (celement == null && resource.getType() == IResource.FILE) { - ICElement[] children; - ICProject cproj = manager.create(resource.getProject()); - if (cproj != null && cproj.isOpen()) { - IArchiveContainer ar = cproj.getArchiveContainer(); - if (ar.isOpen()) { - children = ((CElement)ar).getElementInfo().getChildren(); - for (int i = 0; i < children.length; i++) { - IResource res = children[i].getResource(); - if (resource.equals(res)) { - celement = children[i]; - break; - } - } - } - } - } - // It is not a C resource if the parent is a Binary/ArchiveContainer - // But we have to release too. - if (celement != null && resource.getType() == IResource.FILE) { - ICElement parent = celement.getParent(); - if (parent instanceof IArchiveContainer || parent instanceof IBinaryContainer) { - releaseCElement(celement); - celement = null; - } - } - } catch (CModelException e) { - return null; - } - return celement; - } - - /** - * Adds the given child handle to its parent's cache of children. - */ - protected void addToParentInfo(Openable child) throws CModelException { - Openable parent = (Openable) child.getParent(); - if (parent != null && parent.isOpen()) { - CElementInfo info = parent.getElementInfo(); - // Check if the element exits - if (!info.includesChild(child)) { - info.addChild(child); - } - } - } - - /** - * Removes the given element from its parents cache of children. If the - * element does not have a parent, or the parent is not currently open, - * this has no effect. - */ - private void removeFromParentInfo(ICElement child) throws CModelException { - CModelManager factory = CModelManager.getDefault(); - - // Remove the child from the parent list. - ICElement parent = child.getParent(); - if (parent != null && parent instanceof Parent && factory.peekAtInfo(parent) != null) { - ((Parent)parent).removeChild(child); - } - } - - /** - * Release the Element and cleaning. - */ - protected void releaseCElement(ICElement celement) throws CModelException { - CModelManager factory = CModelManager.getDefault(); - int type = celement.getElementType(); - if (type == ICElement.C_ARCHIVE) { - ICProject cproject = celement.getCProject(); - IArchiveContainer container = cproject.getArchiveContainer(); - fCurrentDelta.changed(container, ICElementDelta.CHANGED); - } else if (type == ICElement.C_BINARY) { - ICProject cproject = celement.getCProject(); - IBinaryContainer container = cproject.getBinaryContainer(); - fCurrentDelta.changed(container, ICElementDelta.CHANGED); - } else { - // If an entire folder was deleted we need to update the - // BinaryContainer/ArchiveContainer also. - ICProject cproject = celement.getCProject(); - CProjectInfo pinfo = (CProjectInfo)factory.peekAtInfo(cproject); - if (pinfo != null && pinfo.vBin != null) { - if (factory.peekAtInfo(pinfo.vBin) != null) { - ICElement[] bins = pinfo.vBin.getChildren(); - for (int i = 0; i < bins.length; i++) { - if (celement.getPath().isPrefixOf(bins[i].getPath())) { - fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); - } - } - } - } - if (pinfo != null && pinfo.vLib != null) { - if (factory.peekAtInfo(pinfo.vLib) != null) { - ICElement[] ars = pinfo.vLib.getChildren(); - for (int i = 0; i < ars.length; i++) { - if (celement.getPath().isPrefixOf(ars[i].getPath())) { - fCurrentDelta.changed(pinfo.vBin, ICElementDelta.CHANGED); - } - } - } - } - } - removeFromParentInfo(celement); - factory.releaseCElement(celement); - } - - /** - * Creates the create corresponding to this resource. - * Returns null if none was found. - */ - protected ICElement createElement(IPath path) { - return CModelManager.getDefault().create(path); - } - - /** - * Processing for an element that has been added:<ul> - * <li>If the element is a project, do nothing, and do not process - * children, as when a project is created it does not yet have any - * natures - specifically a java nature. - * <li>If the elemet is not a project, process it as added (see - * <code>basicElementAdded</code>. - * </ul> - */ - protected void elementAdded(ICElement element, IResourceDelta delta) throws CModelException { - - if (element instanceof Openable) { - addToParentInfo((Openable)element); - } - if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) { - //ICElement movedFromElement = createElement(delta.getMovedFromPath()); - if (movedFromElement == null) { - movedFromElement = createElement(delta.getMovedFromPath()); - } - fCurrentDelta.movedTo(element, movedFromElement); - movedFromElement = null; - } else { - fCurrentDelta.added(element); - } - } - - /** - * Processing for the closing of an element - there are two cases:<ul> - * <li>when a project is closed (in the platform sense), the - * CModel reports this as if the CProject has been removed. - * <li>otherwise, the CModel reports this - * as a the element being closed (CHANGED + F_CLOSED). - * </ul> - * <p>In both cases, the children of the element are not processed. When - * a resource is closed, the platform reports all children as removed. This - * would effectively delete the classpath if we processed children. - */ - protected void elementClosed(ICElement element, IResourceDelta delta) throws CModelException { - - if (element.getElementType() == ICElement.C_PROJECT) { - // treat project closing as removal - elementRemoved(element, delta); - CModelInfo rootInfo = (CModelInfo)CModelManager.getDefault().getCModel().getElementInfo(); - rootInfo.setNonCResources(null); - } else { - fCurrentDelta.closed(element); - } - } - - /** - * Processing for the opening of an element - there are two cases:<ul> - * <li>when a project is opened (in the platform sense), the - * CModel reports this as if the CProject has been added. - * <li>otherwise, the CModel reports this - * as a the element being opened (CHANGED + F_CLOSED). - * </ul> - */ - protected void elementOpened(ICElement element, IResourceDelta delta) throws CModelException { - - if (element.getElementType() == ICElement.C_PROJECT) { - // treat project opening as addition - if (hasCNature(delta.getResource())) { - elementAdded(element, delta); - } - CModelInfo rootInfo = (CModelInfo)CModelManager.getDefault().getCModel().getElementInfo(); - rootInfo.setNonCResources(null); - - } else { - fCurrentDelta.opened(element); - } - } - - /* - * Closes the given element, which removes it from the cache of open elements. - */ - private void close(Openable element) { - try { - element.close(); - } catch (CModelException e) { - // do nothing - } - } - - /** - * Generic processing for elements with changed contents:<ul> - * <li>The element is closed such that any subsequent accesses will re-open - * the element reflecting its new structure. - * <li>An entry is made in the delta reporting a content change (K_CHANGE with F_CONTENT flag set). - * </ul> - */ - protected void elementChanged(ICElement element, IResourceDelta delta) { - if (element instanceof Openable) { - close((Openable)element); - } - fCurrentDelta.changed(element, ICElementDelta.F_CONTENT); - } - - /** - * Generic processing for a removed element:<ul> - * <li>Close the element, removing its structure from the cache - * <li>Remove the element from its parent's cache of children - * <li>Add a REMOVED entry in the delta - * </ul> - */ - protected void elementRemoved(ICElement element, IResourceDelta delta) throws CModelException { - if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { - IPath movedToPath = delta.getMovedToPath(); - // create the moved to element - ICElement movedToElement = createElement(movedToPath); - if (movedToElement == null) { - // moved outside - fCurrentDelta.removed(element); - } else { - movedFromElement = element; - fCurrentDelta.movedFrom(element, movedToElement); - } - } else { - fCurrentDelta.removed(element); - } - releaseCElement(element); - } - - /** - * Filters the generated <code>CElementDelta</code>s to remove those - * which should not be fired (because they don't represent a real change - * in the C Model). - */ - protected ICElementDelta[] filterRealDeltas(ICElementDelta[] deltas) { - - int length = deltas.length; - ICElementDelta[] realDeltas = null; - int index = 0; - for (int i = 0; i < length; i++) { - CElementDelta delta = (CElementDelta)deltas[i]; - if (delta == null) { - continue; - } - if (delta.getAffectedChildren().length > 0 - || delta.getKind() == ICElementDelta.ADDED - || delta.getKind() == ICElementDelta.REMOVED - || (delta.getFlags() & ICElementDelta.F_CLOSED) != 0 - || (delta.getFlags() & ICElementDelta.F_OPENED) != 0 - || delta.resourceDeltasCounter > 0) { - - if (realDeltas == null) { - realDeltas = new ICElementDelta[length]; - } - realDeltas[index++] = delta; - } - } - if (index > 0) { - ICElementDelta[] result = new ICElementDelta[index]; - System.arraycopy(realDeltas, 0, result, 0, index); - return result; - } - return NO_DELTA; - } - - /** - * Returns true if the given resource is contained in an open project - * with a java nature, otherwise false. - */ - protected boolean hasCNature(IResource resource) { - // ensure the project has a C nature (if open) - IProject project = resource.getProject(); - if (project.isOpen()) { - return CoreModel.hasCNature(project); - } - return false; - } - - /** - * Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code> into - * the corresponding set of <code>ICElementDelta</code>, rooted in the - * relevant <code>CModel</code>s. - */ - public ICElementDelta[] processResourceDelta(IResourceDelta changes) { - - try { - ICElement root = CModelManager.getDefault().getCModel(); - // get the workspace delta, and start processing there. - IResourceDelta[] deltas = changes.getAffectedChildren(); - ICElementDelta[] translatedDeltas = new CElementDelta[deltas.length]; - //System.out.println("delta.length: " + deltas.length); - for (int i = 0; i < deltas.length; i++) { - IResourceDelta delta = deltas[i]; - fCurrentDelta = new CElementDelta(root); - traverseDelta(root, delta); // traverse delta - translatedDeltas[i] = fCurrentDelta; - } - return filterRealDeltas(translatedDeltas); - } finally { - } - } - - /** - * Converts an <code>IResourceDelta</code> and its children into - * the corresponding <code>ICElementDelta</code>s. - * Return whether the delta corresponds to a resource on the classpath. - * If it is not a resource on the classpath, it will be added as a non-java - * resource by the sender of this method. - */ - protected void traverseDelta(ICElement parent, IResourceDelta delta) { - boolean updateChildren = true; - try { - IResource resource = delta.getResource(); - ICElement current = createElement(resource); - updateChildren = updateCurrentDeltaAndIndex(current, delta); - if (current == null || current instanceof ISourceRoot) { - nonCResourcesChanged(parent, delta); - } else if (current instanceof ICProject) { - ICProject cprj = (ICProject)current; - CModel cModel = CModelManager.getDefault().getCModel(); - if (!cprj.getProject().isOpen() || cModel.findCProject(cprj.getProject()) == null) { - nonCResourcesChanged(parent, delta); - } - } - if (current != null) { - parent = current; - } - } catch (CModelException e) { - } - if (updateChildren){ - IResourceDelta [] children = delta.getAffectedChildren(); - for (int i = 0; i < children.length; i++) { - traverseDelta(parent, children[i]); - } - } - } - - /** - * Add the resource delta to the right CElementDelta tree. - * @param parent - * @param delta - */ - protected void nonCResourcesChanged(ICElement parent, IResourceDelta delta) throws CModelException { - if (parent instanceof Openable && ((Openable)parent).isOpen()) { - CElementInfo info = ((Openable)parent).getElementInfo(); - switch (parent.getElementType()) { - case ICElement.C_MODEL: - ((CModelInfo)info).setNonCResources(null); - fCurrentDelta.addResourceDelta(delta); - return; - case ICElement.C_PROJECT: - ((CProjectInfo)info).setNonCResources(null); - break; - case ICElement.C_CCONTAINER: - ((CContainerInfo)info).setNonCResources(null); - break; - } - } - CElementDelta elementDelta = fCurrentDelta.find(parent); - if (elementDelta == null) { - fCurrentDelta.changed(parent, ICElementDelta.F_CONTENT); - elementDelta = fCurrentDelta.find(parent); - if (elementDelta != null) { - elementDelta.addResourceDelta(delta); - } - } else { - elementDelta.addResourceDelta(delta); - } - } - - /* - * Update the current delta (ie. add/remove/change the given element) and update the - * correponding index. - * Returns whether the children of the given delta must be processed. - * @throws a CModelException if the delta doesn't correspond to a c element of the given type. - */ - private boolean updateCurrentDeltaAndIndex(ICElement element, IResourceDelta delta) throws CModelException { - - IResource resource = delta.getResource(); - - switch (delta.getKind()) { - case IResourceDelta.ADDED : - if (element != null) { - updateIndexAddResource(element, delta); - elementAdded(element, delta); - } - return true; - - case IResourceDelta.REMOVED : - if (element != null) { - updateIndexRemoveResource(element, delta); - elementRemoved(element, delta); - } - return false; - - case IResourceDelta.CHANGED : - int flags = delta.getFlags(); - if ((flags & IResourceDelta.CONTENT) != 0) { - // content has changed - if (element != null) { - elementChanged(element, delta); - updateIndexAddResource(element, delta); - //check to see if any projects need to be reindexed - updateDependencies(element); - - } - } else if (resource.getType() == IResource.PROJECT) { - if ((flags & IResourceDelta.OPEN) != 0) { - // project has been opened or closed - IProject project = (IProject)resource; - if (element != null) { - if (project.isOpen()) { - if ( CoreModel.hasCNature(project) ) { - // project opening... lets add the runner to the - // map but no need to start it since the deltas - // will populate containers - CModelManager.getDefault().getBinaryRunner((ICProject)element, false); - } - elementOpened(element, delta); - updateIndexAddResource(element, delta); - return true; - } - elementClosed(element, delta); - updateIndexRemoveResource(element, delta); - //Don't process children - return false; - } - } - if ((flags & IResourceDelta.DESCRIPTION) != 0) { - IProject res = (IProject)delta.getResource(); - CModel cModel = CModelManager.getDefault().getCModel(); - boolean wasCProject = cModel.findCProject(res) != null; - boolean isCProject = CProject.hasCNature(res); - if (wasCProject != isCProject) { - // project's nature has been added or removed - if (element != null) { - // note its resources are still visible as roots to other projects - if (isCProject) { - elementAdded(element, delta); - updateIndexAddResource(element, delta); - } else { - elementRemoved(element, delta); - updateIndexRemoveResource(element, delta); - } - return true; - } - } - } - } - return true; - } - return true; - } - - protected void updateIndexAddResource(ICElement element, IResourceDelta delta) { - - if (indexManager == null) - return; - - switch (element.getElementType()) { - case ICElement.C_PROJECT : - this.indexManager.indexAll(element.getCProject().getProject()); - break; - - case ICElement.C_CCONTAINER: - indexManager.indexSourceFolder(element.getCProject().getProject(),element.getPath(),null); - break; - - case ICElement.C_UNIT: - IFile file = (IFile) delta.getResource(); - IProject filesProject = file.getProject(); - indexManager.addSource(file, filesProject.getFullPath()); - break; - } - - } - - protected void updateIndexRemoveResource(ICElement element, IResourceDelta delta) { - - if (indexManager == null) - return; - - switch (element.getElementType()) { - case ICElement.C_PROJECT : - IPath fullPath = element.getCProject().getProject().getFullPath(); - if( delta.getKind() == IResourceDelta.CHANGED ) - indexManager.discardJobs(fullPath.segment(0)); - indexManager.removeIndexFamily(fullPath); - // NB: Discarding index jobs belonging to this project was done during PRE_DELETE - break; - // NB: Update of index if project is opened, closed, or its c nature is added or removed - // is done in updateCurrentDeltaAndIndex - - case ICElement.C_CCONTAINER: - indexManager.removeSourceFolderFromIndex(element.getCProject().getProject(),element.getPath(),null); - break; - - case ICElement.C_UNIT: - IFile file = (IFile) delta.getResource(); - indexManager.remove(file.getFullPath().toString(), file.getProject().getFullPath()); - break; - } - - - } - - private void updateDependencies(ICElement element){ - - IResource resource = element.getResource(); - if (resource == null) - return; - - String filename = resource.getName(); - - if (CoreModel.isValidHeaderUnitName(resource.getProject(), filename)) { - indexManager.updateDependencies(resource); - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DestroyWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DestroyWorkingCopyOperation.java deleted file mode 100644 index a841bf96d54..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DestroyWorkingCopyOperation.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.Map; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.CModelException; - -/** - * Destroys a working copy (remove it from its cache if it is shared) - * and signal its removal through a delta. - */ -public class DestroyWorkingCopyOperation extends CModelOperation { - - public DestroyWorkingCopyOperation(ICElement workingCopy) { - super(new ICElement[] {workingCopy}); - } - - /** - * @exception CModelException if setting the source - * of the original translation unit fails - */ - protected void executeOperation() throws CModelException { - - WorkingCopy workingCopy = getWorkingCopy(); - workingCopy.close(); - - // if original element is not on classpath flush it from the cache - ICElement originalElement = workingCopy.getOriginalElement(); - if (!workingCopy.getParent().exists()) { - ((TranslationUnit)originalElement).close(); - } - - // remove working copy from the cache if it is shared - CModelManager manager = CModelManager.getDefault(); - - // In order to be shared, working copies have to denote the same compilation unit - // AND use the same buffer factory. - // Assuming there is a little set of buffer factories, then use a 2 level Map cache. - Map sharedWorkingCopies = manager.sharedWorkingCopies; - - Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(workingCopy.bufferFactory); - if (perFactoryWorkingCopies != null) { - if (perFactoryWorkingCopies.remove(originalElement) != null) { - //System.out.println("Destroying shared working copy " + workingCopy.toStringWithAncestors());//$NON-NLS-1$ - //CModelManager.getDefault().fire(delta, ElementChangedEvent.POST_RECONCILE); - } - } - - // report C deltas - CElementDelta delta = new CElementDelta(this.getCModel()); - delta.removed(workingCopy); - addDelta(delta); - removeReconcileDelta(workingCopy); - } - - /** - * Returns the working copy this operation is working on. - */ - protected WorkingCopy getWorkingCopy() { - return (WorkingCopy)getElementToProcess(); - } - /** - * @see CModelOperation#isReadOnly - */ - public boolean isReadOnly() { - return true; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java deleted file mode 100644 index 63656a5d469..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElementCache.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IOpenable; -import org.eclipse.cdt.internal.core.util.LRUCache; -import org.eclipse.cdt.internal.core.util.OverflowingLRUCache; - -/** - * An LRU cache of <code>CElements</code>. - * - * This class is similar to the JDT ElementCache class. - */ -public class ElementCache extends OverflowingLRUCache { - - /** - * Constructs a new element cache of the given size. - */ - public ElementCache(int size) { - super(size); - } - /** - * Constructs a new element cache of the given size. - */ - public ElementCache(int size, int overflow) { - super(size, overflow); - } - /** - * Returns true if the element is successfully closed and - * removed from the cache, otherwise false. - * - * <p>NOTE: this triggers an external removal of this element - * by closing the element. - */ - protected boolean close(LRUCacheEntry entry) { - IOpenable element = (IOpenable) entry._fKey; - try { - if (element.hasUnsavedChanges()) { - return false; - } /*else { - // We must close an entire JarPackageFragmentRoot at once. - if (element instanceof JarPackageFragment) { - JarPackageFragment packageFragment= (JarPackageFragment) element; - JarPackageFragmentRoot root = (JarPackageFragmentRoot) packageFragment.getParent(); - root.close(); - }*/ else { - element.close(); - } - return true; - // } - } catch (CModelException npe) { - return false; - } - } - /** - * Returns a new instance of the reciever. - */ - protected LRUCache newInstance(int size, int overflow) { - return new ElementCache(size, overflow); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java deleted file mode 100644 index 344e5c6c6e1..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IEnumeration; - -public class Enumeration extends SourceManipulation implements IEnumeration{ - - public Enumeration(ICElement parent, String name) { - super(parent, name, CElement.C_ENUMERATION); - } - - protected CElementInfo createElementInfo () { - return new EnumerationInfo(this); - } - - private EnumerationInfo getEnumerationInfo() throws CModelException{ - return (EnumerationInfo) getElementInfo(); - } - /** - * @see org.eclipse.cdt.core.model.IVariable#getInitializer() - */ - public String getInitializer() { - return null; - } - - /** - * @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName() - */ - public String getTypeName() throws CModelException { - return getEnumerationInfo().getTypeName(); - } - - /** - * @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String) - */ - public void setTypeName(String type) throws CModelException { - getEnumerationInfo().setTypeName(type); - } - - /** - * @see org.eclipse.cdt.core.model.IDeclaration#isConst() - */ - public boolean isConst() throws CModelException { - return getEnumerationInfo().isConst(); - } - - /** - * @see org.eclipse.cdt.core.model.IDeclaration#isStatic() - */ - public boolean isStatic() throws CModelException { - return getEnumerationInfo().isStatic(); - } - - /** - * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile() - */ - public boolean isVolatile() throws CModelException { - return getEnumerationInfo().isVolatile(); - } - - /** - * Sets the isConst. - * @param isConst The isConst to set - */ - public void setConst(boolean isConst) throws CModelException { - getEnumerationInfo().setConst(isConst); - } - - /** - * Sets the isStatic. - * @param isStatic The isStatic to set - */ - public void setStatic(boolean isStatic) throws CModelException { - getEnumerationInfo().setStatic( isStatic); - } - - /** - * Sets the isVolatile. - * @param isVolatile The isVolatile to set - */ - public void setVolatile(boolean isVolatile) throws CModelException { - getEnumerationInfo().setVolatile(isVolatile); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/EnumerationInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/EnumerationInfo.java deleted file mode 100644 index 511a8a79a00..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/EnumerationInfo.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -public class EnumerationInfo extends VariableInfo{ - - - protected EnumerationInfo(CElement element) { - super(element); - } - - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java deleted file mode 100644 index b72cf36d3d9..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IEnumerator; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -public class Enumerator extends SourceManipulation implements IEnumerator{ - - String constantExpression = ""; //$NON-NLS-1$ - - public Enumerator(ICElement parent, String name) { - super(parent, name, CElement.C_ENUMERATOR); - } - - protected CElementInfo createElementInfo () { - return new SourceManipulationInfo(this); - } - - /** - * @see org.eclipse.cdt.core.model.IEnumerator#getConstantExptrssion() - */ - public String getConstantExpression() { - return constantExpression; - } - - /** - * Sets the constantExpression. - * @param constantExpression The constantExpression to set - */ - public void setConstantExpression(String constantExpression) { - this.constantExpression = constantExpression; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java deleted file mode 100644 index 1f637199e02..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBuffer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * ExternalTranslationUnit - */ -public class ExternalTranslationUnit extends TranslationUnit { - - IPath fPath; - - /** - * @param parent - * @param path - */ - public ExternalTranslationUnit(ICElement parent, IPath path) { - super(parent, path); - fPath = path; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - - // create buffer - translation units only use default buffer factory - BufferManager bufManager = getBufferManager(); - IBuffer buffer = getBufferFactory().createBuffer(this); - if (buffer == null) - return null; - - // set the buffer source - if (buffer.getCharacters() == null){ - IPath path = this.getPath(); - File file = path.toFile(); - if (file != null && file.isFile()) { - try { - InputStream stream = new FileInputStream(file); - buffer.setContents(Util.getInputStreamAsCharArray(stream, (int)file.length(), null)); - } catch (IOException e) { - buffer.setContents(new char[0]); - } - } else { - buffer.setContents(new char[0]); - } - } - - // add buffer to buffer cache - bufManager.addBuffer(buffer); - - // listen to buffer changes - buffer.addBufferChangedListener(this); - - return buffer; - - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return fPath; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java deleted file mode 100644 index 9808c4fa20f..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -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.IField; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -public class Field extends VariableDeclaration implements IField { - - public Field(ICElement parent, String name) { - super(parent, name, CElement.C_FIELD); - } - - public boolean isMutable() throws CModelException{ - return getFieldInfo().isMutable(); - } - - public void setMutable(boolean mutable) throws CModelException{ - getFieldInfo().setMutable(mutable); - } - - public String getTypeName() throws CModelException { - return getFieldInfo().getTypeName(); - } - - public void setTypeName(String type) throws CModelException { - getFieldInfo().setTypeName(type); - } - - public boolean isConst() throws CModelException { - return getFieldInfo().isConst(); - } - - public void setConst(boolean isConst) throws CModelException { - getFieldInfo().setConst(isConst); - } - - public boolean isVolatile() throws CModelException { - return getFieldInfo().isVolatile(); - } - - public void setVolatile(boolean isVolatile) throws CModelException { - getFieldInfo().setVolatile(isVolatile); - } - - public boolean isStatic() throws CModelException { - return getFieldInfo().isStatic(); - } - - public void setStatic(boolean isStatic) throws CModelException { - getFieldInfo().setStatic(isStatic); - } - - public ASTAccessVisibility getVisibility() throws CModelException { - return getFieldInfo().getVisibility(); - } - - public void setVisibility(ASTAccessVisibility visibility) throws CModelException { - getFieldInfo().setVisibility(visibility); - } - - public FieldInfo getFieldInfo() throws CModelException{ - return (FieldInfo) getElementInfo(); - } - - protected CElementInfo createElementInfo () { - return new FieldInfo(this); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FieldInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FieldInfo.java deleted file mode 100644 index 5776a9b326d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FieldInfo.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -public class FieldInfo extends SourceManipulationInfo { - - String typeStr = ""; //$NON-NLS-1$ - boolean isConst = false; - boolean isVolatile = false; - boolean isMutable = false; - boolean isStatic = false; - ASTAccessVisibility visibility; - - protected FieldInfo (CElement element) { - super(element); - visibility = ASTAccessVisibility.PRIVATE; - } - - protected String getTypeName(){ - return typeStr; - } - - protected void setTypeName(String type){ - typeStr = type; - } - - protected boolean isConst(){ - return isConst; - } - - protected void setConst(boolean isConst){ - this.isConst = isConst; - } - - protected boolean isVolatile(){ - return isVolatile; - } - - protected void setVolatile(boolean isVolatile){ - this.isVolatile = isVolatile; - } - - public boolean isStatic() { - return isStatic; - } - - public void setStatic(boolean isStatic) { - this.isStatic = isStatic; - } - - protected boolean isMutable(){ - return isMutable; - } - - protected void setMutable(boolean mutable){ - this.isMutable = mutable; - } - /** - * Returns the visibility. - * @return int - */ - public ASTAccessVisibility getVisibility() { - return visibility; - } - - /** - * Sets the visibility. - * @param visibility The visibility to set - */ - public void setVisibility(ASTAccessVisibility visibility) { - this.visibility = visibility; - } - - /** - * @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(SourceManipulationInfo) - */ - public boolean hasSameContentsAs( SourceManipulationInfo info){ - - return( super.hasSameContentsAs(info) - && (typeStr.equals(((FieldInfo)info).getTypeName())) - && (isConst == ((FieldInfo)info).isConst()) - && (isVolatile == ((FieldInfo)info).isVolatile()) - && (isMutable == ((FieldInfo)info).isMutable()) - && (visibility == ((FieldInfo)info).getVisibility()) - && (isStatic == ((FieldInfo)info).isStatic()) - ); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java deleted file mode 100644 index 7246a96c54e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IFunction; - -public class Function extends FunctionDeclaration implements IFunction { - - public Function(ICElement parent, String name) { - super(parent, name, CElement.C_FUNCTION); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java deleted file mode 100644 index d857c4657c0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IFunctionDeclaration; - -public class FunctionDeclaration extends SourceManipulation implements IFunctionDeclaration { - /** - * An empty list of Strings - */ - protected static final String[] fgEmptyList= new String[] {}; - protected String[] fParameterTypes; - protected String returnType; - - public FunctionDeclaration(ICElement parent, String name) { - super(parent, name, CElement.C_FUNCTION_DECLARATION); - fParameterTypes= fgEmptyList; - } - - public FunctionDeclaration(ICElement parent, String name, int type) { - super(parent, name, type); - fParameterTypes= fgEmptyList; - } - - public String getReturnType(){ - if (returnType != null) - return returnType; - else - return ""; //$NON-NLS-1$ - } - - public void setReturnType(String type){ - returnType = type; - } - - public int getNumberOfParameters() { - return fParameterTypes == null ? 0 : fParameterTypes.length; - } - - public String[] getParameterTypes() { - return fParameterTypes; - } - - public void setParameterTypes(String[] parameterTypes) { - fParameterTypes = parameterTypes; - } - - public String getSignature() throws CModelException{ - StringBuffer sig = new StringBuffer(getElementName()); - sig.append(getParameterClause()); - if(isConst()) - sig.append(" const"); //$NON-NLS-1$ - if(isVolatile()) { - sig.append(" volatile"); //$NON-NLS-1$ - } - return sig.toString(); - } - - public String getParameterClause(){ - StringBuffer sig = new StringBuffer(); - - if(getNumberOfParameters() > 0){ - sig.append("("); //$NON-NLS-1$ - String[] paramTypes = getParameterTypes(); - int i = 0; - sig.append(paramTypes[i++]); - while (i < paramTypes.length){ - sig.append(", "); //$NON-NLS-1$ - sig.append(paramTypes[i++]); - } - sig.append(")"); //$NON-NLS-1$ - } - else{ - sig.append("()"); //$NON-NLS-1$ - } - return sig.toString(); - } - - public String getParameterInitializer(int pos) { - return ""; //$NON-NLS-1$ - } - - public String[] getExceptions(){ - return new String[] {}; - } - - protected CElementInfo createElementInfo () { - return new FunctionInfo(this); - } - - protected FunctionInfo getFunctionInfo() throws CModelException{ - return (FunctionInfo) getElementInfo(); - } - - public boolean equals(Object other) { - // Two function declarations are equal if - // Their parents and names are equal and - return ( super.equals(other) - // their parameter types are equal and - && Util.equalArraysOrNull(fParameterTypes, ((FunctionDeclaration)other).fParameterTypes) - // their return types are equal - && getReturnType().equals(((FunctionDeclaration)other).getReturnType()) - ); - } - - /** - * FunctionDeclarations and Functions can not be constant - * @see org.eclipse.cdt.core.model.IDeclaration#isConst() - */ - public boolean isConst() throws CModelException{ - return getFunctionInfo().isConst(); - } - - public void setConst(boolean isConst) throws CModelException{ - getFunctionInfo().setConst(isConst); - } - - /** - * Returns the isStatic. - * @return boolean - */ - public boolean isStatic() throws CModelException { - return getFunctionInfo().isStatic(); - } - - /** - * Returns the isVolatile. - * @return boolean - */ - public boolean isVolatile() throws CModelException { - return getFunctionInfo().isVolatile(); - } - - /** - * Sets the isStatic. - * @param isStatic The isStatic to set - */ - public void setStatic(boolean isStatic) throws CModelException { - getFunctionInfo().setStatic(isStatic); - } - - /** - * Sets the isVolatile. - * @param isVolatile The isVolatile to set - */ - public void setVolatile(boolean isVolatile) throws CModelException { - getFunctionInfo().setVolatile(isVolatile); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionInfo.java deleted file mode 100644 index 0d74c45793b..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionInfo.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -class FunctionInfo extends SourceManipulationInfo { - - protected boolean isStatic; - protected boolean isVolatile; - protected boolean isConst; - - - protected FunctionInfo (CElement element) { - super(element); - } - - /** - * Returns the isStatic. - * @return boolean - */ - public boolean isStatic() { - return isStatic; - } - - /** - * Returns the isVolatile. - * @return boolean - */ - public boolean isVolatile() { - return isVolatile; - } - - /** - * Sets the isStatic. - * @param isStatic The isStatic to set - */ - public void setStatic(boolean isStatic) { - this.isStatic = isStatic; - } - - /** - * Sets the isVolatile. - * @param isVolatile The isVolatile to set - */ - public void setVolatile(boolean isVolatile) { - this.isVolatile = isVolatile; - } - - /** - * @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo) - */ - public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) { - return (super.hasSameContentsAs(otherInfo) - && (this.isStatic() == ((FunctionInfo)otherInfo).isStatic()) - && (this.isVolatile() == ((FunctionInfo)otherInfo).isVolatile()) - ); - } - - /** - * Returns the isConst. - * @return boolean - */ - public boolean isConst() { - return isConst; - } - - /** - * Sets the isConst. - * @param isConst The isConst to set - */ - public void setConst(boolean isConst) { - this.isConst = isConst; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java deleted file mode 100644 index 3c734d33532..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ITemplate; - -public class FunctionTemplate extends FunctionDeclaration implements ITemplate{ - - protected static final String[] fgEmptyList= new String[] {}; - protected String[] templateParameterTypes; - - public FunctionTemplate(ICElement parent, String name) { - super(parent, name, CElement.C_TEMPLATE_FUNCTION); - templateParameterTypes= fgEmptyList; - } - - /** - * Returns the parameterTypes. - * @see org.eclipse.cdt.core.model.ITemplate#getParameters() - * @return String[] - */ - public String[] getTemplateParameterTypes() { - return templateParameterTypes; - } - - /** - * Sets the fParameterTypes. - * @param fParameterTypes The fParameterTypes to set - */ - public void setTemplateParameterTypes(String[] templateParameterTypes) { - this.templateParameterTypes = templateParameterTypes; - } - /** - * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters() - */ - public int getNumberOfTemplateParameters() { - return templateParameterTypes == null ? 0 : templateParameterTypes.length; - } - - /** - * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature() - */ - /* - * The signature in the outline view will be: - * The class X followed by its template parameters, - * then the scope resolution, then the function name, - * followed by its template parameters, folowed by its - * normal parameter list, then a colon then the function's - * return type. - */ - public String getTemplateSignature() throws CModelException { - StringBuffer sig = new StringBuffer(getElementName()); - if(getNumberOfTemplateParameters() > 0){ - sig.append("<"); //$NON-NLS-1$ - String[] paramTypes = getTemplateParameterTypes(); - int i = 0; - sig.append(paramTypes[i++]); - while (i < paramTypes.length){ - sig.append(", "); //$NON-NLS-1$ - sig.append(paramTypes[i++]); - } - sig.append(">"); //$NON-NLS-1$ - } - else{ - sig.append("<>"); //$NON-NLS-1$ - } - sig.append(this.getParameterClause()); - if(isConst()) - sig.append(" const"); //$NON-NLS-1$ - if(isVolatile()) - sig.append(" volatile"); //$NON-NLS-1$ - - if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){ - sig.append(" : "); //$NON-NLS-1$ - sig.append(this.getReturnType()); - } - - return sig.toString(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferFactory.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferFactory.java deleted file mode 100644 index 0265d5428fb..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IBufferFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.*; -import org.eclipse.cdt.core.model.IOpenable; -/** - * A factory that creates <code>IBuffer</code>s for CFiles. - * <p> - * This interface may be implemented by clients. - * </p> - * - * This interface is similar to the JDT IBufferFactory interface. - */ -public interface IBufferFactory { - - /** - * Creates a buffer for the given owner. - * The new buffer will be initialized with the contents of the owner - * if and only if it was not already initialized by the factory (a buffer is uninitialized if - * its content is <code>null</code>). - * - * @param owner the owner of the buffer - * @see IBuffer - */ - IBuffer createBuffer(IOpenable owner); -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IConstants.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IConstants.java deleted file mode 100644 index b9d20660da9..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * This interface defines constants for use by the builder / compiler interface. - */ -public interface IConstants { - - /* - * Modifiers - */ - int AccPublic = 0x0001; - int AccPrivate = 0x0002; - int AccProtected = 0x0004; - int AccStatic = 0x0008; - int AccExtern = 0x0010; - int AccInline = 0x0020; - int AccVolatile = 0x0040; - int AccRegister = 0x0080; - int AccExplicit = 0x0100; - int AccExport = 0x0200; - int AccAbstract = 0x0400; - int AccMutable = 0x0800; - - /* - * Other VM flags. - */ - int AccAuto = 0x0020; - - /** - * Extra flags for types and members. - */ - int AccVirtual = 0x20000; - int AccTypename = 0x100000; -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IDebugLogConstants.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IDebugLogConstants.java deleted file mode 100644 index 6540954f562..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IDebugLogConstants.java +++ /dev/null @@ -1,30 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003,2004 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM Rational Software - Initial API and implementation -***********************************************************************/package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.parser.Enum; - -/** - * @author bgheorgh - * - */ -public interface IDebugLogConstants { - public class DebugLogConstant extends Enum { - protected DebugLogConstant( int value ) - { - super( value ); - } - - } - - public static final DebugLogConstant PARSER = new DebugLogConstant( 1 ); - public static final DebugLogConstant MODEL = new DebugLogConstant ( 2 ); - public static final DebugLogConstant SCANNER = new DebugLogConstant( 3 ); -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java deleted file mode 100644 index dffe3cdfaa9..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IInclude; - -public class Include extends SourceManipulation implements IInclude { - - private final boolean standard; - private String fullPath; - - public Include(ICElement parent, String name, boolean isStandard) { - super(parent, name, CElement.C_INCLUDE); - standard = isStandard; - } - - public String getIncludeName() { - return getElementName(); - } - - public boolean isStandard() { - return standard; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IInclude#getFullFileName() - */ - public String getFullFileName() { - return fullPath; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IInclude#isLocal() - */ - public boolean isLocal() { - return !isStandard(); - } - - /* - * This is not yet populated properly by the parse; - * however, it might be in the near future. - */ - public void setFullPathName(String fullPath) { - this.fullPath = fullPath; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java deleted file mode 100644 index 6259dc64a73..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeEntry.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public class IncludeEntry extends APathEntry implements IIncludeEntry { - IPath includePath; - boolean isSystemInclude; - - public IncludeEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath includePath, boolean isSystemInclude, - IPath[] exclusionPatterns, boolean isExported) { - super(IIncludeEntry.CDT_INCLUDE, basePath, baseRef, resourcePath, exclusionPatterns, isExported); - this.includePath = (includePath == null) ? Path.EMPTY : includePath; - this.isSystemInclude = isSystemInclude; - } - - /** - * Returns the include path - * - * @return IPath - */ - public IPath getIncludePath() { - return includePath; - } - - /** - * Whether or not it a system include path - * - * @return boolean - */ - public boolean isSystemInclude() { - return isSystemInclude; - } - - public boolean equals(Object obj) { - if (obj instanceof IIncludeEntry) { - IIncludeEntry otherEntry = (IIncludeEntry) obj; - if (!super.equals(otherEntry)) { - return false; - } - if (path == null) { - if (otherEntry.getPath() != null) { - return false; - } - } else { - if (!path.toString().equals(otherEntry.getPath().toString())) { - return false; - } - } - if (includePath == null) { - if (otherEntry.getIncludePath() != null) { - return false; - } - } else { - if (!includePath.toString().equals(otherEntry.getIncludePath().toString())) { - return false; - } - } - if (isSystemInclude != otherEntry.isSystemInclude()) { - return false; - } - return true; - } - return super.equals(obj); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IIncludeEntry#getFullIncludePath() - */ - public IPath getFullIncludePath() { - IPath p; - IPath inc = getIncludePath(); - if (!basePath.isEmpty()) { - IPath loc = basePath; - if (!loc.isAbsolute()) { - IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(loc); - if (res != null) { - loc = res.getLocation(); - } - } - p = loc.append(inc); - return p; - } - - p = inc; - - if (!p.isAbsolute()) { - IPath resPath = getPath(); - IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(resPath); - if (res != null) { - if (res.getType() == IResource.FILE) { - res = res.getParent(); - } - IPath location = res.getLocation(); - if (location != null) { - p = location.append(p); - } - } - } - return p; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(super.toString()); - if (isSystemInclude) { - sb.append(" isSystemInclude:").append(isSystemInclude); //$NON-NLS-1$ - } - if (includePath != null && !includePath.isEmpty()) { - sb.append(" includePath:").append(includePath); //$NON-NLS-1$ - } - return sb.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java deleted file mode 100644 index d5b8316e250..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.io.File; -import java.util.ArrayList; -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.cdt.core.model.IIncludeReference; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; - -/** - * IncludeReference - */ -public class IncludeReference extends Openable implements IIncludeReference { - - IIncludeEntry fIncludeEntry; - IPath fPath; - - /** - * @param parent - * @param name - * @param type - */ - public IncludeReference(ICProject cproject, IIncludeEntry entry) { - this(cproject, entry, entry.getFullIncludePath()); - } - - public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) { - super(celement, null, path.toString(), ICElement.C_VCONTAINER); - fIncludeEntry = entry; - fPath = path; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo() - */ - protected CElementInfo createElementInfo() { - return new OpenableInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IIncludeReference#getIncludeEntry() - */ - public IIncludeEntry getIncludeEntry() { - return fIncludeEntry; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { - return computeChildren(info, underlyingResource); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IIncludeReference#getAffectedPath() - */ - public IPath getAffectedPath() { - return fIncludeEntry.getPath(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CContainer#computeChildren(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.resources.IResource) - */ - protected boolean computeChildren(OpenableInfo info, IResource res) throws CModelException { - ArrayList vChildren = new ArrayList(); - File file = null; - if (fPath != null) { - file = fPath.toFile(); - } else if (fIncludeEntry != null) { - file = fIncludeEntry.getFullIncludePath().toFile(); - } - String[] names = null; - if (file != null && file.isDirectory()) { - names = file.list(); - } - - if (names != null) { - IPath path = new Path(file.getAbsolutePath()); - for (int i = 0; i < names.length; i++) { - File child = new File(file, names[i]); - ICElement celement = null; - if (child.isDirectory()) { - celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath())); - } else if (CoreModel.isValidTranslationUnitName(getCProject().getProject(), names[i]) && - child.isFile()) { - celement = new ExternalTranslationUnit(this, path.append(names[i])); - } - if (celement != null) { - vChildren.add(celement); - } - } - } - info.setChildren(vChildren); - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IIncludeReference#isOnIncludeEntry(org.eclipse.core.runtime.IPath) - */ - public boolean isOnIncludeEntry(IPath path) { - if (fIncludeEntry.getIncludePath().isPrefixOf(path) - && !CoreModelUtil.isExcluded(path, fIncludeEntry.fullExclusionPatternChars())) { - return true; - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return fPath; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java deleted file mode 100644 index 61144d7bda0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryEntry.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public class LibraryEntry extends APathEntry implements ILibraryEntry { - - IPath libraryPath; - IPath sourceAttachmentPath; - IPath sourceAttachmentRootPath; - IPath sourceAttachmentPrefixMapping; - - /** - * - * @param basePath - * @param baseRef - * @param libraryPath - * @param sourceAttachmentPath - * @param sourceAttachmentRootPath - * @param sourceAttachmentPrefixMapping - * @param isExported - */ - public LibraryEntry(IPath resourcePath, IPath basePath, IPath baseRef, IPath libraryPath, IPath sourceAttachmentPath, - IPath sourceAttachmentRootPath, IPath sourceAttachmentPrefixMapping, boolean isExported) { - super(ILibraryEntry.CDT_LIBRARY, basePath, baseRef, resourcePath, APathEntry.NO_EXCLUSION_PATTERNS, isExported); - this.libraryPath = (libraryPath == null) ? Path.EMPTY : libraryPath; - this.sourceAttachmentPath = sourceAttachmentPath; - this.sourceAttachmentRootPath = sourceAttachmentRootPath; - this.sourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping; - } - - /** - * Returns the path to the source archive or folder associated with this - * C path entry, or <code>null</code> if this C path entry has no - * source attachment. - * <p> - * Only library and variable C path entries may have source attachments. - * For library C path entries, the result path (if present) locates a source - * archive or folder. This archive or folder can be located in a project of the - * workspace or outside thr workspace. For variable c path entries, the - * result path (if present) has an analogous form and meaning as the - * variable path, namely the first segment is the name of a c path variable. - * </p> - * - * @return the path to the source archive or folder, or <code>null</code> if none - */ - public IPath getSourceAttachmentPath() { - return sourceAttachmentPath; - } - - /** - * Returns the path within the source archive or folder where source - * are located. An empty path indicates that packages are located at - * the root of the source archive or folder. Returns a non-<code>null</code> value - * if and only if <code>getSourceAttachmentPath</code> returns - * a non-<code>null</code> value. - * - * @return the path within the source archive or folder, or <code>null</code> if - * not applicable - */ - public IPath getSourceAttachmentRootPath() { - return sourceAttachmentRootPath; - } - - /** - * Returns the path to map the source paths with to the source achive or folder - * An empty path indicates that the is a one-to-one mapping of source paths to the - * source achive or folder path. Returns a non-<code>null</code> value - * if and only if <code>getSourceAttachmentPath</code> returns - * a non-<code>null</code> value. - * - * @return the path mapping within the source archive or folder, or <code>null</code> if - * not applicable - */ - public IPath getSourceAttachmentPrefixMapping() { - return sourceAttachmentPrefixMapping; - } - - - public boolean equals(Object obj) { - if (obj instanceof ILibraryEntry) { - ILibraryEntry otherEntry = (ILibraryEntry)obj; - if (!super.equals(obj)) { - return false; - } - IPath otherPath = otherEntry.getLibraryPath(); - if (libraryPath == null) { - if (otherPath != null) { - return false; - } - } else { - if (!libraryPath.equals(otherPath)) { - return false; - } - } - otherPath = otherEntry.getSourceAttachmentPath(); - if (sourceAttachmentPath == null) { - if (otherPath != null) { - return false; - } - } else { - if (!sourceAttachmentPath.equals(otherPath)) { - return false; - } - } - otherPath = otherEntry.getSourceAttachmentRootPath(); - if (sourceAttachmentRootPath == null) { - if (otherPath != null) { - return false; - } - } else { - if (!sourceAttachmentRootPath.equals(otherPath)) { - return false; - } - } - return true; - } - return super.equals(obj); - } - - public IPath getFullLibraryPath() { - IPath p; - IPath lib = getLibraryPath(); - if (!basePath.isEmpty()) { - IPath loc = basePath; - if (!loc.isAbsolute()) { - IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(loc); - if (res != null) { - loc = res.getLocation(); - } - } - p = loc.append(lib); - return p; - } else { - p = lib; - } - if (!p.isAbsolute()) { - IPath resPath = getPath(); - IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(resPath); - if (res != null) { - if (res.getType() == IResource.FILE) { - res = res.getParent(); - } - IPath location = res.getLocation(); - if (location != null) { - p = location.append(p); - } - } - } - return p; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ILibraryEntry#getLibraryPath() - */ - public IPath getLibraryPath() { - return libraryPath; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(super.toString()); - if (libraryPath != null && !libraryPath.isEmpty()) { - sb.append(" librarypath:").append(libraryPath.toString()); //$NON-NLS-1$ - } - return sb.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java deleted file mode 100644 index c960275edb2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReference.java +++ /dev/null @@ -1,75 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************/ -/* - * Created on Apr 2, 2003 - * - * To change this generated comment go to - * Window>Preferences>Java>Code Generation>Code Template - */ -package org.eclipse.cdt.internal.core.model; - -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * @author alain - */ -public class LibraryReference extends Parent implements ILibraryReference { - - ILibraryEntry entry; - - public LibraryReference(ICElement parent, ILibraryEntry e) { - super(parent, e.getLibraryPath().lastSegment(), ICElement.C_VCONTAINER); - entry = e; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#createElementInfo() - */ - protected CElementInfo createElementInfo() { - return new CElementInfo(this); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return entry.getFullLibraryPath(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry() - */ - public ILibraryEntry getLibraryEntry() { - return entry; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#generateInfos(java.lang.Object, java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void generateInfos(Object info, Map newElements, IProgressMonitor monitor) throws CModelException { - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java deleted file mode 100644 index 0e6df43148f..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceArchive.java +++ /dev/null @@ -1,72 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************//* - * Created on Apr 2, 2003 - * - * To change this generated comment go to - * Window>Preferences>Java>Code Generation>Code Template - */ -package org.eclipse.cdt.internal.core.model; - -import java.io.File; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -/** - * @author alain - */ -public class LibraryReferenceArchive extends Archive implements ILibraryReference { - - ILibraryEntry entry; - - public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) { - super(parent, e.getFullLibraryPath(), ar); - entry = e; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return entry.getFullLibraryPath(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - File f = getPath().toFile(); - if (f != null) { - return f.exists(); - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry() - */ - public ILibraryEntry getLibraryEntry() { - return entry; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java deleted file mode 100644 index d735b32efea..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/LibraryReferenceShared.java +++ /dev/null @@ -1,82 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation -***********************************************************************//* - * Created on Apr 2, 2003 - * - * To change this generated comment go to - * Window>Preferences>Java>Code Generation>Code Template - */ -package org.eclipse.cdt.internal.core.model; - -import java.io.File; - -import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.ILibraryReference; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -/** - * @author alain - */ -public class LibraryReferenceShared extends Binary implements ILibraryReference { - - ILibraryEntry entry; - - public LibraryReferenceShared(ICElement parent, ILibraryEntry e, IBinaryObject bin) { - super(parent, e.getFullLibraryPath(), bin); - entry = e; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Binary#getModificationStamp() - */ - protected long getModificationStamp() { - File f = getPath().toFile(); - if (f != null) { - return f.lastModified(); - } - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getResource() - */ - public IResource getResource() { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - File f = getPath().toFile(); - if (f != null) { - return f.exists(); - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#getPath() - */ - public IPath getPath() { - return entry.getFullLibraryPath(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ILibraryReference#getLibraryEntry() - */ - public ILibraryEntry getLibraryEntry() { - return entry; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java deleted file mode 100644 index 8570ed04640..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IMacro; - -public class Macro extends SourceManipulation implements IMacro { - - public Macro(ICElement parent, String name) { - super(parent, name, CElement.C_MACRO); - } - - public String getIdentifierList() { - return ""; //$NON-NLS-1$ - } - - public String getTokenSequence() { - return ""; //$NON-NLS-1$ - } - - protected CElementInfo createElementInfo () { - return new SourceManipulationInfo(this); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java deleted file mode 100644 index 0f0f9dbae35..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MacroEntry.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IMacroEntry; -import org.eclipse.core.runtime.IPath; - -public class MacroEntry extends APathEntry implements IMacroEntry { - - String macroName; - String macroValue; - - public MacroEntry (IPath path, IPath baseRef, String macroName, String macroValue, IPath[] exclusionPatterns, boolean isExported) { - super(IMacroEntry.CDT_MACRO, null, baseRef, path, exclusionPatterns, isExported); - if ( macroName == null) { - throw new IllegalArgumentException("Macro name cannot be null"); //$NON-NLS-1$ - } - this.macroName = macroName; - this.macroValue = macroValue == null ? "" : macroValue; //$NON-NLS-1$ - } - - /** - * Returns the macro name. - * @return String - */ - public String getMacroName() { - return macroName; - } - - /** - * Returns the macro value. - * @return String - */ - public String getMacroValue() { - return macroValue; - } - - public boolean equals(Object obj) { - if (obj instanceof IMacroEntry) { - IMacroEntry otherEntry = (IMacroEntry)obj; - if (!super.equals(otherEntry)) { - return false; - } - if (macroName == null) { - if (otherEntry.getMacroName() != null) { - return false; - } - } else { - if (!macroName.equals(otherEntry.getMacroName())) { - return false; - } - } - if (macroValue == null) { - if (otherEntry.getMacroValue() != null) { - return false; - } - } else { - if (!macroValue.equals(otherEntry.getMacroValue())) { - return false; - } - } - return true; - } - return super.equals(obj); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append(super.toString()); - if (macroName != null && macroName.length() > 0) { - sb.append(" name:").append(macroName); //$NON-NLS-1$ - } - if (macroValue != null && macroValue.length() > 0) { - sb.append(" value:").append(macroValue); //$NON-NLS-1$ - } - return sb.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java deleted file mode 100644 index adaf4a5bfa8..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IMethod; - -public class Method extends MethodDeclaration implements IMethod{ - - public Method(ICElement parent, String name){ - super(parent, name, CElement.C_METHOD); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java deleted file mode 100644 index f64950dbcce..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodDeclaration.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IMethodDeclaration; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -public class MethodDeclaration extends FunctionDeclaration implements IMethodDeclaration{ - - boolean isConst = false; - boolean isConstructor = false; - boolean isDestructor = false; - - public MethodDeclaration(ICElement parent, String name){ - super(parent, name, CElement.C_METHOD_DECLARATION); - } - - public MethodDeclaration(ICElement parent, String name, int type){ - super(parent, name, type); - } - - public boolean isConstructor(){ - // is not implemented in the parser's quick mode - //return isConstructor; - return getElementName().equals(getParent().getElementName()); - } - - public boolean isDestructor() { - // is not implemented in the parser's quick mode - //return isDestructor; - return getElementName().startsWith("~"); //$NON-NLS-1$ - } - - public void setConstructor(boolean isConstructor) { - this.isConstructor = isConstructor; - } - - public void setDestructor(boolean isDestructor) { - this.isDestructor = isDestructor; - } - - public boolean isOperator(){ - return getElementName().startsWith("operator"); //$NON-NLS-1$ - } - - public boolean isPureVirtual() throws CModelException{ - return getMethodInfo().isPureVirtual(); - } - - public void setPureVirtual(boolean isPureVirtual) throws CModelException{ - getMethodInfo().setPureVirtual(isPureVirtual); - } - - public boolean isInline() throws CModelException{ - return getMethodInfo().isInline(); - } - - public void setInline(boolean isInline) throws CModelException{ - getMethodInfo().setInline(isInline); - } - - public boolean isVirtual() throws CModelException{ - return getMethodInfo().isVirtual(); - } - - public void setVirtual(boolean isVirtual) throws CModelException{ - getMethodInfo().setVirtual(isVirtual); - } - - public boolean isFriend() throws CModelException{ - return getMethodInfo().isFriend(); - } - - public void setFriend(boolean isFriend) throws CModelException{ - getMethodInfo().setFriend(isFriend); - } - - public boolean isConst(){ - return isConst; - } - - public void setConst(boolean isConst) throws CModelException{ - this.isConst = isConst; - getMethodInfo().setConst(isConst); - } - - public ASTAccessVisibility getVisibility() throws CModelException{ - return getMethodInfo().getVisibility(); - } - - public void setVisibility(ASTAccessVisibility visibility) throws CModelException{ - getMethodInfo().setVisibility(visibility); - } - - protected CElementInfo createElementInfo () { - return new MethodInfo(this); - } - - private MethodInfo getMethodInfo() throws CModelException{ - return (MethodInfo) getElementInfo(); - } - - /* - * See if we need anything else to put in equals here - */ - public boolean equals(Object other) { - // Two methods are equal if - // their parents, names, parameter types and return types are equal and - return ( super.equals(other) - // their constant directive is the same - && isConst() == ((MethodDeclaration)other).isConst() - ); - } - - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodInfo.java deleted file mode 100644 index bf3f5efadd4..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodInfo.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -public class MethodInfo extends FunctionInfo { - - boolean isPureVirtual = false; - boolean isInline = false; - boolean isVirtual = false; - boolean isFriend = false; - boolean isConst = false; - ASTAccessVisibility visibility = null; - - MethodInfo(CElement element) { - super(element); - visibility = ASTAccessVisibility.PRIVATE; - } - - public boolean isPureVirtual(){ - return isPureVirtual; - } - - public void setPureVirtual(boolean isPureVirtual){ - this.isPureVirtual = isPureVirtual; - } - - public boolean isInline(){ - return isInline; - } - - public void setInline(boolean isInline){ - this.isInline = isInline; - } - - public boolean isVirtual(){ - return isVirtual; - } - - public void setVirtual(boolean isVirtual){ - this.isVirtual = isVirtual; - } - - public boolean isFriend(){ - return isFriend; - } - - public void setFriend(boolean isFriend){ - this.isFriend = isFriend; - } - - public boolean isConst(){ - return isConst; - } - - public void setConst(boolean isConst){ - this.isConst = isConst; - } - - /** - * Returns the visibility. - * @return int - */ - public ASTAccessVisibility getVisibility() { - return visibility; - } - - /** - * Sets the visibility. - * @param visibility The visibility to set - */ - public void setVisibility(ASTAccessVisibility visibility) { - this.visibility = visibility; - } - - /** - * @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo) - */ - public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) { - return (super.hasSameContentsAs(otherInfo) - && (isConst == ((MethodInfo)otherInfo).isConst()) - && (isPureVirtual == ((MethodInfo)otherInfo).isPureVirtual()) - && (isInline == ((MethodInfo)otherInfo).isInline()) - && (isVirtual == ((MethodInfo)otherInfo).isVirtual()) - && (isFriend == ((MethodInfo)otherInfo).isFriend()) - && (visibility == ((MethodInfo)otherInfo).getVisibility()) - ); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java deleted file mode 100644 index 9901c881a9a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ITemplate; - -public class MethodTemplate extends MethodDeclaration implements ITemplate{ - - protected static final String[] fgEmptyList= new String[] {}; - protected String[] templateParameterTypes; - - public MethodTemplate(ICElement parent, String name) { - super(parent, name, CElement.C_TEMPLATE_METHOD); - templateParameterTypes= fgEmptyList; - } - - /** - * Returns the parameterTypes. - * @see org.eclipse.cdt.core.model.ITemplate#getParameters() - * @return String[] - */ - public String[] getTemplateParameterTypes() { - return templateParameterTypes; - } - - /** - * Sets the fParameterTypes. - * @param fParameterTypes The fParameterTypes to set - */ - public void setTemplateParameterTypes(String[] templateParameterTypes) { - this.templateParameterTypes = templateParameterTypes; - } - /** - * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters() - */ - public int getNumberOfTemplateParameters() { - return templateParameterTypes == null ? 0 : templateParameterTypes.length; - } - - /** - * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature() - */ - /* - * The signature in the outline view will be: - * The class X followed by its template parameters, - * then the scope resolution, then the function name, - * followed by its template parameters, folowed by its - * normal parameter list, then a colon then the function's - * return type. - */ - - public String getTemplateSignature() throws CModelException { - StringBuffer sig = new StringBuffer(getElementName()); - if(getNumberOfTemplateParameters() > 0){ - sig.append("<"); //$NON-NLS-1$ - String[] paramTypes = getTemplateParameterTypes(); - int i = 0; - sig.append(paramTypes[i++]); - while (i < paramTypes.length){ - sig.append(", "); //$NON-NLS-1$ - sig.append(paramTypes[i++]); - } - sig.append(">"); //$NON-NLS-1$ - } - else{ - sig.append("<>"); //$NON-NLS-1$ - } - sig.append(this.getParameterClause()); - if(isConst()) - sig.append(" const"); //$NON-NLS-1$ - if(isVolatile()) - sig.append(" volatile"); //$NON-NLS-1$ - - if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){ - sig.append(" : "); //$NON-NLS-1$ - sig.append(this.getReturnType()); - } - - return sig.toString(); - } - -} - diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MoveResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MoveResourceElementsOperation.java deleted file mode 100644 index 8152f58e0e0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MoveResourceElementsOperation.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ -import org.eclipse.cdt.core.model.ICElement; - -/** - * This operation moves resources (package fragments and compilation units) from their current - * container to a specified destination container, optionally renaming the - * elements. - * A move resource operation is equivalent to a copy resource operation, where - * the source resources are deleted after the copy. - * <p>This operation can be used for reorganizing resources within the same container. - * - * @see CopyResourceElementsOperation - */ -public class MoveResourceElementsOperation extends CopyResourceElementsOperation { - /** - * When executed, this operation will move the given elements to the given containers. - */ - public MoveResourceElementsOperation(ICElement[] elementsToMove, ICElement[] destContainers, boolean force) { - super(elementsToMove, destContainers, force); - } - - /** - * @see MultiOperation - */ - protected String getMainTaskName() { - return "operation.moveResourceProgress"; //$NON-NLS-1$ - } - - /** - * @see CopyResourceElementsOperation#isMove() - */ - protected boolean isMove() { - return true; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java deleted file mode 100644 index 4ae5aaec649..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java +++ /dev/null @@ -1,297 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.CModelException; - -/** - * This class is used to perform operations on multiple <code>ICElement</code>. - * It is responible for running each operation in turn, collecting - * the errors and merging the corresponding <code>CElementDelta</code>s. - * <p> - * If several errors occured, they are collected in a multi-status - * <code>CModelStatus</code>. Otherwise, a simple <code>CModelStatus</code> - * is thrown. - */ -public abstract class MultiOperation extends CModelOperation { - /** - * The list of renamings supplied to the operation - */ - protected String[] fRenamingsList= null; - - /** - * Table specifying the new parent for elements being - * copied/moved/renamed. - * Keyed by elements being processed, and - * values are the corresponding destination parent. - */ - protected Map fParentElements; - - /** - * Table specifying insertion positions for elements being - * copied/moved/renamed. Keyed by elements being processed, and - * values are the corresponding insertion point. - * @see processElements(IProgressMonitor) - */ - protected Map fInsertBeforeElements= new HashMap(1); - - /** - * This table presents the data in <code>fRenamingList</code> in a more - * convenient way. - */ - protected Map fRenamings; - - /** - * Creates a new <code>MultiOperation</code>. - */ - protected MultiOperation(ICElement[] elementsToProcess, ICElement[] parentElements, boolean force) { - super(elementsToProcess, parentElements, force); - fParentElements = new HashMap(elementsToProcess.length); - if (elementsToProcess.length == parentElements.length) { - for (int i = 0; i < elementsToProcess.length; i++) { - fParentElements.put(elementsToProcess[i], parentElements[i]); - } - } else { //same destination for all elements to be moved/copied/renamed - for (int i = 0; i < elementsToProcess.length; i++) { - fParentElements.put(elementsToProcess[i], parentElements[0]); - } - } - } - - /** - * Creates a new <code>MultiOperation</code> on <code>elementsToProcess</code>. - */ - protected MultiOperation(ICElement[] elementsToProcess, boolean force) { - super(elementsToProcess, force); - } - - /** - * Convenience method to create a <code>CModelException</code> - * embending a <code>CModelStatus</code>. - */ - protected void error(int code, ICElement element) throws CModelException { - throw new CModelException(new CModelStatus(code, element)); - } - - /** - * Executes the operation. - * - * @exception CModelException if one or several errors occured during the operation. - * If multiple errors occured, the corresponding <code>CModelStatus</code> is a - * multi-status. Otherwise, it is a simple one. - */ - protected void executeOperation() throws CModelException { - try { - processElements(); - } catch (CModelException cme) { - throw cme; - } finally { - mergeDeltas(); - } - } - - /** - * Returns the parent of the element being copied/moved/renamed. - */ - protected ICElement getDestinationParent(ICElement child) { - return (ICElement)fParentElements.get(child); - } - - /** - * Returns the name to be used by the progress monitor. - */ - protected abstract String getMainTaskName(); - - /** - * Returns the new name for <code>element</code>, or <code>null</code> - * if there are no renamings specified. - */ - protected String getNewNameFor(ICElement element) { - if (fRenamings != null) - return (String) fRenamings.get(element); - else - return null; - } - - /** - * Sets up the renamings hashtable - keys are the elements and - * values are the new name. - */ - private void initializeRenamings() { - if (fRenamingsList != null && fRenamingsList.length == fElementsToProcess.length) { - fRenamings = new HashMap(fRenamingsList.length); - for (int i = 0; i < fRenamingsList.length; i++) { - if (fRenamingsList[i] != null) { - fRenamings.put(fElementsToProcess[i], fRenamingsList[i]); - } - } - } - } - - /** - * Returns <code>true</code> if this operation represents a move or rename, <code>false</code> - * if this operation represents a copy.<br> - * Note: a rename is just a move within the same parent with a name change. - */ - protected boolean isMove() { - return false; - } - - /** - * Returns <code>true</code> if this operation represents a rename, <code>false</code> - * if this operation represents a copy or move. - */ - protected boolean isRename() { - return false; - } - - /** - * Process all of the changed deltas generated by these operations. - */ - protected void mergeDeltas() { - if (fDeltas != null) { - CElementDelta rootDelta = newCElementDelta(); - boolean insertedTree = false; - for (int i = 0; i < fDeltas.length; i++) { - ICElementDelta delta = fDeltas[i]; - ICElementDelta[] children = delta.getAffectedChildren(); - for (int j = 0; j < children.length; j++) { - CElementDelta projectDelta = (CElementDelta) children[j]; - rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta); - insertedTree = true; - } - } - if (insertedTree) - fDeltas = new ICElementDelta[] {rootDelta}; - else - fDeltas = null; - } - } - - /** - * Subclasses must implement this method to process a given <code>ICElement</code>. - */ - protected abstract void processElement(ICElement element) throws CModelException; - - /** - * Processes all the <code>ICElement</code>s in turn, collecting errors - * and updating the progress monitor. - * - * @exception CModelException if one or several operation(s) was unable to - * be completed. - */ - protected void processElements() throws CModelException { - beginTask(getMainTaskName(), fElementsToProcess.length); - ICModelStatus[] errors = new ICModelStatus[3]; - int errorsCounter = 0; - for (int i = 0; i < fElementsToProcess.length; i++) { - try { - verify(fElementsToProcess[i]); - processElement(fElementsToProcess[i]); - } catch (CModelException jme) { - if (errorsCounter == errors.length) { - // resize - System.arraycopy(errors, 0, (errors = new ICModelStatus[errorsCounter*2]), 0, errorsCounter); - } - errors[errorsCounter++] = jme.getCModelStatus(); - } finally { - worked(1); - } - } - done(); - if (errorsCounter == 1) { - throw new CModelException(errors[0]); - } else if (errorsCounter > 1) { - if (errorsCounter != errors.length) { - // resize - System.arraycopy(errors, 0, (errors = new ICModelStatus[errorsCounter]), 0, errorsCounter); - } - throw new CModelException(CModelStatus.newMultiStatus(errors)); - } - } - - /** - * Sets the insertion position in the new container for the modified element. The element - * being modified will be inserted before the specified new sibling. The given sibling - * must be a child of the destination container specified for the modified element. - * The default is <code>null</code>, which indicates that the element is to be - * inserted at the end of the container. - */ - public void setInsertBefore(ICElement modifiedElement, ICElement newSibling) { - fInsertBeforeElements.put(modifiedElement, newSibling); - } - - /** - * Sets the new names to use for each element being copied. The renamings - * correspond to the elements being processed, and the number of - * renamings must match the number of elements being processed. - * A <code>null</code> entry in the list indicates that an element - * is not to be renamed. - * - * <p>Note that some renamings may not be used. If both a parent - * and a child have been selected for copy/move, only the parent - * is changed. Therefore, if a new name is specified for the child, - * the child's name will not be changed. - */ - public void setRenamings(String[] renamings) { - fRenamingsList = renamings; - initializeRenamings(); - } - - /** - * This method is called for each <code>ICElement</code> before - * <code>processElement</code>. It should check that this <code>element</code> - * can be processed. - */ - protected abstract void verify(ICElement element) throws CModelException; - - /** - * Verifies that the <code>destination</code> specified for the <code>element</code> is valid for the types of the - * <code>element</code> and <code>destination</code>. - */ - protected void verifyDestination(ICElement element, ICElement destination) throws CModelException { - if (destination == null || !destination.exists()) - error(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, destination); - - } - - /** - * Verify that the new name specified for <code>element</code> is - * valid for that type of C element. - */ - protected void verifyRenaming(ICElement element) throws CModelException { - String newName = getNewNameFor(element); - boolean isValid = true; - // Validate the name here. - if (newName.indexOf(' ') != -1) { - isValid = false; - } - - if (!isValid) { - throw new CModelException(new CModelStatus(ICModelStatusConstants.INVALID_NAME, element, newName)); - } - } - - /** - * Verifies that the positioning sibling specified for the <code>element</code> is exists and - * its parent is the destination container of this <code>element</code>. - */ - protected void verifySibling(ICElement element, ICElement destination) throws CModelException { - ICElement insertBeforeElement = (ICElement) fInsertBeforeElements.get(element); - if (insertBeforeElement != null) { - if (!insertBeforeElement.exists() || !insertBeforeElement.getParent().equals(destination)) { - error(ICModelStatusConstants.INVALID_SIBLING, insertBeforeElement); - } - } - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java deleted file mode 100644 index 24424c9233d..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.INamespace; - -public class Namespace extends SourceManipulation implements INamespace{ - - String typeName = ""; //$NON-NLS-1$ - public Namespace(ICElement parent, String name) { - super(parent, name, CElement.C_NAMESPACE); - } - - /* - * Returns the typeName. - * @return String - */ - public String getTypeName() { - return typeName; - } - - /* - * Sets the typeName. - * @param typeName The typeName to set - */ - public void setTypeName(String typeName) { - this.typeName = typeName; - } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object other) { - // TODO Auto-generated method stub - return (super.equals(other) - && (this.getStartPos() == ((Namespace)other).getStartPos()) - && (this.getLength() == ((Namespace)other).getLength()) - ); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java deleted file mode 100644 index fe1cf0fb1a2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/NullBinaryParser.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.IBinaryParser; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; - -/** - */ -public class NullBinaryParser extends PlatformObject implements IBinaryParser { - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath) - */ - public IBinaryFile getBinary(byte[] data, IPath path) throws IOException { - throw new IOException(CCorePlugin.getResourceString("CoreModel.NullBinaryParser.Not_binary_file")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath) - */ - public IBinaryFile getBinary(IPath path) throws IOException { - throw new IOException(CCorePlugin.getResourceString("CoreModel.NullBinaryParser.Not_binary_file")); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#getFormat() - */ - public String getFormat() { - return CCorePlugin.getResourceString("CoreModel.NullBinaryParser.Null_Format"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#isBinary(byte[], org.eclipse.core.runtime.IPath) - */ - public boolean isBinary(byte[] array, IPath path) { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IBinaryParser#getBufferSize() - */ - public int getHintBufferSize() { - return 0; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Openable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Openable.java deleted file mode 100644 index bf45a75d7c2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Openable.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.cdt.core.model.BufferChangedEvent; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBuffer; -import org.eclipse.cdt.core.model.IBufferChangedListener; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.IOpenable; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -public abstract class Openable extends Parent implements IOpenable, IBufferChangedListener { - - protected IResource resource; - - public Openable (ICElement parent, IPath path, int type) { - // Check if the file is under the workspace. - this (parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation (path), - path.lastSegment(), type); - } - - public Openable (ICElement parent, IResource resource, int type) { - this (parent, resource, resource.getName(), type); - } - - public Openable (ICElement parent, IResource res, String name, int type) { - super (parent, name, type); - resource = res; - } - - public IResource getResource() { - return resource; - } - - /** - * The buffer associated with this element has changed. Registers - * this element as being out of synch with its buffer's contents. - * If the buffer has been closed, this element is set as NOT out of - * synch with the contents. - * - * @see IBufferChangedListener - */ - public void bufferChanged(BufferChangedEvent event) { - if (event.getBuffer().isClosed()) { - CModelManager.getDefault().getElementsOutOfSynchWithBuffers().remove(this); - getBufferManager().removeBuffer(event.getBuffer()); - } else { - CModelManager.getDefault().getElementsOutOfSynchWithBuffers().put(this, this); - } - } - - /** - * Builds this element's structure and properties in the given - * info object, based on this element's current contents (reuse buffer - * contents if this element has an open buffer, or resource contents - * if this element does not have an open buffer). Children - * are placed in the given newElements table (note, this element - * has already been placed in the newElements table). Returns true - * if successful, or false if an error is encountered while determining - * the structure of this element. - */ - protected abstract boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException; - - /** - * Close the buffer associated with this element, if any. - */ - protected void closeBuffer() { - if (!hasBuffer()) return; // nothing to do - IBuffer buffer = null; - buffer = getBufferManager().getBuffer(this); - if (buffer != null) { - buffer.close(); - buffer.removeBufferChangedListener(this); - } - } - - /** - * This element is being closed. Do any necessary cleanup. - */ - protected void closing(Object info) throws CModelException { - closeBuffer(); - } - - /** - * @see org.eclipse.cdt.core.model.IOpenable#getBuffer() - */ - public IBuffer getBuffer() throws CModelException { - if (hasBuffer()) { - // ensure element is open - if (!isOpen()) { - getElementInfo(); - } - IBuffer buffer = getBufferManager().getBuffer(this); - if (buffer == null) { - // try to (re)open a buffer - buffer = openBuffer(null); - } - return buffer; - } - return null; - } - - /** - * Answers the buffer factory to use for creating new buffers - */ - public IBufferFactory getBufferFactory(){ - return getBufferManager().getDefaultBufferFactory(); - } - - /** - * Returns the buffer manager for this element. - */ - protected BufferManager getBufferManager() { - return BufferManager.getDefaultBufferManager(); - } - - /** - * Returns true if this element may have an associated source buffer, - * otherwise false. Subclasses must override as required. - */ - protected boolean hasBuffer() { - return false; - } - /** - * @see org.eclipse.cdt.core.model.IOpenable#hasUnsavedChanges() - */ - public boolean hasUnsavedChanges() throws CModelException{ - - if (isReadOnly() || !isOpen()) { - return false; - } - IBuffer buf = this.getBuffer(); - if (buf != null && buf.hasUnsavedChanges()) { - return true; - } - // for roots and projects must check open buffers - // to see if they have an child with unsaved changes - if (fType == C_MODEL || - fType == C_PROJECT) { - Enumeration openBuffers= getBufferManager().getOpenBuffers(); - while (openBuffers.hasMoreElements()) { - IBuffer buffer= (IBuffer)openBuffers.nextElement(); - if (buffer.hasUnsavedChanges()) { - ICElement owner= (ICElement)buffer.getOwner(); - if (isAncestorOf(owner)) { - return true; - } - } - } - } - - return false; - } - /** - * Subclasses must override as required. - * - * @see org.eclipse.cdt.core.model.IOpenable#isConsistent() - */ - public boolean isConsistent() throws CModelException { - return true; - } - - /** - * @see org.eclipse.cdt.core.model.IOpenable#isOpen() - */ - public boolean isOpen() { - return CModelManager.getDefault().getInfo(this) != null; - } - - /** - * Returns true if this represents a source element. - * Openable source elements have an associated buffer created - * when they are opened. - */ - protected boolean isSourceElement() { - return false; - } - - /** - * @see org.eclipse.cdt.core.model.IOpenable#makeConsistent(IProgressMonitor) - */ - public void makeConsistent(IProgressMonitor pm) throws CModelException { - makeConsistent(pm, false); - } - - public void makeConsistent(IProgressMonitor monitor, boolean forced) throws CModelException { - if (isConsistent()) { - return; - } - - // create a new info and make it the current info - // (this will remove the info and its children just before storing the new infos) - CModelManager manager = CModelManager.getDefault(); - boolean hadTemporaryCache = manager.hasTemporaryCache(); - try { - HashMap newElements = manager.getTemporaryCache(); - CElementInfo info = createElementInfo(); - openWhenClosed(info, monitor); - if (newElements.get(this) == null) { - // close any buffer that was opened for the new elements - Iterator iterator = newElements.keySet().iterator(); - while (iterator.hasNext()) { - ICElement element = (ICElement)iterator.next(); - if (element instanceof Openable) { - ((Openable)element).closeBuffer(); - } - } - throw newNotPresentException(); - } - if (!hadTemporaryCache) { - manager.putInfos(this, newElements); - } - } finally { - if (!hadTemporaryCache) { - manager.resetTemporaryCache(); - } - } - - } - - /** - * @see org.eclipse.cdt.core.model.IOpenable#open(IProgressMonitor) - */ - public void open(IProgressMonitor pm) throws CModelException { - getElementInfo(pm); - } - - /** - * Opens a buffer on the contents of this element, and returns - * the buffer, or returns <code>null</code> if opening fails. - * By default, do nothing - subclasses that have buffers - * must override as required. - */ - protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - return null; - } - - /** - * Open the parent element if necessary. - */ - protected void openParent(Object childInfo, Map newElements, IProgressMonitor pm) throws CModelException { - - Openable openableParent = (Openable)getOpenableParent(); - if (openableParent != null && !openableParent.isOpen()){ - openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#generateInfos(java.lang.Object, java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CElement#generateInfos(java.lang.Object, java.util.Map, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void generateInfos(Object info, Map newElements, IProgressMonitor monitor) throws CModelException { - - if (CModelManager.VERBOSE){ - System.out.println("OPENING Element ("+ Thread.currentThread()+"): " + this); //$NON-NLS-1$//$NON-NLS-2$ - } - - // open the parent if necessary - openParent(info, newElements, monitor); - if (monitor != null && monitor.isCanceled()) return; - - // puts the info before building the structure so that questions to the handle behave as if the element existed - // (case of compilation units becoming working copies) - newElements.put(this, info); - - // build the structure of the openable (this will open the buffer if needed) - try { - OpenableInfo openableInfo = (OpenableInfo)info; - boolean isStructureKnown = buildStructure(openableInfo, monitor, newElements, getResource()); - openableInfo.setIsStructureKnown(isStructureKnown); - } catch (CModelException e) { - newElements.remove(this); - throw e; - } - - // remove out of sync buffer for this element - CModelManager.getDefault().getElementsOutOfSynchWithBuffers().remove(this); - - } - - /** - * @see org.eclipse.cdt.core.model.IOpenable#save(IProgressMonitor, boolean) - */ - public void save(IProgressMonitor pm, boolean force) throws CModelException { - if (isReadOnly() || this.getResource().isReadOnly()) { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - IBuffer buf = getBuffer(); - if (buf != null) { - buf.save(pm, force); - this.makeConsistent(pm); // update the element info of this element - } - } - - /** - * Find enclosing package fragment root if any - */ - public SourceRoot getSourceRoot() { - ICElement current = this; - do { - if (current instanceof SourceRoot) return (SourceRoot)current; - current = current.getParent(); - } while(current != null); - return null; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OpenableInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OpenableInfo.java deleted file mode 100644 index b7a0160409b..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OpenableInfo.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - */ -public class OpenableInfo extends CElementInfo { - - /** - * Constructs a new C Model Info - */ - protected OpenableInfo(CElement element) { - super(element); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java deleted file mode 100644 index dabae0f90a3..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/OutputEntry.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IOutputEntry; -import org.eclipse.core.runtime.IPath; - -/** - * OutputEntry - */ -public class OutputEntry extends APathEntry implements IOutputEntry { - /** - * @param kind - * @param path - * @param exclusionPatterns - * @param isExported - */ - public OutputEntry(IPath path, IPath[] exclusionPatterns, boolean isExported) { - super(CDT_OUTPUT, null, null, path, exclusionPatterns, isExported); - } - - public boolean equals(Object obj) { - if (obj instanceof IOutputEntry) { - IOutputEntry otherEntry = (IOutputEntry) obj; - if (!super.equals(otherEntry)) { - return false; - } - if (path == null) { - if (otherEntry.getPath() != null) { - return false; - } - } else { - if (!path.toString().equals(otherEntry.getPath().toString())) { - return false; - } - } - return true; - } - return super.equals(obj); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java deleted file mode 100644 index db6364e909b..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; - -public abstract class Parent extends CElement { - - public Parent (ICElement parent, String name, int type) { - super (parent, name, type); - } - - // members - - /** - * Adds a child to the current element. - * Implementations override this method to support children - */ - public void addChild(ICElement member) throws CModelException { - getElementInfo().addChild(member); - } - - /** - * Removes a child to the current element. - * Implementations override this method to support children - */ - public void removeChild(ICElement member) throws CModelException { - getElementInfo().removeChild(member); - } - - public void removeChildren () throws CModelException { - getElementInfo().removeChildren(); - } - - /** - * Gets the children of this element. - * Returns null if the element does not support children - * Implementations override this method to support children - */ - public ICElement[] getChildren() throws CModelException { - CElementInfo info = getElementInfo(); - if (info != null) - return info.getChildren(); - else - return new ICElement[]{}; - } - - /** - * Gets the children of a certain type - * @param type - * @return ArrayList - */ - public List getChildrenOfType(int type) throws CModelException { - ICElement[] children = getChildren(); - int size = children.length; - ArrayList list = new ArrayList(size); - for (int i = 0; i < size; ++i) { - CElement elt = (CElement)children[i]; - if (elt.getElementType() == type) { - list.add(elt); - } - } - return list; - } - - public boolean hasChildren () { - try { - return getElementInfo().hasChildren(); - } catch (CModelException e) { - return false; - } - } - - protected void setChanged () { - try { - getElementInfo().setChanged(); - } catch (CModelException e) { - // ignore - } - } - - protected boolean hasChanged () { - try { - return getElementInfo().hasChanged(); - } catch (CModelException e) { - return false; - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java deleted file mode 100644 index 0f06b57e8c0..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntry.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public class PathEntry implements IPathEntry { - - protected int entryKind; - protected boolean isExported; - protected IPath path; - - public PathEntry(int entryKind, IPath path, boolean isExported) { - this.path = (path == null) ? Path.EMPTY : path; - this.entryKind = entryKind; - this.isExported = isExported; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IPathEntry#getEntryKind() - */ - public IPath getPath() { - return path; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IPathEntry#getEntryKind() - */ - public int getEntryKind() { - return entryKind; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.IPathEntry#isExported() - */ - public boolean isExported() { - return isExported; - } - - public boolean equals(Object obj) { - if (obj instanceof IPathEntry) { - IPathEntry otherEntry = (IPathEntry)obj; - if (!path.equals(otherEntry.getPath())) { - return false; - } - if (entryKind != otherEntry.getEntryKind()) { - return false; - } - if (isExported != otherEntry.isExported()) { - return false; - } - return true; - } - return super.equals(obj); - } - - /** - * Returns the kind from its <code>String</code> form. - */ - static int kindFromString(String kindStr) { - - if (kindStr.equalsIgnoreCase("prj")) //$NON-NLS-1$ - return IPathEntry.CDT_PROJECT; - //if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ - // return IPathEntry.CDT_VARIABLE; - if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ - return IPathEntry.CDT_SOURCE; - if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ - return IPathEntry.CDT_LIBRARY; - if (kindStr.equalsIgnoreCase("inc")) //$NON-NLS-1$ - return IPathEntry.CDT_INCLUDE; - if (kindStr.equalsIgnoreCase("mac")) //$NON-NLS-1$ - return IPathEntry.CDT_MACRO; - if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ - return IPathEntry.CDT_CONTAINER; - if (kindStr.equalsIgnoreCase("out")) //$NON-NLS-1$ - return IPathEntry.CDT_OUTPUT; - return -1; - } - - /** - * Returns a <code>String</code> for the kind of a path entry. - */ - static String kindToString(int kind) { - - switch (kind) { - case IPathEntry.CDT_PROJECT : - return "prj"; //$NON-NLS-1$ - case IPathEntry.CDT_SOURCE : - return "src"; //$NON-NLS-1$ - case IPathEntry.CDT_LIBRARY : - return "lib"; //$NON-NLS-1$ - case IPathEntry.CDT_INCLUDE : - return "inc"; //$NON-NLS-1$ - case IPathEntry.CDT_MACRO : - return "mac"; //$NON-NLS-1$ - case IPathEntry.CDT_CONTAINER : - return "con"; //$NON-NLS-1$ - case IPathEntry.CDT_OUTPUT: - return "out"; //$NON-NLS-1$ - default : - return "unknown"; //$NON-NLS-1$ - } - } - - /** - * Returns a printable representation of this classpath entry. - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); - if (path != null && !path.isEmpty()) { - buffer.append(path.toString()).append(' '); - } - buffer.append('['); - switch (getEntryKind()) { - case IPathEntry.CDT_LIBRARY : - buffer.append("CDT_LIBRARY"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_PROJECT : - buffer.append("CDT_PROJECT"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_SOURCE : - buffer.append("CDT_SOURCE"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_OUTPUT : - buffer.append("CDT_OUTPUT"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_INCLUDE : - buffer.append("CDT_INCLUDE"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_MACRO : - buffer.append("CDT_MACRO"); //$NON-NLS-1$ - break; - case IPathEntry.CDT_CONTAINER : - buffer.append("CDT_CONTAINER"); //$NON-NLS-1$ - break; - } - buffer.append(']'); - return buffer.toString(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java deleted file mode 100644 index 2a34b77dab1..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ /dev/null @@ -1,1398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ICDescriptor; -import org.eclipse.cdt.core.ICExtensionReference; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.ElementChangedEvent; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.ICModelMarker; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IContainerEntry; -import org.eclipse.cdt.core.model.IElementChangedListener; -import org.eclipse.cdt.core.model.IIncludeEntry; -import org.eclipse.cdt.core.model.ILibraryEntry; -import org.eclipse.cdt.core.model.IMacroEntry; -import org.eclipse.cdt.core.model.IOutputEntry; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.cdt.core.model.IPathEntryContainer; -import org.eclipse.cdt.core.model.IProjectEntry; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.cdt.core.model.PathEntryContainerInitializer; -import org.eclipse.cdt.core.resources.IPathEntryStore; -import org.eclipse.cdt.core.resources.IPathEntryStoreListener; -import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; - -/** - * @author alain - * - */ -public class PathEntryManager implements IPathEntryStoreListener, IElementChangedListener { - - // PathEntry extension - public final static String PATHENTRY_STORE_ID = "PathEntryStore"; //$NON-NLS-1$ - public final static String PATHENTRY_STORE_UNIQ_ID = CCorePlugin.PLUGIN_ID + "." + PATHENTRY_STORE_ID; //$NON-NLS-1$ - - static String CONTAINER_INITIALIZER_EXTPOINT_ID = "PathEntryContainerInitializer"; //$NON-NLS-1$ - /** - * An empty array of strings indicating that a project doesn't have any prerequesite projects. - */ - static final String[] NO_PREREQUISITES = new String[0]; - /** - * pathentry containers pool - * accessing the Container is done synch with the class - */ - private static HashMap Containers = new HashMap(5); - - static final IPathEntry[] NO_PATHENTRIES = new IPathEntry[0]; - - // Synchronized the access of the cache entries. - private Map resolvedMap = new Hashtable(); - - // Accessing the map is synch with the class - private Map storeMap = new HashMap(); - - private static PathEntryManager pathEntryManager; - private PathEntryManager() { - } - - private class PathEntryContainerLock implements IPathEntryContainer { - - boolean runInitializer; - - public boolean isContainerInitialize() { - return runInitializer; - } - - public void setContainerInitialize(boolean init) { - runInitializer = init; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPathEntries() - */ - public IPathEntry[] getPathEntries() { - return NO_PATHENTRIES; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IPathEntryContainer#getDescription() - */ - public String getDescription() { - return new String("Lock container"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IPathEntryContainer#getPath() - */ - public IPath getPath() { - return Path.EMPTY; - } - } - - /** - * Return the singleton. - */ - public static synchronized PathEntryManager getDefault() { - if (pathEntryManager == null) { - pathEntryManager = new PathEntryManager(); - CoreModel.getDefault().addElementChangedListener(pathEntryManager); - } - return pathEntryManager; - } - - public IPathEntry[] getResolvedPathEntries(ICProject cproject) throws CModelException { - boolean markers = cproject.getProject().getWorkspace().isTreeLocked(); - return getResolvedPathEntries(cproject, !markers); - } - - public IPathEntry[] getResolvedPathEntries(ICProject cproject, boolean generateMarkers) throws CModelException { - ArrayList listEntries = (ArrayList)resolvedMap.get(cproject); - IPathEntry[] resolvedEntries; - if (listEntries == null) { - IPath projectPath = cproject.getPath(); - IPathEntry[] rawEntries = getRawPathEntries(cproject); - listEntries = new ArrayList(); - for (int i = 0; i < rawEntries.length; i++) { - IPathEntry entry = rawEntries[i]; - // Expand the containers. - if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { - IContainerEntry centry = (IContainerEntry) entry; - IPathEntryContainer container = getPathEntryContainer(centry, cproject); - if (container != null) { - IPathEntry[] containerEntries = container.getPathEntries(); - if (containerEntries != null) { - for (int j = 0; j < containerEntries.length; j++) { - IPathEntry newEntry = cloneEntry(projectPath, containerEntries[j]); - listEntries.add(newEntry); - } - } - } - } else { - IPathEntry clone = cloneEntry(projectPath, entry); - IPathEntry e = getExpandedPathEntry(clone, cproject); - if (e != null) { - listEntries.add(e); - } - } - } - listEntries.trimToSize(); - resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); - if (generateMarkers) { - final ICProject finalCProject = cproject; - final IPathEntry[] finalEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); - Job markerTask = new Job("PathEntry Marker Job") { //$NON-NLS-1$ - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus run(IProgressMonitor monitor) { - IProject project = finalCProject.getProject(); - flushPathEntryProblemMarkers(project); - ICModelStatus status = validatePathEntry(finalCProject, finalEntries); - if (!status.isOK()) { - createPathEntryProblemMarker(project, status); - } - for (int j = 0; j < finalEntries.length; j++) { - status = validatePathEntry(finalCProject, finalEntries[j], true, false); - if (!status.isOK()) { - createPathEntryProblemMarker(project, status); - } - } - return CModelStatus.OK_STATUS; - } - }; - markerTask.schedule(); - } - resolvedMap.put(cproject, listEntries); - } else { - resolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); - } - return resolvedEntries; - } - - private IPathEntry getExpandedPathEntry(IPathEntry entry, ICProject cproject) throws CModelException { - switch(entry.getEntryKind()) { - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry includeEntry = (IIncludeEntry)entry; - IPath refPath = includeEntry.getBaseReference(); - if (refPath != null && !refPath.isEmpty()) { - IPath includePath = includeEntry.getIncludePath(); - if (refPath.isAbsolute()) { - IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath); - if (res != null && res.getType() == IResource.PROJECT) { - IProject project = (IProject)res; - if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) { - ICProject refCProject = CoreModel.getDefault().create(project); - if (refCProject != null) { - IPathEntry[] entries = getResolvedPathEntries(refCProject); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { - IIncludeEntry refEntry = (IIncludeEntry)entries[i]; - if (refEntry.getIncludePath().equals(includePath)) { - IPath newBasePath = refEntry.getBasePath(); - // If the includePath is relative give a new basepath if none - if (!newBasePath.isAbsolute() && !includePath.isAbsolute()) { - IResource refRes; - if (!newBasePath.isEmpty()) { - refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath); - } else { - IPath refResPath = refEntry.getPath(); - refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath); - } - if (refRes != null) { - if (refRes.getType() == IResource.FILE) { - refRes = refRes.getParent(); - } - newBasePath = refRes.getLocation().append(newBasePath); - } - } - return CoreModel.newIncludeEntry(includeEntry.getPath(), - newBasePath, includePath); - } - } - } - } - } - } - } else { // Container ref - IPathEntryContainer container = getPathEntryContainer(refPath, cproject); - if (container != null) { - IPathEntry[] entries = container.getPathEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_INCLUDE) { - IIncludeEntry refEntry = (IIncludeEntry)entries[i]; - if (refEntry.getIncludePath().equals(includePath)) { - IPath newBasePath = refEntry.getBasePath(); - return CoreModel.newIncludeEntry(includeEntry.getPath(), newBasePath, includePath); - } - } - } - } - } - } - break; - } - - case IPathEntry.CDT_MACRO: { - IMacroEntry macroEntry = (IMacroEntry)entry; - IPath refPath = macroEntry.getBaseReference(); - if (refPath != null && !refPath.isEmpty()) { - String name = macroEntry.getMacroName(); - if (refPath.isAbsolute()) { - IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath); - if (res != null && res.getType() == IResource.PROJECT) { - IProject project = (IProject)res; - if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) { - ICProject refCProject = CoreModel.getDefault().create(project); - if (refCProject != null) { - IPathEntry[] entries = getResolvedPathEntries(refCProject); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) { - IMacroEntry refEntry = (IMacroEntry)entries[i]; - if (refEntry.getMacroName().equals(name)) { - String value = refEntry.getMacroValue(); - return CoreModel.newMacroEntry(macroEntry.getPath(), name, value); - } - } - } - } - } - } - } else { // Container ref - IPathEntryContainer container = getPathEntryContainer(refPath, cproject); - if (container != null) { - IPathEntry[] entries = container.getPathEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_MACRO) { - IMacroEntry refEntry = (IMacroEntry)entries[i]; - if (refEntry.getMacroName().equals(name)) { - String value = refEntry.getMacroValue(); - return CoreModel.newMacroEntry(macroEntry.getPath(), name, value); - } - } - } - } - } - } - break; - } - - case IPathEntry.CDT_LIBRARY: { - ILibraryEntry libEntry = (ILibraryEntry)entry; - IPath refPath = libEntry.getBaseReference(); - if (refPath != null && !refPath.isEmpty()) { - IPath libraryPath = libEntry.getLibraryPath(); - if (refPath.isAbsolute()) { - IResource res = cproject.getCModel().getWorkspace().getRoot().findMember(refPath); - if (res != null && res.getType() == IResource.PROJECT) { - IProject project = (IProject)res; - if (CoreModel.hasCNature(project) || CoreModel.hasCCNature(project)) { - ICProject refCProject = CoreModel.getDefault().create(project); - if (refCProject != null) { - IPathEntry[] entries = getResolvedPathEntries(refCProject); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) { - ILibraryEntry refEntry = (ILibraryEntry)entries[i]; - if (refEntry.getLibraryPath().equals(libraryPath)) { - IPath newBasePath = refEntry.getBasePath(); - // If the libraryPath is relative give a new basepath if none - if (!newBasePath.isAbsolute() && !libraryPath.isAbsolute()) { - IResource refRes; - if (!newBasePath.isEmpty()) { - refRes = cproject.getCModel().getWorkspace().getRoot().findMember(newBasePath); - } else { - IPath refResPath = refEntry.getPath(); - refRes = cproject.getCModel().getWorkspace().getRoot().findMember(refResPath); - } - if (refRes != null) { - if (refRes.getType() == IResource.FILE) { - refRes = refRes.getParent(); - } - newBasePath = refRes.getLocation().append(newBasePath); - } - } - - return CoreModel.newLibraryEntry(entry.getPath(), newBasePath, - refEntry.getLibraryPath(), refEntry.getSourceAttachmentPath(), - refEntry.getSourceAttachmentRootPath(), - refEntry.getSourceAttachmentPrefixMapping(), false); - } - } - } - } - } - } - } else { // Container ref - IPathEntryContainer container = getPathEntryContainer(refPath, cproject); - if (container != null) { - IPathEntry[] entries = container.getPathEntries(); - for (int i = 0; i < entries.length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_LIBRARY) { - ILibraryEntry refEntry = (ILibraryEntry)entries[i]; - if (refEntry.getPath().equals(libraryPath)) { - return CoreModel.newLibraryEntry(entry.getPath(), refEntry.getBasePath(), - refEntry.getLibraryPath(), refEntry.getSourceAttachmentPath(), - refEntry.getSourceAttachmentRootPath(), - refEntry.getSourceAttachmentPrefixMapping(), false); - } - } - } - } - } - } - break; - } - - } - return entry; - } - - public void setRawPathEntries(ICProject cproject, IPathEntry[] newEntries, IProgressMonitor monitor) throws CModelException { - try { - IPathEntry[] oldResolvedEntries = null; - ArrayList listEntries = (ArrayList)resolvedMap.get(cproject); - if (listEntries != null) { - oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); - } - SetPathEntriesOperation op = new SetPathEntriesOperation(cproject, oldResolvedEntries, newEntries); - CModelManager.getDefault().runOperation(op, monitor); - } catch (CoreException e) { - throw new CModelException(e); - } - } - - public IPathEntry[] getRawPathEntries(ICProject cproject) throws CModelException { - IProject project = cproject.getProject(); - // Check if the Project is accesible. - if (!(CoreModel.hasCNature(project) || CoreModel.hasCCNature(project))) { - throw new CModelException(new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST)); - } - IPathEntry[] pathEntries; - try { - IPathEntryStore store = getPathEntryStore(project, true); - pathEntries = store.getRawPathEntries(); - } catch (CoreException e) { - throw new CModelException(e); - } - - // Checks/hacks for backward compatibility .. - // if no output is specified we return the project - // if no source is specified we return the project - boolean foundSource = false; - boolean foundOutput = false; - for (int i = 0; i < pathEntries.length; i++) { - IPathEntry rawEntry = pathEntries[i]; - if (rawEntry.getEntryKind() == IPathEntry.CDT_SOURCE) { - foundSource = true; - } - if (rawEntry.getEntryKind() == IPathEntry.CDT_OUTPUT) { - foundOutput = true; - } - } - - if (!foundSource) { - IPathEntry[] newEntries = new IPathEntry[pathEntries.length + 1]; - System.arraycopy(pathEntries, 0, newEntries, 0, pathEntries.length); - newEntries[pathEntries.length] = CoreModel.newSourceEntry(cproject.getPath()); - pathEntries = newEntries; - } - if (!foundOutput) { - IPathEntry[] newEntries = new IPathEntry[pathEntries.length + 1]; - System.arraycopy(pathEntries, 0, newEntries, 0, pathEntries.length); - newEntries[pathEntries.length] = CoreModel.newOutputEntry(cproject.getPath()); - pathEntries = newEntries; - } - return pathEntries; - } - - public void setPathEntryContainer(ICProject[] affectedProjects, IPathEntryContainer newContainer, IProgressMonitor monitor) - throws CModelException { - if (monitor != null && monitor.isCanceled()) { - return; - } - IPath containerPath = (newContainer == null) ? new Path("") : newContainer.getPath(); //$NON-NLS-1$ - final int projectLength = affectedProjects.length; - final ICProject[] modifiedProjects = new ICProject[projectLength]; - System.arraycopy(affectedProjects, 0, modifiedProjects, 0, projectLength); - final IPathEntry[][] oldResolvedEntries = new IPathEntry[projectLength][]; - // filter out unmodified project containers - int remaining = 0; - for (int i = 0; i < projectLength; i++) { - if (monitor != null && monitor.isCanceled()) { - return; - } - ICProject affectedProject = affectedProjects[i]; - boolean found = false; - IPathEntry[] rawPath = getRawPathEntries(affectedProject); - for (int j = 0, cpLength = rawPath.length; j < cpLength; j++) { - IPathEntry entry = rawPath[j]; - if (entry.getEntryKind() == IPathEntry.CDT_CONTAINER) { - IContainerEntry cont = (IContainerEntry) entry; - if (cont.getPath().equals(containerPath)) { - found = true; - break; - } - } - } - if (!found) { - // filter out this project - does not reference the container path - modifiedProjects[i] = null; - // Still add it to the cache - containerPut(affectedProject, containerPath, newContainer); - continue; - } - IPathEntryContainer oldContainer = containerGet(affectedProject, containerPath); - if (oldContainer != null && newContainer != null && oldContainer.equals(newContainer)) { - modifiedProjects[i] = null; // filter out this project - - // container did not change - continue; - } - remaining++; - ArrayList listEntries = (ArrayList) resolvedMap.remove(affectedProject); - if (listEntries != null) { - oldResolvedEntries[i] = (IPathEntry[]) listEntries.toArray(NO_PATHENTRIES); - } else { - oldResolvedEntries[i] = null; - } - containerPut(affectedProject, containerPath, newContainer); - } - // Nothing change. - if (remaining == 0) { - return; - } - // trigger model refresh - try { - //final boolean canChangeResources = !ResourcesPlugin.getWorkspace().isTreeLocked(); - CoreModel.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor progressMonitor) throws CoreException { - - boolean shouldFire = false; - CModelManager mgr = CModelManager.getDefault(); - for (int i = 0; i < projectLength; i++) { - if (progressMonitor != null && progressMonitor.isCanceled()) { - return; - } - ICProject affectedProject = modifiedProjects[i]; - if (affectedProject == null) { - continue; // was filtered out - } - // Only fire deltas if we had previous cache - if (oldResolvedEntries[i] != null) { - IPathEntry[] newEntries = getResolvedPathEntries(affectedProject); - ICElementDelta[] deltas = generatePathEntryDeltas(affectedProject, oldResolvedEntries[i], newEntries); - if (deltas.length > 0) { - affectedProject.close(); - shouldFire = true; - for (int j = 0; j < deltas.length; j++) { - mgr.registerCModelDelta(deltas[j]); - } - } - } - } - if (shouldFire) { - mgr.fire(ElementChangedEvent.POST_CHANGE); - } - } - }, monitor); - } catch (CoreException e ) { - // - } - } - - public IPathEntryContainer getPathEntryContainer(IContainerEntry entry, ICProject cproject) throws CModelException { - return getPathEntryContainer(entry.getPath(), cproject); - } - - public IPathEntryContainer getPathEntryContainer(final IPath containerPath, final ICProject project) throws CModelException { - // Try the cache. - IPathEntryContainer container = containerGet(project, containerPath); - if (container instanceof PathEntryContainerLock) { - boolean runInitializer = false; - PathEntryContainerLock lock = (PathEntryContainerLock)container; - synchronized(lock) { - if (!lock.isContainerInitialize()) { - runInitializer = true; - lock.setContainerInitialize(runInitializer); - } else { - // Wait for the inialization to finish. - while(containerGet(project, containerPath) instanceof PathEntryContainerLock) { - try { - lock.wait(); - } catch (InterruptedException e) { - //e.printStackTrace(); - } - } - } - } - if (runInitializer) { - // remove the lock. - final PathEntryContainerInitializer initializer = getPathEntryContainerInitializer(containerPath.segment(0)); - if (initializer != null) { - final boolean[] ok = {true}; - // wrap initializer call with Safe runnable in case - // initializer would be - // causing some grief - Platform.run(new ISafeRunnable() { - - public void handleException(Throwable exception) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, - "Exception occurred in container initializer: "+initializer, exception); //$NON-NLS-1$ - CCorePlugin.log(status); - ok[0] = false; - } - - public void run() throws Exception { - initializer.initialize(containerPath, project); - } - }); - if (!ok[0]) { - containerPut(project, containerPath, null); // flush and notify - } - } - } - // retrieve new value - container = containerGet(project, containerPath); - } - return container; - } - - /** - * Helper method finding the container initializer registered for a given container ID or <code>null</code> if none was found - * while iterating over the contributions to extension point to the extension point - * "org.eclipse.cdt.core.PathEntryContainerInitializer". - * <p> - * A containerID is the first segment of any container path, used to identify the registered container initializer. - * <p> - * - * @param containerID - - * a containerID identifying a registered initializer - * @return PathEntryContainerInitializer - the registered container initializer or <code>null</code> if none was found. - */ - public PathEntryContainerInitializer getPathEntryContainerInitializer(String containerID) { - Plugin core = CCorePlugin.getDefault(); - if (core == null) { - return null; - } - IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CONTAINER_INITIALIZER_EXTPOINT_ID); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String initializerID = configElements[j].getAttribute("id"); //$NON-NLS-1$ - if (initializerID != null && initializerID.equals(containerID)) { - try { - Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ - if (execExt instanceof PathEntryContainerInitializer) { - return (PathEntryContainerInitializer) execExt; - } - } catch (CoreException e) { - // executable extension could not be created: - // ignore this initializer if - //e.printStackTrace(); - } - } - } - } - } - return null; - } - - private synchronized IPathEntryContainer containerGet(ICProject cproject, IPath containerPath) { - Map projectContainers = (Map) Containers.get(cproject); - if (projectContainers == null) { - projectContainers = new HashMap(); - Containers.put(cproject, projectContainers); - } - IPathEntryContainer container = (IPathEntryContainer) projectContainers.get(containerPath); - // Initialize the first time with a lock - if (container == null) { - container = new PathEntryContainerLock(); - projectContainers.put(containerPath, container); - } - return container; - } - - private synchronized void containerPut(ICProject cproject, IPath containerPath, IPathEntryContainer container) { - Map projectContainers = (Map) Containers.get(cproject); - if (projectContainers == null) { - projectContainers = new HashMap(); - Containers.put(cproject, projectContainers); - } - IPathEntryContainer oldContainer = (IPathEntryContainer)projectContainers.put(containerPath, container); - if (oldContainer instanceof PathEntryContainerLock) { - synchronized (oldContainer) { - oldContainer.notifyAll(); - } - } - } - - private synchronized void containerRemove(ICProject cproject) { - Containers.remove(cproject); - } - - public String[] projectPrerequisites(IPathEntry[] entries) throws CModelException { - if (entries != null) { - ArrayList prerequisites = new ArrayList(); - for (int i = 0, length = entries.length; i < length; i++) { - if (entries[i].getEntryKind() == IPathEntry.CDT_PROJECT) { - IProjectEntry entry = (IProjectEntry) entries[i]; - prerequisites.add(entry.getPath().lastSegment()); - } - } - int size = prerequisites.size(); - if (size != 0) { - String[] result = new String[size]; - prerequisites.toArray(result); - return result; - } - } - return NO_PREREQUISITES; - } - - public void saveRawPathEntries(ICProject cproject, IPathEntry[] entries) throws CModelException { - // sanity - if (entries == null) { - entries = NO_PATHENTRIES; - } - - ArrayList list = new ArrayList(entries.length); - IPath projectPath = cproject.getPath(); - for (int i = 0; i < entries.length; i++) { - IPathEntry entry; - - int kind = entries[i].getEntryKind(); - - // translate the project prefix. - IPath resourcePath = entries[i].getPath(); - if (resourcePath == null) { - resourcePath = Path.EMPTY; - } - - // Do not do this for container, the path is the ID. - if (kind != IPathEntry.CDT_CONTAINER) { - // translate to project relative from absolute (unless a device path) - if (resourcePath.isAbsolute()) { - if (projectPath != null && projectPath.isPrefixOf(resourcePath)) { - if (resourcePath.segment(0).equals(projectPath.segment(0))) { - resourcePath = resourcePath.removeFirstSegments(1); - resourcePath = resourcePath.makeRelative(); - } else { - resourcePath = resourcePath.makeAbsolute(); - } - } - } - } - - // Specifics to the entries - switch(kind) { - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry include = (IIncludeEntry)entries[i]; - IPath baseRef = include.getBaseReference(); - if (baseRef == null || baseRef.isEmpty()) { - entry = CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(), - include.isSystemInclude(), include.getExclusionPatterns(), include.isExported()); - } else { - entry = CoreModel.newIncludeRefEntry(resourcePath, baseRef, include.getIncludePath()); - } - break; - } - case IPathEntry.CDT_LIBRARY: { - ILibraryEntry library = (ILibraryEntry)entries[i]; - IPath sourcePath = library.getSourceAttachmentPath(); - if (sourcePath != null) { - // translate to project relative from absolute - if (projectPath != null && projectPath.isPrefixOf(sourcePath)) { - if (sourcePath.segment(0).equals(projectPath.segment(0))) { - sourcePath = sourcePath.removeFirstSegments(1); - sourcePath = sourcePath.makeRelative(); - } - } - } - IPath baseRef = library.getBaseReference(); - if (baseRef == null || baseRef.isEmpty()) { - entry = CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), - library.getLibraryPath(), sourcePath, library.getSourceAttachmentRootPath(), - library.getSourceAttachmentPrefixMapping(), library.isExported()); - } else { - entry = CoreModel.newLibraryRefEntry(resourcePath, baseRef, library.getLibraryPath()); - } - break; - } - case IPathEntry.CDT_MACRO: { - IMacroEntry macro = (IMacroEntry)entries[i]; - IPath baseRef = macro.getBaseReference(); - if (baseRef == null || baseRef.isEmpty()) { - entry = CoreModel.newMacroEntry(resourcePath, macro.getMacroName(), macro.getMacroValue(), - macro.getExclusionPatterns(), macro.isExported()); - } else { - entry = CoreModel.newMacroRefEntry(resourcePath, baseRef, macro.getMacroName()); - } - break; - } - case IPathEntry.CDT_OUTPUT: { - IOutputEntry out = (IOutputEntry)entries[i]; - entry = CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns()); - break; - } - case IPathEntry.CDT_PROJECT: { - IProjectEntry projEntry = (IProjectEntry)entries[i]; - entry = CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported()); - break; - } - case IPathEntry.CDT_SOURCE: { - ISourceEntry source = (ISourceEntry)entries[i]; - entry = CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns()); - break; - } - case IPathEntry.CDT_CONTAINER: - entry = CoreModel.newContainerEntry(entries[i].getPath(), entries[i].isExported()); - break; - default: - entry = entries[i]; - } - list.add(entry); - } - try { - IPathEntry[] newRawEntries = new IPathEntry[list.size()]; - list.toArray(newRawEntries); - IProject project = cproject.getProject(); - IPathEntryStore store = getPathEntryStore(project, true); - store.setRawPathEntries(newRawEntries); - } catch (CoreException e) { - throw new CModelException(e); - } - } - - public ICElementDelta[] generatePathEntryDeltas(ICProject cproject, IPathEntry[] oldEntries, IPathEntry[] newEntries) { - ArrayList list = new ArrayList(); - - // if nothing was known before do not generate any deltas. - if (oldEntries == null) { - return new ICElementDelta[0]; - } - // Sanity checks - if (newEntries == null) { - newEntries = NO_PATHENTRIES; - } - - // Check the removed entries. - for (int i = 0; i < oldEntries.length; i++) { - boolean found = false; - for (int j = 0; j < newEntries.length; j++) { - if (oldEntries[i].equals(newEntries[j])) { - found = true; - break; - } - } - // Was it deleted. - if (!found) { - ICElementDelta delta = makePathEntryDelta(cproject, oldEntries[i], true); - if (delta != null) { - list.add(delta); - } - } - } - - // Check the new entries. - for (int i = 0; i < newEntries.length; i++) { - boolean found = false; - for (int j = 0; j < oldEntries.length; j++) { - if (newEntries[i].equals(oldEntries[j])) { - found = true; - break; - } - } - // is it new? - if (!found) { - ICElementDelta delta = makePathEntryDelta(cproject, newEntries[i], false); - if (delta != null) { - list.add(delta); - } - } - } - - // Check for reorder - if (list.size() == 0 && oldEntries.length == newEntries.length) { - for (int i = 0; i < newEntries.length; i++) { - if (!newEntries[i].equals(oldEntries[i])) { - ICElementDelta delta = makePathEntryDelta(cproject, null, false); - if (delta != null) { - list.add(delta); - } - } - } - } - ICElementDelta[] deltas = new ICElementDelta[list.size()]; - list.toArray(deltas); - return deltas; - } - - /** - * return a delta, with the specified change flag. - */ - protected ICElementDelta makePathEntryDelta(ICProject cproject, IPathEntry entry, boolean removed) { - ICElement celement = null; - int flag = ICElementDelta.F_PATHENTRY_REORDER; - if (entry == null) { - celement = cproject; - flag = ICElementDelta.F_PATHENTRY_REORDER; - } else { - int kind = entry.getEntryKind(); - switch (kind) { - case IPathEntry.CDT_SOURCE: { - ISourceEntry source = (ISourceEntry) entry; - IPath path = source.getPath(); - celement = CoreModel.getDefault().create(path); - flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_SOURCE : ICElementDelta.F_ADDED_PATHENTRY_SOURCE; - break; - } - case IPathEntry.CDT_LIBRARY: { - celement = cproject; - flag = (removed) ? ICElementDelta.F_REMOVED_PATHENTRY_LIBRARY : ICElementDelta.F_ADDED_PATHENTRY_LIBRARY; - break; - } - case IPathEntry.CDT_PROJECT: { - //IProjectEntry pentry = (IProjectEntry) entry; - celement = cproject; - flag = ICElementDelta.F_CHANGED_PATHENTRY_PROJECT; - break; - } - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry include = (IIncludeEntry) entry; - IPath path = include.getPath(); - celement = CoreModel.getDefault().create(path); - flag = ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE; - break; - } - case IPathEntry.CDT_MACRO: { - IMacroEntry macro = (IMacroEntry) entry; - IPath path = macro.getPath(); - celement = CoreModel.getDefault().create(path); - flag = ICElementDelta.F_CHANGED_PATHENTRY_MACRO; - break; - } - case IPathEntry.CDT_CONTAINER: { - //IContainerEntry container = (IContainerEntry) entry; - //celement = cproject; - //SHOULD NOT BE HERE Container are resolved. - break; - } - } - } - if (celement == null) { - celement = cproject; - } - CElementDelta delta = new CElementDelta(cproject.getCModel()); - delta.changed(celement, flag); - return delta; - } - - static String[] getRegisteredContainerIDs() { - Plugin core = CCorePlugin.getDefault(); - if (core == null) { - return null; - } - ArrayList containerIDList = new ArrayList(5); - IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CONTAINER_INITIALIZER_EXTPOINT_ID); - if (extension != null) { - IExtension[] extensions = extension.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IConfigurationElement[] configElements = extensions[i].getConfigurationElements(); - for (int j = 0; j < configElements.length; j++) { - String idAttribute = configElements[j].getAttribute("id"); //$NON-NLS-1$ - if (idAttribute != null) - containerIDList.add(idAttribute); - } - } - } - String[] containerIDs = new String[containerIDList.size()]; - containerIDList.toArray(containerIDs); - return containerIDs; - } - - public void setPathEntryStore(IProject project, IPathEntryStore newStore) { - IPathEntryStore oldStore = null; - synchronized(this) { - oldStore = (IPathEntryStore)storeMap.remove(project); - if (newStore != null) { - storeMap.put(project, newStore); - } - } - if (oldStore != null) { - // remove are self before closing - oldStore.removePathEntryStoreListener(this); - oldStore.close(); - } - } - - public synchronized IPathEntryStore getPathEntryStore(IProject project, boolean create) throws CoreException { - IPathEntryStore store = (IPathEntryStore)storeMap.get(project); - if (store == null && create == true) { - store = createPathEntryStore(project); - storeMap.put(project, store); - store.addPathEntryStoreListener(this); - } - return store; - } - - public IPathEntryStore createPathEntryStore(IProject project) throws CoreException { - IPathEntryStore store = null; - if (project != null) { - try { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false); - if (cdesc != null) { - ICExtensionReference[] cextensions = cdesc.get(PATHENTRY_STORE_UNIQ_ID, true); - if (cextensions.length > 0) { - for (int i = 0; i < cextensions.length; i++) { - try { - store = (IPathEntryStore) cextensions[i].createExtension(); - break; - } catch (ClassCastException e) { - // - CCorePlugin.log(e); - } - } - } - } - } catch (CoreException e) { - // ignore since we fall back to a default.... - } - } - if (store == null) { - store = new DefaultPathEntryStore(project); - } - return store; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.resources.IPathEntryStoreListener#pathEntryStoreChanged(org.eclipse.cdt.core.resources.PathEntryChangedEvent) - */ - public void pathEntryStoreChanged(PathEntryStoreChangedEvent event) { - IProject project = event.getProject(); - - // sanity - if (project == null) { - return; - } - - CModelManager manager = CModelManager.getDefault(); - ICProject cproject = manager.create(project); - if (event.hasClosed()) { - setPathEntryStore(project, null); - containerRemove(cproject); - } - if (project.isAccessible()) { - try { - // Clear the old cache entries. - IPathEntry[] oldResolvedEntries = null; - ArrayList listEntries = (ArrayList) resolvedMap.remove(cproject); - if (listEntries != null) { - oldResolvedEntries = (IPathEntry[])listEntries.toArray(NO_PATHENTRIES); - } - IPathEntry[] newResolvedEntries = getResolvedPathEntries(cproject); - ICElementDelta[] deltas = generatePathEntryDeltas(cproject, oldResolvedEntries, newResolvedEntries); - if (deltas.length > 0) { - cproject.close(); - for (int i = 0; i < deltas.length; i++) { - manager.registerCModelDelta(deltas[i]); - } - manager.fire(ElementChangedEvent.POST_CHANGE); - } - } catch (CModelException e) { - CCorePlugin.log(e); - } - } else { - resolvedMap.remove(cproject); - containerRemove(cproject); - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IElementChangedListener#elementChanged(org.eclipse.cdt.core.model.ElementChangedEvent) - */ - public void elementChanged(ElementChangedEvent event) { - try { - processDelta(event.getDelta()); - } catch(CModelException e) { - } - } - - protected void processDelta(ICElementDelta delta) throws CModelException { - int kind= delta.getKind(); - int flags= delta.getFlags(); - ICElement element= delta.getElement(); - - //System.out.println("Processing " + element); - - // handle closing and removing of projects - if (((flags & ICElementDelta.F_CLOSED) != 0) || (kind == ICElementDelta.REMOVED)) { - if (element.getElementType() == ICElement.C_PROJECT) { - ICProject cproject = (ICProject)element; - IProject project = cproject.getProject(); - IPathEntryStore store = null; - try { - store = getPathEntryStore(project, false); - if (store != null) { - store.close(); - } - } catch (CoreException e) { - throw new CModelException(e); - } finally { - if (store == null) { - resolvedMap.remove(cproject); - containerRemove(cproject); - } - } - } - } - ICElementDelta[] affectedChildren= delta.getAffectedChildren(); - for (int i= 0; i < affectedChildren.length; i++) { - processDelta(affectedChildren[i]); - } - } - - protected IPathEntry cloneEntry(IPath rpath, IPathEntry entry) { - - // get the path - IPath entryPath = entry.getPath(); - if (entryPath == null) { - entryPath = Path.EMPTY; - } - IPath resourcePath = (entryPath.isAbsolute()) ? entryPath : rpath.append(entryPath); - - switch(entry.getEntryKind()) { - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry include = (IIncludeEntry)entry; - return CoreModel.newIncludeEntry(resourcePath, include.getBasePath(), include.getIncludePath(), - include.isSystemInclude(), include.getExclusionPatterns(), include.isExported()); - } - case IPathEntry.CDT_LIBRARY: { - ILibraryEntry library = (ILibraryEntry)entry; - return CoreModel.newLibraryEntry(resourcePath, library.getBasePath(), library.getLibraryPath(), - library.getSourceAttachmentPath(), library.getSourceAttachmentRootPath(), - library.getSourceAttachmentPrefixMapping(), library.isExported()); - } - case IPathEntry.CDT_MACRO: { - IMacroEntry macro = (IMacroEntry)entry; - return CoreModel.newMacroEntry(resourcePath, macro.getMacroName(), macro.getMacroValue(), - macro.getExclusionPatterns(), macro.isExported()); - } - case IPathEntry.CDT_OUTPUT: { - IOutputEntry out = (IOutputEntry)entry; - return CoreModel.newOutputEntry(resourcePath, out.getExclusionPatterns()); - } - case IPathEntry.CDT_PROJECT: { - IProjectEntry projEntry = (IProjectEntry)entry; - return CoreModel.newProjectEntry(projEntry.getPath(), projEntry.isExported()); - } - case IPathEntry.CDT_SOURCE: { - ISourceEntry source = (ISourceEntry)entry; - return CoreModel.newSourceEntry(resourcePath, source.getExclusionPatterns()); - } - case IPathEntry.CDT_CONTAINER: - return CoreModel.newContainerEntry(entry.getPath(), entry.isExported()); - } - return entry; - } - - public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry[] entries) { - - // Check duplication. - for (int i = 0; i < entries.length; i++) { - IPathEntry entry = entries[i]; - if (entry == null) { - continue; - } - for (int j = 0; j < entries.length; j++) { - IPathEntry otherEntry = entries[j]; - if (otherEntry == null) { - continue; - } - if (entry != otherEntry && otherEntry.equals(entry)) { - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.DuplicateEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); - } - } - } - - // allow nesting source entries in each other as long as the outer entry excludes the inner one - for (int i = 0; i < entries.length; i++) { - IPathEntry entry = entries[i]; - if (entry == null) { - continue; - } - IPath entryPath = entry.getPath(); - int kind = entry.getEntryKind(); - if (kind == IPathEntry.CDT_SOURCE){ - for (int j = 0; j < entries.length; j++){ - IPathEntry otherEntry = entries[j]; - if (otherEntry == null) { - continue; - } - int otherKind = otherEntry.getEntryKind(); - IPath otherPath = otherEntry.getPath(); - if (entry != otherEntry && (otherKind == IPathEntry.CDT_SOURCE)) { - char[][] exclusionPatterns = ((ISourceEntry)otherEntry).fullExclusionPatternChars(); - if (otherPath.isPrefixOf(entryPath) && !otherPath.equals(entryPath) - && !CoreModelUtil.isExcluded(entryPath.append("*"), exclusionPatterns)) { //$NON-NLS-1$ - - String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0); - if (CoreModelUtil.isExcluded(entryPath, exclusionPatterns)) { - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); - } else { - if (otherKind == IPathEntry.CDT_SOURCE) { - exclusionPattern += '/'; - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); - } else { - StringBuffer errMesg = new StringBuffer(CCorePlugin.getResourceString("CoreModel.PathEntry.NestedEntry")); //$NON-NLS-1$ - errMesg.append(':').append(entry.toString()); - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, errMesg.toString()); //$NON-NLS-1$ - } - } - } - } - } - } - } - - return CModelStatus.VERIFIED_OK; - } - - public ICModelStatus validatePathEntry(ICProject cProject, IPathEntry entry, boolean checkSourceAttachment, boolean recurseInContainers){ - IProject project = cProject.getProject(); - StringBuffer sb = new StringBuffer(); - sb.append(CCorePlugin.getResourceString("CoreModel.PathEntry.InvalidPathEntry")); //$NON-NLS-1$ - sb.append(':').append(entry.toString()); - String entryMesg = sb.toString(); - switch(entry.getEntryKind()) { - case IPathEntry.CDT_INCLUDE: { - IIncludeEntry include = (IIncludeEntry)entry; - IPath path = include.getPath(); - if (!isValidWorkspacePath(project, path)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - IPath includePath = include.getFullIncludePath(); - if (!isValidExternalPath(includePath)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_LIBRARY: { - ILibraryEntry library = (ILibraryEntry)entry; - IPath path = library.getPath(); - if (!isValidWorkspacePath(project, path)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - if (checkSourceAttachment) { - IPath sourceAttach = library.getSourceAttachmentPath(); - if (sourceAttach != null) { - if(!sourceAttach.isAbsolute()) { - if (!isValidWorkspacePath(project, sourceAttach)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); - } - } else if (!isValidExternalPath(sourceAttach)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); - } - } - } - IPath libraryPath = library.getFullLibraryPath(); - if (!isValidExternalPath(libraryPath)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_MACRO: { - IMacroEntry macro = (IMacroEntry)entry; - IPath path = macro.getPath(); - if (!isValidWorkspacePath(project, path)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_OUTPUT: { - IOutputEntry out = (IOutputEntry)entry; - IPath path = out.getPath(); - if (!isValidWorkspacePath(project, path)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_PROJECT: { - IProjectEntry projEntry = (IProjectEntry)entry; - IPath path = projEntry.getPath(); - if (path != null && path.isAbsolute() && !path.isEmpty()) { - IProject reqProject = project.getWorkspace().getRoot().getProject(path.segment(0)); - if (!reqProject.exists() || !(CoreModel.hasCCNature(reqProject) || CoreModel.hasCCNature(reqProject))) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - if (!reqProject.isOpen()){ - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - } else { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_SOURCE: { - ISourceEntry source = (ISourceEntry)entry; - IPath path = source.getPath(); - if (!isValidWorkspacePath(project, path)) { - return new CModelStatus(ICModelStatusConstants.INVALID_PATHENTRY, entryMesg); //$NON-NLS-1$ - } - break; - } - case IPathEntry.CDT_CONTAINER: - if (recurseInContainers) { - try { - IPathEntryContainer cont = getPathEntryContainer((IContainerEntry)entry, cProject); - IPathEntry[] contEntries = cont.getPathEntries(); - for (int i = 0; i < contEntries.length; i++) { - ICModelStatus status = validatePathEntry(cProject, contEntries[i], checkSourceAttachment, false); - if (!status.isOK()) { - return status; - } - } - } catch (CModelException e) { - return new CModelStatus(e); - } - } - break; - } - return CModelStatus.VERIFIED_OK; - } - - private boolean isValidWorkspacePath(IProject project, IPath path) { - if (path == null) { - return false; - } - IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot(); - // We accept empy path as the project - IResource res = null; - if (path.isAbsolute()) { - res = workspaceRoot.findMember(path); - } else { - res = project.findMember(path); - } - return (res != null && res.isAccessible()); - } - - private boolean isValidExternalPath(IPath path) { - if (path != null) { - File file = path.toFile(); - if (file != null) { - return file.exists(); - } - } - return false; - } - - /** - * Record a new marker denoting a classpath problem - */ - void createPathEntryProblemMarker(IProject project, ICModelStatus status) { - - IMarker marker = null; - int severity; - switch (status.getCode()) { - case ICModelStatusConstants.INVALID_PATHENTRY : - severity = IMarker.SEVERITY_WARNING; - break; - - case ICModelStatusConstants.INVALID_PATH: - severity = IMarker.SEVERITY_WARNING; - break; - - default: - severity = IMarker.SEVERITY_ERROR; - break; - } - - try { - marker = project.createMarker(ICModelMarker.PATHENTRY_PROBLEM_MARKER); - marker.setAttributes( - new String[] { - IMarker.MESSAGE, - IMarker.SEVERITY, - IMarker.LOCATION, - ICModelMarker.PATHENTRY_FILE_FORMAT, - }, - new Object[] { - status.getString(), - new Integer(severity), - "pathentry",//$NON-NLS-1$ - "false",//$NON-NLS-1$ - } - ); - } catch (CoreException e) { - // could not create marker: cannot do much - //e.printStackTrace(); - } - } - - /** - * Remove all markers denoting classpath problems - */ - protected void flushPathEntryProblemMarkers(IProject project) { - IWorkspace workspace = project.getWorkspace(); - - try { - if (project.isAccessible()) { - IMarker[] markers = project.findMarkers(ICModelMarker.PATHENTRY_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); - if (markers != null) { - workspace.deleteMarkers(markers); - } - } - } catch (CoreException e) { - // could not flush markers: not much we can do - //e.printStackTrace(); - } - } - - - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java deleted file mode 100644 index cb45b87a9e4..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ProjectEntry.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.IProjectEntry; -import org.eclipse.core.runtime.IPath; - - -public class ProjectEntry extends PathEntry implements IProjectEntry { - - public ProjectEntry(IPath path, boolean isExported) { - super(IProjectEntry.CDT_PROJECT, path, isExported); - } - - public boolean equals(Object obj) { - if (obj instanceof IProjectEntry) { - IProjectEntry otherEntry = (IProjectEntry)obj; - if (!super.equals(otherEntry)) { - return false; - } - if (path == null) { - if (otherEntry.getPath() != null) { - return false; - } - } else { - if (!path.toString().equals(otherEntry.getPath().toString())) { - return false; - } - } - return true; - } - return super.equals(obj); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java deleted file mode 100644 index 418e52ef8c5..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICModelStatus; -import org.eclipse.cdt.core.model.ICModelStatusConstants; - -/** - * Reconcile a working copy and signal the changes through a delta. - */ -public class ReconcileWorkingCopyOperation extends CModelOperation { - - boolean forceProblemDetection; - - public ReconcileWorkingCopyOperation(ICElement workingCopy, boolean forceProblemDetection) { - super(new ICElement[] {workingCopy}); - this.forceProblemDetection = forceProblemDetection; - } - /** - * @exception CModelException if setting the source - * of the original compilation unit fails - */ - protected void executeOperation() throws CModelException { - if (fMonitor != null){ - if (fMonitor.isCanceled()) return; - fMonitor.beginTask("element.reconciling", 10); //$NON-NLS-1$ - } - - WorkingCopy workingCopy = getWorkingCopy(); - boolean wasConsistent = workingCopy.isConsistent(); - CElementDeltaBuilder deltaBuilder = null; - - try { - // create the delta builder (this remembers the current content of the cu) - if (!wasConsistent){ - deltaBuilder = new CElementDeltaBuilder(workingCopy); - - // update the element infos with the content of the working copy - workingCopy.makeConsistent(fMonitor); - deltaBuilder.buildDeltas(); - - // register the deltas - if (deltaBuilder != null){ - if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) { - addReconcileDelta(workingCopy, deltaBuilder.delta); - } - } - - } - - if (fMonitor != null) fMonitor.worked(2); - - // force problem detection? - if structure was consistent - if (forceProblemDetection && wasConsistent){ - if (fMonitor != null && fMonitor.isCanceled()) return; - } - - } finally { - if (fMonitor != null) fMonitor.done(); - } - } - - /** - * Returns the working copy this operation is working on. - */ - protected WorkingCopy getWorkingCopy() { - return (WorkingCopy)getElementToProcess(); - } - /** - * @see CModelOperation#isReadOnly - */ - public boolean isReadOnly() { - return true; - } - - protected ICModelStatus verify() { - ICModelStatus status = super.verify(); - if (!status.isOK()) { - return status; - } - WorkingCopy workingCopy = getWorkingCopy(); - if (workingCopy.useCount == 0) { - return new CModelStatus(ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed - } - return status; - } - - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/RenameResourceElementsOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/RenameResourceElementsOperation.java deleted file mode 100644 index 6c4da177eff..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/RenameResourceElementsOperation.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.CModelException; - -/** - * This operation renames resources (Package fragments and compilation units). - * - * <p>Notes:<ul> - * <li>When a compilation unit is renamed, its main type and the constructors of the - * main type are renamed. - * </ul> - */ -public class RenameResourceElementsOperation extends MoveResourceElementsOperation { - /** - * When executed, this operation will rename the specified elements with the given names in the - * corresponding destinations. - */ - public RenameResourceElementsOperation(ICElement[] elements, ICElement[] destinations, String[] newNames, boolean force) { - //a rename is a move to the same parent with a new name specified - //these elements are from different parents - super(elements, destinations, force); - setRenamings(newNames); - } - - /** - * @see MultiOperation - */ - protected String getMainTaskName() { - return "operation.renameResourceProgress"; //$NON-NLS-1$ - } - - /** - * @see CopyResourceElementsOperation#isRename() - */ - protected boolean isRename() { - return true; - } - - /** - * @see MultiOperation - */ - protected void verify(ICElement element) throws CModelException { - super.verify(element); - verifyRenaming(element); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java deleted file mode 100644 index 53b699750dc..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SetPathEntriesOperation.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IPathEntry; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.CoreException; - -/** - */ -public class SetPathEntriesOperation extends CModelOperation { - - /** - * An empty array of strings indicating that a project doesn't have any prerequesite projects. - */ - static final String[] NO_PREREQUISITES = new String[0]; - - IPathEntry[] oldResolvedEntries; - IPathEntry[] newRawEntries; - ICProject cproject; - - public SetPathEntriesOperation(ICProject project, IPathEntry[] oldResolvedEntries, IPathEntry[] newRawEntries) { - super(project); - this.oldResolvedEntries = oldResolvedEntries; - this.newRawEntries = newRawEntries; - this.cproject = project; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.CModelOperation#executeOperation() - */ - protected void executeOperation() throws CModelException { - // project reference updated - may throw an exception if unable to write .cdtproject file - updateProjectReferencesIfNecessary(); - PathEntryManager mgr = PathEntryManager.getDefault(); - hasModifiedResource = true; - mgr.saveRawPathEntries(cproject, newRawEntries); - done(); - } - - protected void updateProjectReferencesIfNecessary() throws CModelException { - PathEntryManager mgr = PathEntryManager.getDefault(); - String[] oldRequired = mgr.projectPrerequisites(oldResolvedEntries); - String[] newRequired = mgr.projectPrerequisites(newRawEntries); - - try { - IProject projectResource = cproject.getProject(); - IProjectDescription description = projectResource.getDescription(); - - IProject[] projectReferences = description.getReferencedProjects(); - - HashSet oldReferences = new HashSet(projectReferences.length); - for (int i = 0; i < projectReferences.length; i++) { - String projectName = projectReferences[i].getName(); - oldReferences.add(projectName); - } - HashSet newReferences = (HashSet) oldReferences.clone(); - - for (int i = 0; i < oldRequired.length; i++) { - String projectName = oldRequired[i]; - newReferences.remove(projectName); - } - for (int i = 0; i < newRequired.length; i++) { - String projectName = newRequired[i]; - newReferences.add(projectName); - } - - Iterator iter; - int newSize = newReferences.size(); - - checkIdentity : { - if (oldReferences.size() == newSize) { - iter = newReferences.iterator(); - while (iter.hasNext()) { - if (!oldReferences.contains(iter.next())) { - break checkIdentity; - } - } - return; - } - } - String[] requiredProjectNames = new String[newSize]; - int index = 0; - iter = newReferences.iterator(); - while (iter.hasNext()) { - requiredProjectNames[index++] = (String) iter.next(); - } - Arrays.sort(requiredProjectNames); // ensure that if changed, the order is consistent - - IProject[] requiredProjectArray = new IProject[newSize]; - IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot(); - for (int i = 0; i < newSize; i++) { - requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]); - } - - description.setReferencedProjects(requiredProjectArray); - projectResource.setDescription(description, this.fMonitor); - - } catch (CoreException e) { - throw new CModelException(e); - } - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java deleted file mode 100644 index 2128bf72e93..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceEntry.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.core.runtime.IPath; - -public class SourceEntry extends APathEntry implements ISourceEntry { - - /** - * - * @param path - * @param exclusionPatterns - */ - public SourceEntry(IPath sourcePath, IPath[] exclusionPatterns) { - super(ISourceEntry.CDT_SOURCE, null, null, sourcePath, exclusionPatterns, false); - } - - public boolean equals (Object obj) { - if (obj instanceof ISourceEntry) { - ISourceEntry otherEntry = (ISourceEntry)obj; - if (!super.equals(otherEntry)) { - return false; - } - if (path == null) { - if (otherEntry.getPath() != null) { - return false; - } - } else { - if (!path.toString().equals(otherEntry.getPath().toString())) { - return false; - } - } - return true; - } - return super.equals(obj); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java deleted file mode 100644 index bd96ed0d40e..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulation.java +++ /dev/null @@ -1,183 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.Map; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IOpenable; -import org.eclipse.cdt.core.model.ISourceManipulation; -import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Abstract class for C elements which implement ISourceReference. - */ - -public class SourceManipulation extends Parent implements ISourceManipulation, ISourceReference { - - public SourceManipulation(ICElement parent, String name, int type) { - super(parent, name, type); - } - - /** - * @see ISourceManipulation - */ - public void copy(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - if (container == null) { - throw new IllegalArgumentException("operation.nullContainer"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {this}; - ICElement[] containers= new ICElement[] {container}; - ICElement[] siblings= null; - if (sibling != null) { - siblings= new ICElement[] {sibling}; - } - String[] renamings= null; - if (rename != null) { - renamings= new String[] {rename}; - } - getCModel().copy(elements, containers, siblings, renamings, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void delete(boolean force, IProgressMonitor monitor) throws CModelException { - ICElement[] elements = new ICElement[] {this}; - getCModel().delete(elements, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void move(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - if (container == null) { - throw new IllegalArgumentException("operation.nullContainer"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {this}; - ICElement[] containers= new ICElement[] {container}; - ICElement[] siblings= null; - if (sibling != null) { - siblings= new ICElement[] {sibling}; - } - String[] renamings= null; - if (rename != null) { - renamings= new String[] {rename}; - } - getCModel().move(elements, containers, siblings, renamings, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void rename(String name, boolean force, IProgressMonitor monitor) throws CModelException { - if (name == null) { - throw new IllegalArgumentException("element.nullName"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {this}; - ICElement[] dests= new ICElement[] {this.getParent()}; - String[] renamings= new String[] {name}; - getCModel().rename(elements, dests, renamings, force, monitor); - } - - /** - * @see IMember - */ - public ITranslationUnit getTranslationUnit() { - try { - return getSourceManipulationInfo().getTranslationUnit(); - } catch (CModelException e) { - return null; - } - } - - /** - * Elements within compilation units and class files have no - * corresponding resource. - * - * @see ICElement - */ - public IResource getCorrespondingResource() throws CModelException { - return null; - } - - /** - * Returns the first parent of the element that is an instance of - * IOpenable. - */ - public IOpenable getOpenableParent() { - ICElement current = getParent(); - while (current != null){ - if (current instanceof IOpenable){ - return (IOpenable) current; - } - current = current.getParent(); - } - return null; - } - - /** - * @see ISourceReference - */ - public String getSource() throws CModelException { - return getSourceManipulationInfo().getSource(); - } - - /** - * @see ISourceReference - */ - public ISourceRange getSourceRange() throws CModelException { - return getSourceManipulationInfo().getSourceRange(); - } - - /** - * @see ICElement - */ - public IResource getUnderlyingResource() { - return getParent().getUnderlyingResource(); - } - - public IResource getResource() { - return null; - } - - protected CElementInfo createElementInfo () { - return new SourceManipulationInfo(this); - } - - protected SourceManipulationInfo getSourceManipulationInfo() throws CModelException { - return (SourceManipulationInfo)getElementInfo(); - } - - public boolean isIdentical(SourceManipulation other) throws CModelException{ - return (this.equals(other) - && (this.getSourceManipulationInfo().hasSameContentsAs(other.getSourceManipulationInfo()))); - } - - /* - * @see JavaElement#generateInfos - */ - protected void generateInfos(Object info, Map newElements, IProgressMonitor pm) throws CModelException { - Openable openableParent = (Openable)getOpenableParent(); - if (openableParent == null) { - return; - } - - CElementInfo openableParentInfo = (CElementInfo) CModelManager.getDefault().getInfo(openableParent); - if (openableParentInfo == null) { - openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm); - } - newElements.put(this, info); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java deleted file mode 100644 index fd561a58881..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceManipulationInfo.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; - -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.ISourceRange; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Element info for ISourceReference elements. - */ -/* package */ -class SourceManipulationInfo extends CElementInfo { - - int modifiers; - - protected SourceManipulationInfo(CElement element) { - super(element); - setIsStructureKnown(true); - modifiers = 0; - } - - protected ISourceRange getSourceRange() { - return new SourceRange(getElement().getStartPos(), - getElement().getLength(), - getElement().getIdStartPos(), - getElement().getIdLength(), - getElement().getStartLine(), - getElement().getEndLine()); - } - - /** - * @see ISourceReference - */ - public String getSource() throws CModelException { - ITranslationUnit tu = getTranslationUnit(); - if (tu != null) { - try { - IResource res = tu.getResource(); - if (res != null && res instanceof IFile) { - StringBuffer buffer = Util.getContent((IFile)res); - return buffer.substring(getElement().getStartPos(), - getElement().getStartPos() + getElement().getLength()); - } - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } catch (StringIndexOutOfBoundsException bound) { - // This is not good we screwed up the offset some how - throw new CModelException(bound, ICModelStatusConstants.INDEX_OUT_OF_BOUNDS); - } - } - return ""; //$NON-NLS-1$ - } - - /** - * @see IMember - */ - public ITranslationUnit getTranslationUnit() { - ICElement celem = getElement(); - for (; celem != null; celem = celem.getParent()) { - if (celem instanceof ITranslationUnit) - return (ITranslationUnit)celem; - } - return null; - } - - /** - * @see ISourceManipulation - */ - public void copy(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - if (container == null) { - throw new IllegalArgumentException("operation.nullContainer"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {getElement()}; - ICElement[] containers= new ICElement[] {container}; - ICElement[] siblings= null; - if (sibling != null) { - siblings= new ICElement[] {sibling}; - } - String[] renamings= null; - if (rename != null) { - renamings= new String[] {rename}; - } - getElement().getCModel().copy(elements, containers, siblings, renamings, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void delete(boolean force, IProgressMonitor monitor) throws CModelException { - ICElement[] elements = new ICElement[] {getElement()}; - getElement().getCModel().delete(elements, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void move(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - if (container == null) { - throw new IllegalArgumentException("operation.nullContainer"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {getElement()}; - ICElement[] containers= new ICElement[] {container}; - ICElement[] siblings= null; - if (sibling != null) { - siblings= new ICElement[] {sibling}; - } - String[] renamings= null; - if (rename != null) { - renamings= new String[] {rename}; - } - getElement().getCModel().move(elements, containers, siblings, renamings, force, monitor); - } - - /** - * @see ISourceManipulation - */ - public void rename(String name, boolean force, IProgressMonitor monitor) throws CModelException { - if (name == null) { - throw new IllegalArgumentException("element.nullName"); //$NON-NLS-1$ - } - ICElement[] elements= new ICElement[] {getElement()}; - ICElement[] dests= new ICElement[] {getElement().getParent()}; - String[] renamings= new String[] {name}; - getElement().getCModel().rename(elements, dests, renamings, force, monitor); - } - - /** - * return the element modifiers - * @return int - */ - public int getModifiers(){ - return modifiers; - } - - /** - * subclasses should override - */ - public boolean hasSameContentsAs( SourceManipulationInfo otherInfo){ - return (this.element.fType == otherInfo.element.fType); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java deleted file mode 100644 index 5c5c064aea2..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceMapper.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.core.model; - -import java.util.List; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.model.ITranslationUnit; - -/** - */ -public class SourceMapper { - ICProject cproject; - - public SourceMapper(ICProject p) { - cproject = p; - } - - public ITranslationUnit findTranslationUnit(String filename) { - return findTranslationUnit(cproject, filename); - } - - public ITranslationUnit findTranslationUnit(IParent container, String filename) { - try { - List list = container.getChildrenOfType(ICElement.C_UNIT); - for (int i = 0; i < list.size(); i++) { - Object o = list.get(i); - if (o instanceof ITranslationUnit) { - ITranslationUnit tu = (ITranslationUnit)o; - // TODO: What about non case sensitive filesystems. - if (filename.equals(tu.getElementName())) { - return tu; - } - } - } - - // TODO: This to simple, we are not protected against - // loop in the file system symbolic links etc .. - list = container.getChildrenOfType(ICElement.C_CCONTAINER); - for (int i = 0; i < list.size(); i++) { - Object o = list.get(i); - if (o instanceof ICContainer) { - ITranslationUnit tu = findTranslationUnit((ICContainer)o, filename); - if (tu != null) { - return tu; - } - } - } - } catch (CModelException e) { - } - return null; - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRange.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRange.java deleted file mode 100644 index 775f6f3d882..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRange.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ISourceRange; - -/** - * @see ISourceRange - */ -class SourceRange implements ISourceRange { - - protected int startPos, length; - protected int idStartPos, idLength; - protected int startLine, endLine; - - protected SourceRange(int startPos, int length) { - this.startPos = startPos; - this.length = length; - idStartPos = 0; - idLength = 0; - startLine = 0; - endLine = 0; - } - - protected SourceRange(int startPos, int length, int idStartPos, int idLength) { - this.startPos = startPos; - this.length = length; - this.idStartPos = idStartPos; - this.idLength = idLength; - } - - protected SourceRange(int startPos, int length, int idStartPos, int idLength, - int startLine, int endLine) { - this.startPos = startPos; - this.length = length; - this.idStartPos = idStartPos; - this.idLength = idLength; - this.startLine = startLine; - this.endLine = endLine; - } - /** - * @see ISourceRange - */ - public int getLength() { - return length; - } - - /** - * @see ISourceRange - */ - public int getStartPos() { - return startPos; - } - - /** - */ - public int getIdStartPos() { - return idStartPos; - } - - public int getIdLength() { - return idLength; - } - - public int getStartLine() { - return startLine; - } - - public int getEndLine() { - return endLine; - } - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("[offset="); //$NON-NLS-1$ - buffer.append(this.startPos); - buffer.append(", length="); //$NON-NLS-1$ - buffer.append(this.length); - buffer.append("]"); //$NON-NLS-1$ - - buffer.append("[IdOffset="); //$NON-NLS-1$ - buffer.append(this.idStartPos); - buffer.append(", idLength="); //$NON-NLS-1$ - buffer.append(this.idLength); - buffer.append("]"); //$NON-NLS-1$ - return buffer.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java deleted file mode 100644 index ee5da5334e4..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/SourceRoot.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.cdt.internal.core.model; - - -import org.eclipse.cdt.core.model.CoreModelUtil; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ISourceEntry; -import org.eclipse.cdt.core.model.ISourceRoot; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; - -/** - * SourceRoot - */ -public class SourceRoot extends CContainer implements ISourceRoot { - - ISourceEntry sourceEntry; - - /** - * @param parent - * @param res - */ - public SourceRoot(ICElement parent, IResource res, ISourceEntry entry) { - super(parent, res); - sourceEntry = entry; - IPath path = getPath(); - IPath cpath = getParent().getPath(); - if (path.segmentCount() > cpath.segmentCount()) { - IPath p = path.removeFirstSegments(cpath.segmentCount()); - setElementName(p.toString()); - } - } - - public ISourceEntry getSourceEntry() { - return sourceEntry; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceRoot#isOnclasspath(org.eclipse.cdt.core.model.ICElement) - */ - public boolean isOnSourceEntry(ICElement element) { - IPath path = element.getPath(); - return this.isOnSourceEntry(path); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceRoot#isOnSourceEntry(org.eclipse.core.resources.IResource) - */ - public boolean isOnSourceEntry(IResource res) { - IPath path = res.getFullPath(); - return isOnSourceEntry(path); - } - - private boolean isOnSourceEntry(IPath path) { - if (sourceEntry.getPath().isPrefixOf(path) - && !CoreModelUtil.isExcluded(path, sourceEntry.fullExclusionPatternChars())) { - return true; - } - return false; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java deleted file mode 100644 index d08f79cf701..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Structure.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IField; -import org.eclipse.cdt.core.model.IMethodDeclaration; -import org.eclipse.cdt.core.model.IStructure; -import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; - -public class Structure extends SourceManipulation implements IStructure { - - Map superClassesNames = new TreeMap(); - - public Structure(ICElement parent, int kind, String name) { - super(parent, name, kind); - } - - public IField[] getFields() throws CModelException { - List fields = new ArrayList(); - fields.addAll(getChildrenOfType(ICElement.C_FIELD)); - return (IField[]) fields.toArray(new IField[fields.size()]); - } - - public IField getField(String name) { - try { - IField[] fields = getFields(); - for (int i = 0; i<fields.length; i++){ - IField field = fields[i]; - if(field.getElementName().equals(name)){ - return field; - } - } - } catch (CModelException e) { - } - return null; - } - - public IMethodDeclaration[] getMethods() throws CModelException { - List methods = new ArrayList(); - methods.addAll(getChildrenOfType(ICElement.C_METHOD_DECLARATION)); - methods.addAll(getChildrenOfType(ICElement.C_METHOD)); - return (IMethodDeclaration[])methods.toArray(new IMethodDeclaration[methods.size()]); - } - - public IMethodDeclaration getMethod(String name) { - try { - IMethodDeclaration[] methods = getMethods(); - for (int i = 0; i<methods.length; i++){ - IMethodDeclaration method = methods[i]; - if(method.getElementName().equals(name)){ - return method; - } - } - } catch (CModelException e) { - } - return null; - } - - public boolean isUnion() throws CModelException { - return getStructureInfo().isUnion(); - } - - public boolean isClass() throws CModelException { - return getStructureInfo().isClass(); - } - - public boolean isStruct() throws CModelException { - return getStructureInfo().isStruct(); - } - - public boolean isAbstract() throws CModelException { - IMethodDeclaration[] methods = getMethods(); - for(int i=0; i<methods.length; i++){ - IMethodDeclaration method = methods[i]; - if(method.isPureVirtual()) - return true; - } - return false; - } - - public String[] getSuperClassesNames(){ - return (String[])superClassesNames.keySet().toArray(new String[superClassesNames.keySet().size()]); - } - - public ASTAccessVisibility getSuperClassAccess(String name){ - return (ASTAccessVisibility)superClassesNames.get(name); - } - - public String getTypeName() throws CModelException { - return getStructureInfo().getTypeName(); - } - - public void setTypeName(String type) throws CModelException{ - getStructureInfo().setTypeString(type); - } - - public boolean isConst() throws CModelException { - return getStructureInfo().isConst(); - } - - public void setConst(boolean isConst) throws CModelException { - getStructureInfo().setConst(isConst); - } - - public boolean isVolatile() throws CModelException { - return getStructureInfo().isVolatile(); - } - - public void setVolatile(boolean isVolatile) throws CModelException { - getStructureInfo().setVolatile(isVolatile); - } - - public boolean isStatic() throws CModelException { - return getStructureInfo().isStatic(); - } - - public void setStatic(boolean isStatic) throws CModelException { - getStructureInfo().setStatic(isStatic); - } - - public StructureInfo getStructureInfo() throws CModelException{ - return (StructureInfo) getElementInfo(); - } - - public void addSuperClass(String name) { - superClassesNames.put(name, ASTAccessVisibility.PUBLIC); - } - - public void addSuperClass(String name, ASTAccessVisibility access) { - superClassesNames.put(name, access); - } - - protected CElementInfo createElementInfo () { - return new StructureInfo(this); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureInfo.java deleted file mode 100644 index 2e7644e2a5a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureInfo.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -import org.eclipse.cdt.core.model.ICElement; - -public class StructureInfo extends VariableInfo { - - protected StructureInfo (CElement element) { - super(element); - - if (element.getElementType() == ICElement.C_CLASS) - this.setTypeName("class"); //$NON-NLS-1$ - else if (element.getElementType() == ICElement.C_UNION) - this.setTypeName("union"); //$NON-NLS-1$ - else - this.setTypeName("struct"); //$NON-NLS-1$ - } - - public boolean isUnion() { - return element.getElementType() == ICElement.C_UNION; - } - - public boolean isClass() { - return element.getElementType() == ICElement.C_CLASS; - } - - public boolean isStruct() { - return element.getElementType() == ICElement.C_STRUCT; - } - -} - diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java deleted file mode 100644 index a99967b7840..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ITemplate; - -public class StructureTemplate extends Structure implements ITemplate{ - - protected static final String[] fgEmptyList= new String[] {}; - protected String[] templateParameterTypes; - - public StructureTemplate(ICElement parent, int kind, String name) { - super(parent, kind, name); - templateParameterTypes= fgEmptyList; - } - /** - * Returns the parameterTypes. - * @see org.eclipse.cdt.core.model.ITemplate#getParameters() - * @return String[] - */ - public String[] getTemplateParameterTypes() { - return templateParameterTypes; - } - - /** - * Sets the fParameterTypes. - * @param fParameterTypes The fParameterTypes to set - */ - public void setTemplateParameterTypes(String[] templateParameterTypes) { - this.templateParameterTypes = templateParameterTypes; - } - - /** - * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters() - */ - public int getNumberOfTemplateParameters() { - return templateParameterTypes == null ? 0 : templateParameterTypes.length; - } - - /** - * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature() - */ - public String getTemplateSignature() { - StringBuffer sig = new StringBuffer(getElementName()); - if(getNumberOfTemplateParameters() > 0){ - sig.append("<"); //$NON-NLS-1$ - String[] paramTypes = getTemplateParameterTypes(); - int i = 0; - sig.append(paramTypes[i++]); - while (i < paramTypes.length){ - sig.append(", "); //$NON-NLS-1$ - sig.append(paramTypes[i++]); - } - sig.append(">"); //$NON-NLS-1$ - } - else{ - sig.append("<>"); //$NON-NLS-1$ - } - return sig.toString(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java deleted file mode 100644 index 476381c821c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ /dev/null @@ -1,555 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.filetype.ICFileType; -import org.eclipse.cdt.core.filetype.ICFileTypeConstants; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.IBuffer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IInclude; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IUsing; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * @see ITranslationUnit - */ -public class TranslationUnit extends Openable implements ITranslationUnit { - - IPath location = null; - - /** - * If set, this is the problem requestor which will be used to notify problems - * detected during reconciling. - */ - protected IProblemRequestor problemRequestor; - - - SourceManipulationInfo sourceManipulationInfo = null; - - public TranslationUnit(ICElement parent, IFile file) { - super(parent, file, ICElement.C_UNIT); - } - - public TranslationUnit(ICElement parent, IPath path) { - super(parent, path, ICElement.C_UNIT); - } - - public ITranslationUnit getTranslationUnit () { - return this; - } - - public IInclude createInclude(String name, ICElement sibling, IProgressMonitor monitor) - throws CModelException { - return null; - } - - public IUsing createUsing(String name, IProgressMonitor monitor) throws CModelException { - return null; - } - - public ICElement getElementAtLine(int line) throws CModelException { - ICElement[] celements = getChildren(); - for (int i = 0; i < celements.length; i++) { - ISourceRange range = ((ISourceReference)celements[i]).getSourceRange(); - int startLine = range.getStartLine(); - int endLine = range.getEndLine(); - if (line >= startLine && line <= endLine) { - return celements[i]; - } - } - return null; - } - - public ICElement getElementAtOffset(int pos) throws CModelException { - ICElement e= getSourceElementAtOffset(pos); - if (e == this) { - return null; - } - return e; - } - - public ICElement[] getElementsAtOffset(int pos) throws CModelException { - ICElement[] e= getSourceElementsAtOffset(pos); - if (e.length == 1 && e[0] == this) { - return CElement.NO_ELEMENTS; - } - return e; - } - - public ICElement getElement(String name ) { - try { - ICElement[] celements = getChildren(); - for (int i = 0; i < celements.length; i++) { - if (name.equals(celements[i].getElementName())) { - return celements[i]; - } - } - } catch (CModelException e) { - } - return null; - } - - public IInclude getInclude(String name) { - try { - ICElement[] celements = getChildren(); - for (int i = 0; i < celements.length; i++) { - if (celements[i].getElementType() == ICElement.C_INCLUDE) { - if (name.equals(celements[i].getElementName())) { - return (IInclude)celements[i]; - } - } - } - } catch (CModelException e) { - } - return null; - } - - public IInclude[] getIncludes() throws CModelException { - ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); - for (int i = 0; i < celements.length; i++) { - if (celements[i].getElementType() == ICElement.C_INCLUDE) { - aList.add(celements[i]); - } - } - return (IInclude[])aList.toArray(new IInclude[0]); - } - - public IUsing getUsing(String name) { - try { - ICElement[] celements = getChildren(); - for (int i = 0; i < celements.length; i++) { - if (celements[i].getElementType() == ICElement.C_USING) { - if (name.equals(celements[i].getElementName())) { - return (IUsing)celements[i]; - } - } - } - } catch (CModelException e) { - } - return null; - } - - public IUsing[] getUsings() throws CModelException { - ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); - for (int i = 0; i < celements.length; i++) { - if (celements[i].getElementType() == ICElement.C_USING) { - aList.add(celements[i]); - } - } - return (IUsing[])aList.toArray(new IUsing[0]); - } - - public void setLocation(IPath loc) { - location = loc; - } - - public IPath getLocation() { - if (location == null) { - IFile file = getFile(); - if (file != null) { - location = file.getLocation(); - } else { - return getPath(); - } - } - return location; - } - - protected IFile getFile() { - IResource res = getResource(); - if (res instanceof IFile) { - return (IFile)res; - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#copy(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void copy(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - getSourceManipulationInfo().copy(container, sibling, rename, force, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#delete(boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void delete(boolean force, IProgressMonitor monitor) throws CModelException { - getSourceManipulationInfo().delete(force, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#move(org.eclipse.cdt.core.model.ICElement, org.eclipse.cdt.core.model.ICElement, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void move(ICElement container, ICElement sibling, String rename, boolean force, - IProgressMonitor monitor) throws CModelException { - getSourceManipulationInfo().move(container, sibling, rename, force, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceManipulation#rename(java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void rename(String name, boolean force, IProgressMonitor monitor) - throws CModelException { - getSourceManipulationInfo().rename(name, force, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceReference#getSource() - */ - public String getSource() throws CModelException { - return getSourceManipulationInfo().getSource(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ISourceReference#getSourceRange() - */ - public ISourceRange getSourceRange() throws CModelException { - return getSourceManipulationInfo().getSourceRange(); - } - - protected TranslationUnitInfo getTranslationUnitInfo() throws CModelException { - return (TranslationUnitInfo)getElementInfo(); - } - - protected SourceManipulationInfo getSourceManipulationInfo() { - if (sourceManipulationInfo == null) { - sourceManipulationInfo = new SourceManipulationInfo(this); - } - return sourceManipulationInfo; - } - - protected CElementInfo createElementInfo () { - return new TranslationUnitInfo(this); - } - - /** - * Returns true if this handle represents the same Java element - * as the given handle. - * - * <p>Compilation units must also check working copy state; - * - * @see Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (!(o instanceof ITranslationUnit)) return false; - return super.equals(o) && !((ITranslationUnit)o).isWorkingCopy(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#findSharedWorkingCopy(org.eclipse.cdt.internal.core.model.IBufferFactory) - */ - public IWorkingCopy findSharedWorkingCopy(IBufferFactory factory) { - - // if factory is null, default factory must be used - if (factory == null) factory = BufferManager.getDefaultBufferManager(); - - // In order to be shared, working copies have to denote the same translation unit - // AND use the same buffer factory. - // Assuming there is a little set of buffer factories, then use a 2 level Map cache. - Map sharedWorkingCopies = CModelManager.getDefault().sharedWorkingCopies; - - Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); - if (perFactoryWorkingCopies == null) return null; - return (WorkingCopy)perFactoryWorkingCopies.get(this); - } - - /** - * To be removed with the new model builder in place - * @param newElements - * @param element - */ - private void getNewElements(Map mapping, CElement element){ - Object info = null; - try { - info = element.getElementInfo(); - } catch (CModelException e) { - } - if(info != null){ - if(element instanceof IParent){ - ICElement[] children = ((CElementInfo)info).getChildren(); - int size = children.length; - for (int i = 0; i < size; ++i) { - CElement child = (CElement) children[i]; - getNewElements(mapping, child); - } - } - } - mapping.put(element, info); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#buildStructure(org.eclipse.cdt.internal.core.model.OpenableInfo, org.eclipse.core.runtime.IProgressMonitor, java.util.Map, org.eclipse.core.resources.IResource) - */ - protected boolean buildStructure(OpenableInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws CModelException { - TranslationUnitInfo unitInfo = (TranslationUnitInfo) info; - - // We reuse the general info cache in the CModelBuilder, We should not do this - // and instead create the info explicitely(see JDT). - // So to get by we need to remove in the LRU all the info of this handle - CModelManager.getDefault().removeChildrenInfo(this); - - // generate structure - this.parse(newElements); - - /////////////////////////////////////////////////////////////// - - if (isWorkingCopy()) { - ITranslationUnit original = ((IWorkingCopy)this).getOriginalElement(); - // might be IResource.NULL_STAMP if original does not exist - IResource r = original.getResource(); - if (r != null && r instanceof IFile) { - unitInfo.fTimestamp = ((IFile) r).getModificationStamp(); - } - } - - return unitInfo.isStructureKnown(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#getContents() - */ - public char[] getContents() { - try { - IBuffer buffer = this.getBuffer(); - return buffer == null ? null : buffer.getCharacters(); - } catch (CModelException e) { - return new char[0]; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory) - */ - public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory) - throws CModelException { - return getSharedWorkingCopy(monitor, factory, null); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory, org.eclipse.cdt.core.model.IProblemRequestor) - */ - public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory, IProblemRequestor requestor) - throws CModelException { - - // if factory is null, default factory must be used - if (factory == null) factory = BufferManager.getDefaultBufferManager(); - - CModelManager manager = CModelManager.getDefault(); - - // In order to be shared, working copies have to denote the same translation unit - // AND use the same buffer factory. - // Assuming there is a little set of buffer factories, then use a 2 level Map cache. - Map sharedWorkingCopies = manager.sharedWorkingCopies; - - Map perFactoryWorkingCopies = (Map) sharedWorkingCopies.get(factory); - if (perFactoryWorkingCopies == null){ - perFactoryWorkingCopies = new HashMap(); - sharedWorkingCopies.put(factory, perFactoryWorkingCopies); - } - WorkingCopy workingCopy = (WorkingCopy)perFactoryWorkingCopies.get(this); - if (workingCopy != null) { - workingCopy.useCount++; - return workingCopy; - - } else { - CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor); - runOperation(op, monitor); - return (IWorkingCopy)op.getResultElements()[0]; - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy() - */ - public IWorkingCopy getWorkingCopy()throws CModelException{ - return this.getWorkingCopy(null, null); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory) - */ - public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory)throws CModelException{ - WorkingCopy workingCopy = new WorkingCopy(getParent(), getFile(), factory); - // open the working copy now to ensure contents are that of the current state of this element - workingCopy.open(monitor); - return workingCopy; - } - - /** - * Returns true if this element may have an associated source buffer. - */ - protected boolean hasBuffer() { - return true; - } - - /* - * @see Openable#openParent - */ - protected void openParent(Object childInfo, Map newElements, IProgressMonitor pm) throws CModelException { - try { - super.openParent(childInfo, newElements, pm); - } catch(CModelException e){ - // allow parent to not exist for working copies defined outside - if (!isWorkingCopy()){ - throw e; - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.IOpenable#isConsistent() - */ - public boolean isConsistent() throws CModelException { - return CModelManager.getDefault().getElementsOutOfSynchWithBuffers().get(this) == null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#isSourceElement() - */ - protected boolean isSourceElement() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isWorkingCopy() - */ - public boolean isWorkingCopy() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.model.Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor) - */ - protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - - // create buffer - translation units only use default buffer factory - BufferManager bufManager = getBufferManager(); - IBuffer buffer = getBufferFactory().createBuffer(this); - if (buffer == null) - return null; - - // set the buffer source - if (buffer.getCharacters() == null){ - IResource file = this.getResource(); - if (file != null && file.getType() == IResource.FILE) { - buffer.setContents(Util.getResourceContentsAsCharArray((IFile)file)); - } - } - - // add buffer to buffer cache - bufManager.addBuffer(buffer); - - // listen to buffer changes - buffer.addBufferChangedListener(this); - - return buffer; - } - - public Map parse() { - Map map = new HashMap(); - try { - getNewElements(map, this); - } catch (Exception e) { - } - return map; - } - - /** - * Parse the buffer contents of this element. - */ - private void parse(Map newElements){ - try { - CModelBuilder modelBuilder = new CModelBuilder(this, newElements); - boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode()); - modelBuilder.parse(quickParseMode); - } catch (Exception e) { - // use the debug log for this exception. - Util.debugLog( "Exception in CModelBuilder", IDebugLogConstants.MODEL); //$NON-NLS-1$ - } - } - - public IProblemRequestor getProblemRequestor() { - return problemRequestor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit() - */ - public boolean isHeaderUnit() { - IProject project = getCProject().getProject(); - return CoreModel.isValidHeaderUnitName(project, getPath().lastSegment()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit() - */ - public boolean isSourceUnit() { - IProject project = getCProject().getProject(); - return CoreModel.isValidSourceUnitName(project, getPath().lastSegment()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isCLanguage() - */ - public boolean isCLanguage() { - IProject project = getCProject().getProject(); - ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment()); - String lid = type.getLanguage().getId(); - return lid != null && lid.equals(ICFileTypeConstants.LANG_C); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isCXXLanguage() - */ - public boolean isCXXLanguage() { - IProject project = getCProject().getProject(); - ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment()); - String lid = type.getLanguage().getId(); - return lid != null && lid.equals(ICFileTypeConstants.LANG_CXX); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITranslationUnit#isASMLanguage() - */ - public boolean isASMLanguage() { - IProject project = getCProject().getProject(); - ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment()); - String lid = type.getLanguage().getId(); - return lid != null && lid.equals(ICFileTypeConstants.LANG_ASM); - } - - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - IResource res = getResource(); - if (res != null) - return res.exists(); - return super.exists(); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitInfo.java deleted file mode 100644 index a4d7024963f..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ISourceRange; -import org.eclipse.core.runtime.IPath; - -/** - * The Element Info of a Translation Unit. - */ -class TranslationUnitInfo extends OpenableInfo { - - /** - * Timestamp of original resource at the time this element - * was opened or last updated. - */ - protected long fTimestamp; - - protected TranslationUnitInfo (CElement element) { - super(element); - } - - /* Overide the SourceManipulation for the range. */ - protected ISourceRange getSourceRange() { - IPath location = ((TranslationUnit)getElement()).getLocation(); - return new SourceRange(0, (int)location.toFile().length()); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java deleted file mode 100644 index cb4684baa87..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TypeDef.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ITypeDef; - -public class TypeDef extends SourceManipulation implements ITypeDef{ - - String typeName= ""; //$NON-NLS-1$ - public TypeDef(ICElement parent, String name) { - super(parent, name, CElement.C_TYPEDEF); - } - /** - * Returns the typeName. - * @return String - */ - public String getTypeName() { - return typeName; - } - - /** - * Sets the typeName. - * @param typeName The typeName to set - */ - public void setTypeName(String typeName) { - this.typeName = typeName; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java deleted file mode 100644 index a7add0cad3c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Using.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IUsing; - -public class Using extends SourceManipulation implements IUsing{ - - public Using(ICElement parent, String name) { - super(parent, name, CElement.C_USING); - } - - protected CElementInfo createElementInfo () { - return new SourceManipulationInfo(this); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java deleted file mode 100644 index c51be2c15bf..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ /dev/null @@ -1,284 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved. - */ -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.text.MessageFormat; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ICLogConstants; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.internal.core.model.IDebugLogConstants.DebugLogConstant; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -public class Util implements ICLogConstants { - public static boolean VERBOSE_PARSER = false; - public static boolean VERBOSE_SCANNER = false; - public static boolean VERBOSE_MODEL = false; - - private Util() { - } - - public static StringBuffer getContent(IFile file) throws IOException { - InputStream stream = null; - try { - stream = new BufferedInputStream(file.getContents(true)); - } catch (CoreException e) { - throw new IOException(e.getMessage()); - } - try { - char[] b = getInputStreamAsCharArray(stream, -1, null); - return new StringBuffer(b.length).append(b); - } finally { - try { - if (stream != null) - stream.close(); - } catch (IOException e) { - } - } - } - - /** - * Returns the given input stream's contents as a character array. If a - * length is specified (ie. if length != -1), only length chars are - * returned. Otherwise all chars in the stream are returned. Note this - * doesn't close the stream. - * - * @throws IOException - * if a problem occured reading the stream. - */ - public static char[] getInputStreamAsCharArray(InputStream stream, - int length, String encoding) throws IOException { - InputStreamReader reader = null; - reader = encoding == null - ? new InputStreamReader(stream) - : new InputStreamReader(stream, encoding); - char[] contents; - if (length == -1) { - contents = new char[0]; - int contentsLength = 0; - int charsRead = -1; - do { - int available = stream.available(); - // resize contents if needed - if (contentsLength + available > contents.length) { - System.arraycopy(contents, 0, - contents = new char[contentsLength + available], 0, - contentsLength); - } - // read as many chars as possible - charsRead = reader.read(contents, contentsLength, available); - if (charsRead > 0) { - // remember length of contents - contentsLength += charsRead; - } - } while (charsRead > 0); - // resize contents if necessary - if (contentsLength < contents.length) { - System.arraycopy(contents, 0, - contents = new char[contentsLength], 0, contentsLength); - } - } else { - contents = new char[length]; - int len = 0; - int readSize = 0; - while ((readSize != -1) && (len != length)) { - // See PR 1FMS89U - // We record first the read size. In this case len is the - // actual read size. - len += readSize; - readSize = reader.read(contents, len, length - len); - } - // See PR 1FMS89U - // Now we need to resize in case the default encoding used more - // than one byte for each - // character - if (len != length) - System.arraycopy(contents, 0, (contents = new char[len]), 0, - len); - } - return contents; - } - - public static void save(StringBuffer buffer, IFile file) - throws CoreException { - byte[] bytes = buffer.toString().getBytes(); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - // use a platform operation to update the resource contents - boolean force = true; - file.setContents(stream, force, true, null); // record history - } - - /** - * Returns the given file's contents as a character array. - */ - public static char[] getResourceContentsAsCharArray(IFile file) - throws CModelException { - return getResourceContentsAsCharArray(file, null); - } - - public static char[] getResourceContentsAsCharArray(IFile file, - String encoding) throws CModelException { - InputStream stream = null; - try { - stream = new BufferedInputStream(file.getContents(true)); - } catch (CoreException e) { - throw new CModelException(e, - ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST); - } - try { - return Util.getInputStreamAsCharArray(stream, -1, encoding); - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } finally { - try { - stream.close(); - } catch (IOException e) { - } - } - } - - /* - * Add a log entry - */ - public static void log(Throwable e, String message, LogConst logType) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, message,e); - Util.log(status, logType); - } - - public static void log(IStatus status, LogConst logType) { - if (logType.equals(ICLogConstants.PDE)) { - CCorePlugin.getDefault().getLog().log(status); - } else if (logType.equals(ICLogConstants.CDT)) { - CCorePlugin.getDefault().cdtLog.log(status); - } - } - - public static void log(String message, LogConst logType) { - IStatus status = new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, IStatus.INFO, message, null); - Util.log(status, logType); - } - - public static void debugLog(String message, DebugLogConstant client) { - Util.debugLog(message, client, true); - } - - public static void debugLog(String message, DebugLogConstant client, - boolean addTimeStamp) { - if (CCorePlugin.getDefault() == null) - return; - if (CCorePlugin.getDefault().isDebugging() && isActive(client)) { - // Time stamp - if (addTimeStamp) - message = MessageFormat.format("[{0}] {1}", new Object[]{ //$NON-NLS-1$ - new Long(System.currentTimeMillis()), message}); //$NON-NLS-1$ - while (message.length() > 100) { - String partial = message.substring(0, 100); - message = message.substring(100); - System.out.println(partial + "\\"); //$NON-NLS-1$ - } - if (message.endsWith("\n")) { //$NON-NLS-1$ - System.err.print(message); - } else { - System.out.println(message); - } - } - } - - /** - * @param client - * @return - */ - public static boolean isActive(DebugLogConstant client) { - if (client.equals(IDebugLogConstants.PARSER)) { - return VERBOSE_PARSER; - } else if (client.equals(IDebugLogConstants.SCANNER)) - return VERBOSE_SCANNER; - else if (client.equals(IDebugLogConstants.MODEL)) { - return VERBOSE_MODEL; - } - return false; - } - - public static void setDebugging(boolean value) { - CCorePlugin.getDefault().setDebugging(value); - } - - /** - * Combines two hash codes to make a new one. - */ - public static int combineHashCodes(int hashCode1, int hashCode2) { - return hashCode1 * 17 + hashCode2; - } - - /** - * Compares two arrays using equals() on the elements. Either or both - * arrays may be null. Returns true if both are null. Returns false if only - * one is null. If both are arrays, returns true iff they have the same - * length and all elements compare true with equals. - */ - public static boolean equalArraysOrNull(Object[] a, Object[] b) { - if (a == b) - return true; - if (a == null || b == null) - return false; - int len = a.length; - if (len != b.length) - return false; - for (int i = 0; i < len; ++i) { - if (a[i] == null) { - if (b[i] != null) - return false; - } else { - if (!a[i].equals(b[i])) - return false; - } - } - return true; - } - - /** - * Compares two arrays using equals() on the elements. Either or both - * arrays may be null. Returns true if both are null. Returns false if only - * one is null. If both are arrays, returns true iff they have the same - * length and all elements are equal. - */ - public static boolean equalArraysOrNull(int[] a, int[] b) { - if (a == b) - return true; - if (a == null || b == null) - return false; - int len = a.length; - if (len != b.length) - return false; - for (int i = 0; i < len; ++i) { - if (a[i] != b[i]) - return false; - } - return true; - } - - /** - * Compares two objects using equals(). Either or both array may be null. - * Returns true if both are null. Returns false if only one is null. - * Otherwise, return the result of comparing with equals(). - */ - public static boolean equalOrNull(Object a, Object b) { - if (a == b) { - return true; - } - if (a == null || b == null) { - return false; - } - return a.equals(b); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java deleted file mode 100644 index 1324cdc8b8c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IVariable; - -public class Variable extends VariableDeclaration implements IVariable { - - public Variable(ICElement parent, String name) { - super(parent, name, CElement.C_VARIABLE); - } - - public Variable(ICElement parent, String name, int kind) { - super(parent, name, kind); - } - - public String getInitializer() { - return ""; //$NON-NLS-1$ - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java deleted file mode 100644 index 924c2cd01b5..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IVariableDeclaration; - -public class VariableDeclaration extends SourceManipulation implements IVariableDeclaration { - - public VariableDeclaration(ICElement parent, String name) { - super(parent, name, CElement.C_VARIABLE_DECLARATION); - } - - public VariableDeclaration(ICElement parent, String name, int type) { - super(parent, name, type); - } - - public String getTypeName() throws CModelException { - return getVariableInfo().getTypeName(); - } - - public void setTypeName(String type) throws CModelException { - getVariableInfo().setTypeString(type); - } - - public boolean isConst() throws CModelException { - return getVariableInfo().isConst(); - } - - public void setConst(boolean isConst) throws CModelException { - getVariableInfo().setConst(isConst); - } - - public boolean isVolatile() throws CModelException { - return getVariableInfo().isVolatile(); - } - - public void setVolatile(boolean isVolatile) throws CModelException { - getVariableInfo().setVolatile(isVolatile); - } - - public boolean isStatic() throws CModelException { - return getVariableInfo().isStatic(); - } - - public void setStatic(boolean isStatic) throws CModelException { - getVariableInfo().setStatic(isStatic); - } - - public VariableInfo getVariableInfo() throws CModelException{ - return (VariableInfo) getElementInfo(); - } - - protected CElementInfo createElementInfo () { - return new VariableInfo(this); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableInfo.java deleted file mode 100644 index 21026773e9c..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableInfo.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -class VariableInfo extends SourceManipulationInfo { - - String typeStr = ""; //$NON-NLS-1$ - boolean isConst = false; - boolean isVolatile = false; - boolean isStatic = false; - - protected VariableInfo (CElement element) { - super(element); - } - - protected String getTypeName(){ - return typeStr; - } - - protected void setTypeName(String type){ - typeStr = type; - } - - protected void setTypeString(String type){ - typeStr = type; - } - protected boolean isConst(){ - return isConst; - } - - protected void setConst(boolean isConst){ - this.isConst = isConst; - } - - protected boolean isVolatile(){ - return isVolatile; - } - - protected void setVolatile(boolean isVolatile){ - this.isVolatile = isVolatile; - } - - protected boolean isStatic() { - return isStatic; - } - - protected void setStatic(boolean isStatic) { - this.isStatic = isStatic; - } - - /** - * @see org.eclipse.cdt.internal.core.model.SourceManipulationInfo#hasSameContentsAs(org.eclipse.cdt.internal.core.model.SourceManipulationInfo) - */ - public boolean hasSameContentsAs(SourceManipulationInfo otherInfo) { - return - ( super.hasSameContentsAs(otherInfo) - && ( typeStr.equals(((VariableInfo)otherInfo).getTypeName()) ) - && ( isConst() == ((VariableInfo)otherInfo).isConst() ) - && (isVolatile() == ((VariableInfo)otherInfo).isVolatile() ) - && (isStatic() == ((VariableInfo)otherInfo).isStatic() ) - ); - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java deleted file mode 100644 index f7e0d4b7d0b..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.eclipse.cdt.internal.core.model; -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ITemplate; - -public class VariableTemplate extends Variable implements ITemplate { - - protected static final String[] fgEmptyList= new String[] {}; - protected String[] templateParameterTypes; - - public VariableTemplate(ICElement parent, String name) { - super(parent, name, CElement.C_TEMPLATE_VARIABLE); - templateParameterTypes= fgEmptyList; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters() - */ - public int getNumberOfTemplateParameters() { - return templateParameterTypes == null ? 0 : templateParameterTypes.length; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITemplate#getTemplateParameterTypes() - */ - public String[] getTemplateParameterTypes() { - return templateParameterTypes; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITemplate#setTemplateParameterTypes(java.lang.String[]) - */ - public void setTemplateParameterTypes(String[] templateParameterTypes) { - this.templateParameterTypes = templateParameterTypes; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature() - */ - public String getTemplateSignature() throws CModelException { - StringBuffer sig = new StringBuffer(getElementName()); - if(getNumberOfTemplateParameters() > 0){ - sig.append("<"); //$NON-NLS-1$ - String[] paramTypes = getTemplateParameterTypes(); - int i = 0; - sig.append(paramTypes[i++]); - while (i < paramTypes.length){ - sig.append(", "); //$NON-NLS-1$ - sig.append(paramTypes[i++]); - } - sig.append(">"); //$NON-NLS-1$ - } - else{ - sig.append("<>"); //$NON-NLS-1$ - } - - sig.append(" : "); //$NON-NLS-1$ - sig.append(this.getTypeName()); - - return sig.toString(); - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java deleted file mode 100644 index 69e6ef62b01..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java +++ /dev/null @@ -1,342 +0,0 @@ -package org.eclipse.cdt.internal.core.model; - -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -import java.io.ByteArrayInputStream; -import java.io.IOException; - -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.ICModelStatusConstants; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Implementation of a working copy translation unit. A working copy maintains - * the timestamp of the resource it was created from. - */ -public class WorkingCopy extends TranslationUnit implements IWorkingCopy { - - /** - * If set, this is the factory that will be used to create the buffer. - */ - protected IBufferFactory bufferFactory; - /** - * A counter of the number of time clients have asked for this - * working copy. It is set to 1, if the working - * copy is not managed. When destroyed, this counter is - * set to 0. Once destroyed, this working copy cannot be opened - * and non-handle info can not be accessed. This is - * never true if this translation unit is not a working copy. - */ - protected int useCount = 1; - - /** - * Creates a working copy of this element - */ - public WorkingCopy(ICElement parent, IFile file, IBufferFactory bufferFactory) { - this(parent, file, bufferFactory, null); - } - public WorkingCopy(ICElement parent, IFile file, IBufferFactory bufferFactory, IProblemRequestor requestor) { - super(parent, file); - this.bufferFactory = - bufferFactory == null ? - getBufferManager() : - bufferFactory; - problemRequestor = requestor; - } - - public WorkingCopy(ICElement parent, IPath path, IBufferFactory bufferFactory) { - super(parent, path); - this.bufferFactory = - bufferFactory == null ? - getBufferManager() : - bufferFactory; - } - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#commit(boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void commit(boolean force, IProgressMonitor monitor) - throws CModelException { - ITranslationUnit original = this.getOriginalElement(); - if (original.exists()) { - CommitWorkingCopyOperation op= new CommitWorkingCopyOperation(this, force); - runOperation(op, monitor); - } else { - String contents = this.getSource(); - if (contents == null) return; - try { - IFile originalRes = (IFile)original.getResource(); - String encoding = null; - try { - encoding = originalRes.getCharset(); - } - catch (CoreException ce) { - // use no encoding - } - byte[] bytes = encoding == null - ? contents.getBytes() - : contents.getBytes(encoding); - ByteArrayInputStream stream = new ByteArrayInputStream(bytes); - if (originalRes.exists()) { - originalRes.setContents( - stream, - force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, - null); - } else { - originalRes.create( - stream, - force, - monitor); - } - } catch (IOException e) { - throw new CModelException(e, ICModelStatusConstants.IO_EXCEPTION); - } catch (CoreException e) { - throw new CModelException(e); - } - } - } - - /** - * Returns a new element info for this element. - */ - protected CElementInfo createElementInfo() { - return new WorkingCopyInfo(this); - } - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#destroy() - */ - public void destroy() { - if (--this.useCount > 0) { - return; - } - try { - DestroyWorkingCopyOperation op = new DestroyWorkingCopyOperation(this); - runOperation(op, null); - } catch (CModelException e) { - // do nothing - } - } - - /** - * @see org.eclipse.cdt.core.model.ICElement#exists() - */ - public boolean exists() { - // working copy always exists in the model until it is detroyed - return this.useCount != 0; - } - - /** - * Answers custom buffer factory - */ - public IBufferFactory getBufferFactory(){ - - return this.bufferFactory; - } - - /** - * Working copies must be identical to be equal. - * - * @see Object#equals - */ - public boolean equals(Object o) { - return this == o; - } - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement() - */ - public ITranslationUnit getOriginalElement() { - return new TranslationUnit(getParent(), getFile()); - } - - /** - * @see org.eclipse.cdt.core.model.ITranslationUnit#getSharedWorkingCopy(IProgressMonitor, IBufferFactory) - */ - public IWorkingCopy getSharedWorkingCopy(IProgressMonitor monitor,IBufferFactory factory) - throws CModelException{ - return this; - } - /** - * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy() - */ - public IWorkingCopy getWorkingCopy() { - return this; - } - - /** - * @see IWorkingCopy - */ - public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory){ - return this; - } - - /** - * @see IWorkingCopy - */ - public boolean isBasedOn(IResource resource) { - if (resource.getType() != IResource.FILE) { - return false; - } - if (this.useCount == 0) { - return false; - } - try { - // if resource got deleted, then #getModificationStamp() will answer IResource.NULL_STAMP, which is always different from the cached - // timestamp - return ((TranslationUnitInfo) getElementInfo()).fTimestamp == ((IFile) resource).getModificationStamp(); - } catch (CModelException e) { - return false; - } - } - /** - * @see org.eclipse.cdt.core.model.ITranslationUnit#isWorkingCopy() - */ - public boolean isWorkingCopy() { - return true; - } - - /** - * @see ICFile - * @see IWorkingCopy - * - * @exception CModelException attempting to open a read only element for - * something other than navigation or if this is a working copy being - * opened after it has been destroyed. - */ - public void open(IProgressMonitor monitor) throws CModelException { - if (this.useCount == 0) { // was destroyed - throw newNotPresentException(); - } else { - super.open(monitor); - //if (monitor != null && monitor.isCanceled()) return; - //if (this.problemRequestor != null && this.problemRequestor.isActive()){ - // this.problemRequestor.beginReporting(); - // TranslationUnitProblemFinder.process(this, this.problemRequestor, monitor); - // this.problemRequestor.endReporting(); - //} - } - } - /** - * @see org.eclipse.cdt.internal.core.model.CFile#openBuffer(IProgressMonitor) - */ - protected IBuffer openBuffer(IProgressMonitor pm) throws CModelException { - - if (this.useCount == 0) throw newNotPresentException(); - - // create buffer - working copies may use custom buffer factory - IBuffer buffer = getBufferFactory().createBuffer(this); - if (buffer == null) - return null; - - // set the buffer source if needed - if (buffer.getCharacters() == null){ - ITranslationUnit original= this.getOriginalElement(); - IBuffer originalBuffer = null; - try { - originalBuffer = original.getBuffer(); - } catch (CModelException e) { - // original element does not exist: create an empty working copy - if (!e.getCModelStatus().doesNotExist()) { - throw e; - } - } - if (originalBuffer != null) { - char[] originalContents = originalBuffer.getCharacters(); - if (originalContents != null) { - buffer.setContents((char[])originalContents.clone()); - } - } else { - // initialize buffer - buffer.setContents(new char[0]); - } - } - - // add buffer to buffer cache - this.getBufferManager().addBuffer(buffer); - - // listen to buffer changes - buffer.addBufferChangedListener(this); - - return buffer; - } - - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#reconcile() - */ - public IMarker[] reconcile() throws CModelException { - reconcile(false, null); - return null; - } - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#reconcile(boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void reconcile(boolean forceProblemDetection, IProgressMonitor monitor) throws CModelException { - - if (this.useCount == 0) throw newNotPresentException(); //was destroyed - - ReconcileWorkingCopyOperation op = new ReconcileWorkingCopyOperation(this, forceProblemDetection); - runOperation(op, monitor); - } - - /** - * @see org.eclipse.cdt.core.model.IWorkingCopy#restore() - */ - public void restore() throws CModelException{ - if (this.useCount == 0) throw newNotPresentException(); //was destroyed - - TranslationUnit original = (TranslationUnit) getOriginalElement(); - IBuffer buffer = this.getBuffer(); - if (buffer == null) return; - buffer.setContents(original.getContents()); - updateTimeStamp(original); - makeConsistent(null); - } - - /** - * @see org.eclipse.cdt.core.model.ICFile#save(IProgressMonitor, boolean) - */ - public void save(IProgressMonitor pm, boolean force) throws CModelException { - if (isReadOnly()) { - throw new CModelException(new CModelStatus(ICModelStatusConstants.READ_ONLY, this)); - } - // computes fine-grain deltas in case the working copy is being reconciled already (if not it would miss one iteration of deltas). - this.reconcile(); - } - - /** - * @param original - * @throws CModelException - */ - protected void updateTimeStamp(TranslationUnit original) throws CModelException { - long timeStamp = - ((IFile) original.getResource()).getModificationStamp(); - if (timeStamp == IResource.NULL_STAMP) { - throw new CModelException( - new CModelStatus(ICModelStatusConstants.INVALID_RESOURCE)); - } - ((TranslationUnitInfo) getElementInfo()).fTimestamp = timeStamp; - } - -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopyInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopyInfo.java deleted file mode 100644 index a63dff35e2a..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopyInfo.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.eclipse.cdt.internal.core.model; -/********************************************************************** - * Copyright (c) 2002,2003 Rational Software Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * Rational Software - Initial API and implementation -***********************************************************************/ - -/** - * The Element Info of a Working Copy. - */ -public class WorkingCopyInfo extends TranslationUnitInfo { - - public WorkingCopyInfo (CElement element) { - super(element); - } - -}
\ No newline at end of file |