From e0fe72f58c104c6dc38071bcfe8e2c88b4472af2 Mon Sep 17 00:00:00 2001
From: Sebastien Marineau TF>Tb4x694qKvacIfK$)DsTDW&iT5J>Lge
uFElwZXJQhE0?P))qnx3#4A+~NYAMR>Q{@tW_@zx#-}8XO6orX`4AuY)CNi1;
literal 0
HcmV?d00001
diff --git a/core/org.eclipse.cdt.core/icons/full/elcl16/clear_co.gif b/core/org.eclipse.cdt.core/icons/full/elcl16/clear_co.gif
new file mode 100644
index 0000000000000000000000000000000000000000..6faf8d66fef6cedd9433f3730ae8b3aa3be2bdc9
GIT binary patch
literal 122
zcmZ?wbhEHb6krfwSj50^|Nj2}|NrmbzkmMx`3(&X_4V~YE&~ID;!hSv1_m|;9UvR1
zQh
+ * This class provides static methods only; it is not intended to be
+ * instantiated or subclassed by clients.
+ *
+ * Examples results:
+ *
+ * For example, the corresponding resource for an
+ * Note: This does not imply anything about consistency with the
+ * underlying resource/buffer contents.
+ *
+ * Deltas have a different status depending on the kind of change they represent.
+ * The list below summarizes each status (as returned by
+ * Move operations are indicated by other change flags, layered on top
+ * of the change flags described above. If element A is moved to become B,
+ * the delta for the change in A will have status
+ * Note that the move change flags only describe the changes to a single element, they
+ * do not imply anything about the parent or children of the element.
+ */
+public interface ICElementDelta {
+
+ /**
+ * Status constant indicating that the element has been added.
+ */
+ public int ADDED = 1;
+
+ /**
+ * Status constant indicating that the element has been removed.
+ */
+ public int REMOVED = 2;
+
+ /**
+ * Status constant indicating that the element has been changed,
+ * as described by the change flags.
+ */
+ public int CHANGED = 4;
+
+ /**
+ * Change flag indicating that the content of the element has changed.
+ */
+ public int F_CONTENT = 0x0001;
+
+ /**
+ * Change flag indicating that the modifiers of the element have changed.
+ */
+ public int F_MODIFIERS = 0x0002;
+
+ /**
+ * Change flag indicating that there are changes to the children of the element.
+ */
+ public int F_CHILDREN = 0x0008;
+
+ /**
+ * Change flag indicating that the element was moved from another location.
+ * The location of the old element can be retrieved using
+ * Note that resource deltas, like C element deltas, are generally only valid
+ * for the dynamic scope of an event notification. Clients must not hang on to
+ * these objects.
+ *
+ * This interface declares constants only; it is not intended to be implemented
+ * or extended.
+ *
+ * C model status object are distinguished by their plug-in id:
+ *
+ * A C model status may also carry additional information (that is, in
+ * addition to the information defined in
+ * This interface is not intended to be implemented by clients.
+ *
+ * This interface declares constants only; it is not intended to be implemented
+ * or extended.
+ *
+ *
+ */
+
+public interface IBuildPath {
+
+ public String[] getCPPOpts();
+ public String[] getCPPFlags();
+ public void setCPP(IPath p);
+ public void setCPPOpts(String[] s);
+ public void setCPPFlags(String[] s);
+
+ public IPath getCXX();
+ public String[] getCXXOPT();
+ public String[] getCXXFlags();
+ public void setCXX(IPath p);
+ public void setCXXOpts(String[] s);
+ public void setCXXFlags(String[] s);
+
+ public IPath getCC();
+ public String[] getCFLAGS();
+ public String[] getCOpts();
+ public void setCFLAGS(String[] s);
+ public void setCOpts(String[] s);
+ public void setCC(IPath p);
+
+ public IPath getAS();
+ public String[] getASFlags();
+ public String[] getASOpts();
+ public void getAS(IPath p);
+ public void getASOpts(String[] s);
+ public void getASFlags(String[] s);
+
+ public IPath getLD();
+ public String[] getLDOpts();
+ public String[] getLDFlags();
+ public void setLD(IPath p);
+ public void setLDOpts(String[] s);
+ public void setLDFlags(String[] s);
+
+ public IPath getAR();
+ public String[] getARFlags();
+ public String[] getAROpts();
+ public void setAR(IPath p);
+ public void setAROpts(String[] s);
+ public void setARFlags(String[] s);
+
+ public IPath[] getIncVPath();
+ public void setIncVPath(IPath[] p);
+
+ public IPath[] getLibs();
+ public void setLibs(IPath[] p);
+
+ public IPath[] getLibVPath();
+ public void setLibVPath(IPath[] p);
+
+ public IPath[] getSRCVPath();
+ public void setSRCVPath(IPath[] p);
+}
diff --git a/core/org.eclipse.cdt.core/icons/full/clcl16/alphab_sort_co.gif b/core/org.eclipse.cdt.core/icons/full/clcl16/alphab_sort_co.gif
new file mode 100644
index 0000000000000000000000000000000000000000..6d772441d0dbf077f40c69416a5bf27d2901b966
GIT binary patch
literal 224
zcmZ?wbhEHb6krfwIKsd%Kfa!sfoZ;deZ74>BO|lD{d{}-c>DPM_VxSi=kKqdKY#xI
z{S1r@`{&QUzaIpE0t^fc|Ns97lEeVTpDc_F3_=V#AjKd%8CYW%sPv^|dYvlN=>93t
zzr(BeCyQaFf}XH`=iPInol8Yb=B@3p@(?@xlz(B6$dtwGpH)nG_a$_ixeJ-7^f5Z@
mQJs7Fb%z;X&649dbdtyw6qEs4_4s@iN6IB_t>^SOWlBJVIUo
literal 0
HcmV?d00001
diff --git a/core/org.eclipse.cdt.core/icons/full/clcl16/clear_co.gif b/core/org.eclipse.cdt.core/icons/full/clcl16/clear_co.gif
new file mode 100644
index 0000000000000000000000000000000000000000..255832653fde9e9748855347fe7bce013aa0a6c7
GIT binary patch
literal 162
zcmZ?wbhEHb6krfw*v!Ci|Ni{?`uO?t>-X=UfB*je|NsB*2eRhRZ)j)$vKcUd;!hSv
z1_n+B9gqyj36S=IZeE_xkkq`S0=c6S=IZeE_xkkq`S0=cstart
end(exclusive).
+ * @param text
, the String object to search in
+ * @param start
, the starting index of the search range, inclusive
+ * @param end
, the ending index of the search range, exclusive
+ * @return an StringMatcher.Position
object that keeps the starting
+ * (inclusive) and ending positions (exclusive) of the first occurrence of the
+ * pattern in the specified range of the text; return null if not found or subtext
+ * is empty (start==end). A pair of zeros is returned if pattern is empty string
+ * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc"
+ * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned
+ */
+
+ public StringMatcher.Position find(String text, int start, int end) {
+ if (fPattern == null || text == null)
+ throw new IllegalArgumentException();
+
+ int tlen= text.length();
+ if (start < 0)
+ start= 0;
+ if (end > tlen)
+ end= tlen;
+ if (end < 0 || start >= end)
+ return null;
+ if (fLength == 0)
+ return new Position(start, start);
+ if (fIgnoreWildCards) {
+ int x= posIn(text, start, end);
+ if (x < 0)
+ return null;
+ return new Position(x, x + fLength);
+ }
+
+ int segCount= fSegments.length;
+ if (segCount == 0) //pattern contains only '*'(s)
+ return new Position(start, end);
+
+ int curPos= start;
+ int matchStart= -1;
+ for (int i= 0; i < segCount && curPos < end; ++i) {
+ String current= fSegments[i];
+ int nextMatch= regExpPosIn(text, curPos, end, current);
+ if (nextMatch < 0)
+ return null;
+ if (i == 0)
+ matchStart= nextMatch;
+ curPos= nextMatch + current.length();
+ }
+ return new Position(matchStart, curPos);
+ }
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern which may contain * for 0 and many characters and
+ * ? for exactly one character. Also takes as parameter a boolean object
+ * specifying if case should be ignored
+ * @deprecated Use StringMatcher(pattern, ignoreCase, ignoreWildCards).
+ */
+ public StringMatcher(String aPattern, boolean ignoreCase) {
+ this(aPattern, ignoreCase, false);
+ }
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern which may contain * for 0 and many characters and
+ * ? for exactly one character.
+ *
+ * Literal '*' and '?' characters must be escaped in the pattern
+ * e.g., "\*" means literal "*", etc.
+ *
+ * Escaping any other character (including the escape character itself),
+ * just results in that character in the pattern.
+ * e.g., "\a" means "a" and "\\" means "\"
+ *
+ * If invoking the StringMatcher with string literals in Java, don't forget
+ * escape characters are represented by "\\".
+ *
+ * @param aPattern the pattern to match text against
+ * @param ignoreCase if true, case is ignored
+ * @param ignoreWildCards if true, wild cards and their escape sequences are ignored
+ * (everything is taken literally).
+ */
+ public StringMatcher(String aPattern, boolean ignoreCase, boolean ignoreWildCards) {
+ fIgnoreCase= ignoreCase;
+ fIgnoreWildCards= ignoreWildCards;
+ fLength= aPattern.length();
+
+ /* convert case */
+ if (fIgnoreCase) {
+ fPattern= aPattern.toUpperCase();
+ } else {
+ fPattern= aPattern;
+ }
+
+ if (fIgnoreWildCards) {
+ parseNoWildCards();
+ } else {
+ parseWildCards();
+ }
+ }
+ /**
+ * Given the starting (inclusive) and the ending (exclusive) poisitions in the
+ * text
, determine if the given substring matches with aPattern
+ * @return true if the specified portion of the text matches the pattern
+ * @param String text
, a String object that contains the substring to match
+ * @param int start
marks the starting position (inclusive) of the substring
+ * @param int
is case sensitive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int textPosIn(String text, int start, int end, String p) {
+
+ int plen= p.length();
+ int max= end - plen;
+
+ if (!fIgnoreCase) {
+ int i= text.indexOf(p, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i= 0; i <= max; ++i) {
+ if (text.regionMatches(true, i, p, 0, plen))
+ return i;
+ }
+
+ return -1;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CModelException.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CModelException.java
new file mode 100644
index 00000000000..dbe943a1445
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CModelException.java
@@ -0,0 +1,117 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.cdt.internal.core.model.CModelStatus;
+
+/**
+ * A checked exception representing a failure in the C model.
+ * C model exceptions contain a C-specific status object describing the
+ * cause of the exception.
+ *
+ * @see ICModelStatus
+ * @see ICModelStatusConstants
+ */
+public class CModelException extends CoreException {
+ /**
+ * Creates a C model exception that wrappers the given end
, a string that has no wildcard
+ * @param marks the ending index (exclusive) of the substring
+ */
+ public boolean match(String text, int start, int end) {
+ if (null == fPattern || null == text)
+ throw new IllegalArgumentException();
+
+ if (start > end)
+ return false;
+
+ if (fIgnoreWildCards)
+ return fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength);
+ int segCount= fSegments.length;
+ if (segCount == 0) //pattern contains only '*'(s) or empty pattern
+ return true;
+ if (start == end)
+ return fLength == 0;
+ if (fLength == 0)
+ return start == end;
+
+ int tlen= text.length();
+ if (start < 0)
+ start= 0;
+ if (end > tlen)
+ end= tlen;
+
+ int tCurPos= start;
+ int bound= end - fBound;
+ if (bound < 0)
+ return false;
+ int i= 0;
+ String current= fSegments[i];
+ int segLength= current.length();
+
+ /* process first segment */
+ if (!fHasLeadingStar) {
+ if (!regExpRegionMatches(text, start, current, 0, segLength)) {
+ return false;
+ } else {
+ ++i;
+ tCurPos= tCurPos + segLength;
+ }
+ }
+
+ /* process middle segments */
+ for (; i < segCount && tCurPos <= bound; ++i) {
+ current= fSegments[i];
+ int currentMatch;
+ int k= current.indexOf(fSingleWildCard);
+ if (k < 0) {
+ currentMatch= textPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ } else {
+ currentMatch= regExpPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ }
+ tCurPos= currentMatch + current.length();
+ }
+
+ /* process final segment */
+ if (!fHasTrailingStar && tCurPos != end) {
+ int clen= current.length();
+ return regExpRegionMatches(text, end - clen, current, 0, clen);
+ }
+ return i == segCount;
+ }
+ /**
+ * match the given
is case sensitive
+ */
+ protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) {
+ while (plen-- > 0) {
+ char tchar= text.charAt(tStart++);
+ char pchar= p.charAt(pStart++);
+
+ /* process wild cards */
+ if (!fIgnoreWildCards) {
+ /* skip single wild cards */
+ if (pchar == fSingleWildCard) {
+ continue;
+ }
+ }
+ if (pchar == tchar)
+ continue;
+ if (fIgnoreCase) {
+ char tc= Character.toUpperCase(tchar);
+ if (tc == pchar)
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+ /**
+ * @param text
with the pattern
+ * @return true if matched eitherwise false
+ * @param text
, a String object
+ */
+ public boolean match(String text) {
+ return match(text, 0, text.length());
+ }
+ /**
+ * This method parses the given pattern into segments seperated by wildcard '*' characters.
+ * Since wildcards are not being used in this case, the pattern consists of a single segment.
+ */
+ private void parseNoWildCards() {
+ fSegments= new String[1];
+ fSegments[0]= fPattern;
+ fBound= fLength;
+ }
+ /**
+ * This method parses the given pattern into segments seperated by wildcard '*' characters.
+ * @param p, a String object that is a simple regular expression with * and/or ?
+ */
+ private void parseWildCards() {
+ if (fPattern.startsWith("*")) //$NON-NLS-1$
+ fHasLeadingStar= true;
+ if (fPattern.endsWith("*")) { //$NON-NLS-1$
+ /* make sure it's not an escaped wildcard */
+ if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') {
+ fHasTrailingStar= true;
+ }
+ }
+
+ Vector temp= new Vector();
+
+ int pos= 0;
+ StringBuffer buf= new StringBuffer();
+ while (pos < fLength) {
+ char c= fPattern.charAt(pos++);
+ switch (c) {
+ case '\\' :
+ if (pos >= fLength) {
+ buf.append(c);
+ } else {
+ char next= fPattern.charAt(pos++);
+ /* if it's an escape sequence */
+ if (next == '*' || next == '?' || next == '\\') {
+ buf.append(next);
+ } else {
+ /* not an escape sequence, just insert literally */
+ buf.append(c);
+ buf.append(next);
+ }
+ }
+ break;
+ case '*' :
+ if (buf.length() > 0) {
+ /* new segment */
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ buf.setLength(0);
+ }
+ break;
+ case '?' :
+ /* append special character representing single match wildcard */
+ buf.append(fSingleWildCard);
+ break;
+ default :
+ buf.append(c);
+ }
+ }
+
+ /* add last buffer to segment list */
+ if (buf.length() > 0) {
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ }
+
+ fSegments= new String[temp.size()];
+ temp.copyInto(fSegments);
+ }
+ /**
+ * @param text
, a string which contains no wildcard
+ * @param start
, the starting index in the text for search, inclusive
+ * @param end
, the stopping point of search, exclusive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int posIn(String text, int start, int end) { //no wild card in pattern
+ int max= end - fLength;
+
+ if (!fIgnoreCase) {
+ int i= text.indexOf(fPattern, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i= start; i <= max; ++i) {
+ if (text.regionMatches(true, i, fPattern, 0, fLength))
+ return i;
+ }
+
+ return -1;
+ }
+ /**
+ * @param text
, a simple regular expression that may only contain '?'(s)
+ * @param start
, the starting index in the text for search, inclusive
+ * @param end
, the stopping point of search, exclusive
+ * @param p
, a simple regular expression that may contains '?'
+ * @param caseIgnored
, wether the pattern is not casesensitive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int regExpPosIn(String text, int start, int end, String p) {
+ int plen= p.length();
+
+ int max= end - plen;
+ for (int i= start; i <= max; ++i) {
+ if (regExpRegionMatches(text, i, p, 0, plen))
+ return i;
+ }
+ return -1;
+ }
+ /**
+ *
+ * @return boolean
+ * @param text
, a String to match
+ * @param start
, int that indicates the starting index of match, inclusive
+ * @param end
int that indicates the ending index of match, exclusive
+ * @param p
, String, String, a simple regular expression that may contain '?'
+ * @param ignoreCase
, boolean indicating wether code>ptext
, the string to match
+ * @param start
, the starting index in the text for search, inclusive
+ * @param end
, the stopping point of search, exclusive
+ * @param code>pignoreCase
, boolean indicating wether code>pThrowable
.
+ * The exception contains a C-specific status object with severity
+ * IStatus.ERROR
and the given status code.
+ *
+ * @param exception the Throwable
+ * @param code one of the C-specific status codes declared in
+ * ICModelStatusConstants
+ * @return the new C model exception
+ * @see ICModelStatusConstants
+ * @see org.eclipse.core.runtime.IStatus#ERROR
+ */
+ public CModelException(Throwable e, int code) {
+ this(new CModelStatus(code, e));
+ }
+
+ /**
+ * Creates a C model exception for the given CoreException
.
+ * Equivalent to
+ * CModelException(exception,ICModelStatusConstants.CORE_EXCEPTION
.
+ *
+ * @param exception the CoreException
+ * @return the new C model exception
+ */
+ public CModelException(CoreException exception) {
+ this(new CModelStatus(exception));
+ }
+
+ /**
+ * Creates a C model exception for the given C-specific status object.
+ *
+ * @param status the C-specific status object
+ * @return the new C model exception
+ */
+ public CModelException(ICModelStatus status) {
+ super(status);
+ }
+
+ /**
+ * Returns the underlying Throwable
that caused the failure.
+ *
+ * @return the wrappered Throwable
, or null
if the
+ * direct case of the failure was at the C model layer
+ */
+ public Throwable getException() {
+ return getStatus().getException();
+ }
+
+ /**
+ * Returns the C model status object for this exception.
+ * Equivalent to (ICModelStatus) getStatus()
.
+ *
+ * @return a status object
+ */
+ public ICModelStatus getCModelStatus() {
+ return (ICModelStatus) getStatus();
+ }
+
+ /**
+ * Returns whether this exception indicates that a C model element does not
+ * exist. Such exceptions have a status with a code of
+ * ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST
.
+ * This is a convenience method.
+ *
+ * @return true
if this exception indicates that a C model
+ * element does not exist
+ * @see ICModelStatus#doesNotExist
+ * @see ICModelStatusConstants#ELEMENT_DOES_NOT_EXIST
+ */
+ public boolean doesNotExist() {
+ ICModelStatus cModelStatus = getCModelStatus();
+ return cModelStatus != null && cModelStatus.doesNotExist();
+ }
+
+ /**
+ * Returns a printable representation of this exception suitable for debugging
+ * purposes only.
+ */
+ public String toString() {
+ StringBuffer buffer= new StringBuffer();
+ buffer.append("C Model Exception: "); //$NON-NLS-1$
+ if (getException() != null) {
+ if (getException() instanceof CoreException) {
+ CoreException c= (CoreException)getException();
+ buffer.append("Core Exception [code "); //$NON-NLS-1$
+ buffer.append(c.getStatus().getCode());
+ buffer.append("] "); //$NON-NLS-1$
+ buffer.append(c.getStatus().getMessage());
+ } else {
+ buffer.append(getException().toString());
+ }
+ } else {
+ buffer.append(getStatus().toString());
+ }
+ return buffer.toString();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
new file mode 100644
index 00000000000..76a09f62266
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java
@@ -0,0 +1,252 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+//import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.core.model.CModelManager;
+
+// This should be done in the Plugin.
+
+public class CoreModel {
+
+ private static CoreModel cmodel = null;
+ private static CModelManager manager = null;
+
+ /**
+ * Plugin string id.
+ */
+ public final static String PLUGIN_ID = "org.eclipse.cdt.core";
+
+ /**
+ * C nature string name, "cnature".
+ */
+ public final static String C_NATURE_NAME = "cnature";
+ /**
+ * C nature string id, PLUGIN_ID + C_NATURE_NAME
+ */
+ public final static String C_NATURE_ID = PLUGIN_ID + "." + C_NATURE_NAME;
+
+ /**
+ * C++ nature string name, "ccnature"
+ */
+ public final static String CC_NATURE_NAME = "ccnature";
+ /**
+ * C++ nature string id, PLUGIN_ID + CC_NATURE_NAME
+ */
+ public final static String CC_NATURE_ID = PLUGIN_ID + "." + CC_NATURE_NAME;
+
+ /**
+ * Returns the plugin id.
+ */
+ public static String getPluginId() {
+ return PLUGIN_ID;
+ }
+
+ /**
+ * Returns the C nature Name.
+ */
+ public static String getCNatureName () {
+ return C_NATURE_NAME;
+ }
+
+ /**
+ * Returns the C++ nature name.
+ */
+ public static String getCCNatureName () {
+ return CC_NATURE_NAME;
+ }
+
+ /**
+ * Returns the C nature Id.
+ */
+ public static String getCNatureId () {
+ return C_NATURE_ID;
+ }
+
+ /**
+ * Returns the C++ nature Id.
+ */
+ public static String getCCNatureId () {
+ return CC_NATURE_ID;
+ }
+
+ /**
+ * Creates an ICElement form and IPath.
+ * Returns null if not found.
+ */
+ public ICElement create(IPath path) {
+ return manager.create(path);
+ }
+
+ /**
+ * Creates an ICElement form and IFile.
+ * Returns null if not found.
+ */
+ public ICElement create(IFile file) {
+ return manager.create(file);
+ }
+
+ /**
+ * Creates an ICElement form and IFolder.
+ * Returns null if not found.
+ */
+ public ICElement create(IFolder folder) {
+ return manager.create(folder);
+ }
+
+ /**
+ * Creates an ICElement form and IProject.
+ * Returns null if not found.
+ */
+ public ICElement create(IProject project) {
+ return manager.create(project);
+ }
+
+ /**
+ * Creates an ICElement form and IWorkspaceRoot.
+ * Returns null if not found.
+ */
+ public ICElement create(IWorkspaceRoot root) {
+ return manager.create(root);
+ }
+
+ /**
+ * Creates an ICElement form and IResource.
+ * Returns null if not found.
+ */
+ public ICElement create(IResource resource) {
+ return manager.create(resource);
+ }
+
+ /**
+ * Returns the default ICRoot.
+ */
+ public ICElement getCRoot() {
+ return manager.getCRoot();
+ }
+
+ /**
+ * Return true if IFile is a shared library, i.e. libxx.so
+ */
+ public static boolean isSharedLib(IFile file) {
+ return manager.isSharedLib(file);
+ }
+
+ /**
+ * Return true if IFile is a an object(ELF), i.e. *.o
+ */
+ public static boolean isObject(IFile file) {
+ return manager.isObject(file);
+ }
+
+ /**
+ * Return true if IFile is an ELF executable
+ */
+ public static boolean isExecutable(IFile file) {
+ return manager.isExecutable(file);
+ }
+
+ /**
+ * Return true if IFile is an ELF.
+ */
+ public static boolean isBinary(IFile file) {
+ return manager.isBinary(file);
+ }
+
+ /**
+ * Return true if IFile is an Achive, *.a
+ */
+ public static boolean isArchive(IFile file) {
+ return manager.isArchive(file);
+ }
+
+ /**
+ * Return true if IFile is a TranslationUnit.
+ */
+ public static boolean isTranslationUnit(IFile file) {
+ return manager.isTranslationUnit(file);
+ }
+
+ /**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidTranslationUnitName(String name){
+ return manager.isValidTranslationUnitName(name);
+ }
+
+ /**
+ * Return true if project has C nature.
+ */
+ public static boolean hasCNature(IProject project){
+ return manager.hasCNature(project);
+ }
+
+ public static boolean hasCCNature(IProject project){
+ return manager.hasCCNature(project);
+ }
+
+ public static void addCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ manager.addCNature(project, monitor);
+ }
+
+ public static void addCCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ manager.addCCNature(project, monitor);
+ }
+
+ public static void removeCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ manager.removeCNature(project, monitor);
+ }
+
+ public static void removeCCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ manager.removeCCNature(project, monitor);
+ }
+
+ public static void addNature(IProject project, String natureId, IProgressMonitor monitor)
+ throws CModelException {
+ manager.addNature(project, natureId, monitor);
+ }
+
+ public static void removeNature(IProject project, String natureId, IProgressMonitor monitor)
+ throws CModelException {
+ manager.removeNature(project, natureId, monitor);
+ }
+
+ /**
+ * Return the singleton.
+ */
+ public static CoreModel getDefault() {
+ if (cmodel == null) {
+ cmodel = new CoreModel();
+ manager = CModelManager.getDefault();
+ }
+ return cmodel;
+ }
+
+ public static void addElementChangedListener(IElementChangedListener listener) {
+ manager.addElementChangedListener(listener);
+ }
+
+ /**
+ * Removes the given element changed listener.
+ * Has no affect if an identical listener is not registered.
+ *
+ * @param listener the listener
+ */
+ public static void removeElementChangedListener(IElementChangedListener listener) {
+ manager.removeElementChangedListener(listener);
+ }
+
+ private CoreModel() {
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ElementChangedEvent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ElementChangedEvent.java
new file mode 100644
index 00000000000..92feb5953fa
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ElementChangedEvent.java
@@ -0,0 +1,33 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import java.util.EventObject;
+
+/**
+ * An element changed event describes a change to the structure or contents
+ * of a tree of C elements. The changes to the elements are described by
+ * the associated delta object carried by this event.
+ *
+ * @see IElementChangedListener
+ * @see ICElementDelta
+ */
+public class ElementChangedEvent extends EventObject {
+ /**
+ * Creates an new element changed event (based on a ICElementDelta
).
+ *
+ * @param delta the C element delta.
+ */
+ public ElementChangedEvent(ICElementDelta delta) {
+ super(delta);
+ }
+ /**
+ * Returns the delta describing the change.
+ *
+ */
+ public ICElementDelta getDelta() {
+ return (ICElementDelta) source;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/Flags.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/Flags.java
new file mode 100644
index 00000000000..30925076c86
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/Flags.java
@@ -0,0 +1,188 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.internal.core.model.IConstants;
+
+/**
+ * Utility class for decoding modifier flags in C elements.
+ * abstract
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the abstract
modifier is included
+ */
+ public static boolean isAbstract(int flags) {
+ return (flags & IConstants.AccAbstract) != 0;
+ }
+
+ /**
+ *
+ * Return whether the give integer include the keyword export
modifier.
+ * @param flags the flags
+ * @return true
if the element is export
+ */
+ public static boolean isExport(int flags) {
+ return (flags & IConstants.AccExport) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the inline
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the inline
modifier is included
+ */
+ public static boolean isInline(int flags) {
+ return (flags & IConstants.AccInline) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the explicit
modifier.
+ *
+ * @param flags the flags
+ * @return true
if explicit
modifier is included
+ */
+ public static boolean isExplicit(int flags) {
+ return (flags & IConstants.AccExplicit) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the private
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the private
modifier is included
+ */
+ public static boolean isPrivate(int flags) {
+ return (flags & IConstants.AccPrivate) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the protected
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the protected
modifier is included
+ */
+ public static boolean isProtected(int flags) {
+ return (flags & IConstants.AccProtected) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the public
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the public
modifier is included
+ */
+ public static boolean isPublic(int flags) {
+ return (flags & IConstants.AccPublic) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the static
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the static
modifier is included
+ */
+ public static boolean isStatic(int flags) {
+ return (flags & IConstants.AccStatic) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the extern
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the extern
modifier is included
+ */
+ public static boolean isExtern(int flags) {
+ return (flags & IConstants.AccExtern) != 0;
+ }
+ /**
+ * Returns whether the given integer includes the mutable
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the mutable
modifier is included
+ */
+ public static boolean isMutable(int flags) {
+ return (flags & IConstants.AccMutable) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the indication that the
+ * element is a register storage specifier.
+ *
+ * @param flags the flags
+ * @return true
if the element is marked register storage specifier
+ */
+ public static boolean isRegister(int flags) {
+ return (flags & IConstants.AccRegister) != 0;
+ }
+ /**
+ * Returns whether the given integer includes the virtual
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the virtual
modifier is included
+ */
+ public static boolean isVirtual(int flags) {
+ return (flags & IConstants.AccVirtual) != 0;
+ }
+
+ /**
+ * Returns whether the given integer includes the volatile
modifier.
+ *
+ * @param flags the flags
+ * @return true
if the volatile
modifier is included
+ */
+ public static boolean isVolatile(int flags) {
+ return (flags & IConstants.AccVolatile) != 0;
+ }
+
+ /**
+ * Returns a standard string describing the given modifier flags.
+ * Only modifier flags are included in the output; the deprecated and
+ * synthetic flags are ignored if set.
+ *
+ *
+ * "public static"
+ * "private"
+ * ICRoot
.
+ */
+ public static final int C_ROOT = 10;
+
+ /**
+ * Constant representing a C project(IProject object).
+ * A C element with this type can be safely cast to ICProject
.
+ */
+ public static final int C_PROJECT = 11;
+
+ /**
+ * Constant representing a folder(ICFolder object).
+ * A C element with this type can be safely cast to ICFolder
.
+ */
+ public static final int C_FOLDER = 12;
+
+ /**
+ * Constant representing a file(ICFile object).
+ * A C element with this type can be safely cast to ICFile
.
+ */
+ public static final int C_FILE = 13;
+
+ /**
+ * Virtual container serving as a place holder.
+ */
+ public static final int C_CONTAINER = 30;
+
+ /**
+ * Constant representing a C/C++ children of a Translation Unit
+ */
+ public static final int C_UNIT = 60;
+
+ /**
+ * Namespace.
+ */
+ public static final int C_NAMESPACE = 61;
+
+ /**
+ * Using.
+ */
+ public static final int C_USING = 62;
+
+ /**
+ * Enumeration.
+ */
+ public static final int C_ENUMERATION = 63;
+
+ /**
+ * Constant representing a class structure.
+ */
+ public static final int C_CLASS = 64;
+
+ /**
+ * Constant representing a struct structure.
+ */
+ public static final int C_STRUCT = 65;
+
+ /**
+ * Constant representing a union structure.
+ */
+ public static final int C_UNION = 66;
+
+ /**
+ * A method definition part of a structure(class, struct, union).
+ */
+ public static final int C_METHOD = 67;
+
+ /**
+ * A method declaration part of a structure(class, struct, union).
+ */
+ public static final int C_METHOD_DECLARATION = 68;
+
+ /**
+ * A Field definition part of a structure(class, struct, union).
+ */
+ public static final int C_FIELD = 69;
+
+ /**
+ * a C/C++ function prototype.
+ */
+ public static final int C_FUNCTION_DECLARATION = 70;
+
+ /**
+ * a C/C++ function.
+ */
+ public static final int C_FUNCTION = 71;
+
+ /**
+ * Preprocessor #include directive.
+ */
+ public static final int C_INCLUDE = 72;
+
+ /**
+ * C++ template class.
+ */
+ public static final int C_TEMPLATE = 73;
+
+ /**
+ * Global variable.
+ */
+ public static final int C_VARIABLE = 74;
+
+ /**
+ * variable Declaration.
+ */
+ public static final int C_VARIABLE_DECLARATION = 75;
+
+ /**
+ * Local Variable.
+ */
+ public static final int C_VARIABLE_LOCAL = 76;
+
+ /**
+ * A preprocessor macro.
+ */
+ public static final int C_MACRO = 77;
+
+ /**
+ * a Typedef.
+ */
+ public static final int C_TYPEDEF = 78;
+
+ /**
+ * Modifier indicating a class constructor
+ */
+ public static final int C_CLASS_CTOR = 0x100;
+
+ /**
+ * Modifier indicating a class destructor
+ */
+ public static final int C_CLASS_DTOR = 0x200;
+
+ /**
+ * Modifier indicating a static storage attribute
+ */
+ public static final int C_STORAGE_STATIC = 0x400;
+
+ /**
+ * Modifier indicating an extern storage attribute
+ */
+ public static final int C_STORAGE_EXTERN = 0x800;
+
+ /**
+ * Modifier indicating a private class
+ */
+ public static final int CPP_PRIVATE = 0x1000;
+
+ /**
+ * Modifier indicating a public class
+ */
+
+ public static final int CPP_PUBLIC = 0x2000;
+
+ /**
+ * Modifier indicating a friend class
+ */
+ public static final int CPP_FRIEND = 0x4000;
+
+ /**
+ * Returns whether this C element exists in the model.
+ *
+ * @return true
if this element exists in the C model
+ */
+ boolean exists();
+
+ /**
+ * Returns the resource that corresponds directly to this element,
+ * or null
if there is no resource that corresponds to
+ * this element.
+ * ATranslationUnit
+ * is its underlying IFile
.
+ *
+ * @return the corresponding resource, or null
if none
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ IResource getCorrespondingResource() throws CModelException;
+
+ /**
+ * Returns the name of this element.
+ *
+ * @return the element name
+ */
+ String getElementName();
+
+ /**
+ * Returns this element's kind encoded as an integer.
+ * This is a handle-only method.
+ *
+ * @return the kind of element; one of the constants declared in
+ * ICElement
+ * @see ICElement
+ */
+ public int getElementType();
+
+ /**
+ * Returns the C model.
+ *
+ * @return the C model
+ */
+ ICRoot getCRoot();
+
+ /**
+ * Returns the C project this element is contained in,
+ * or null
if this element is not contained in any C project
+ *
+ * @return the containing C project, or null
if this element is
+ * not contained in a C project
+ */
+ ICProject getCProject();
+
+ /**
+ * Returns the element directly containing this element,
+ * or null
if this element has no parent.
+ *
+ * @return the parent element, or null
if this element has no parent
+ */
+ ICElement getParent();
+
+ /**
+ * Returns the path to the innermost resource enclosing this element.
+ * If this element is not included in an external archive,
+ * the path returned is the full, absolute path to the underlying resource,
+ * relative to the workbench.
+ * If this element is included in an external archive,
+ * the path returned is the absolute path to the archive in the file system.
+ * This is a handle-only method.
+ *
+ */
+ IPath getPath();
+
+ /**
+ * Returns the underlying resource that contains
+ * this element, or null
if this element is not contained
+ * in a resource.
+ *
+ * @return the underlying resource, or null
if none
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its underlying resource
+ */
+ IResource getUnderlyingResource() throws CModelException;
+
+ /**
+ * Returns whether this C element is read-only. An element is read-only
+ * if its structure cannot be modified by the C model.
+ *
+ * @return true
if this element is read-only
+ */
+ boolean isReadOnly();
+
+ /**
+ * Returns whether the structure of this element is known. For example, for a
+ * translation unit that could not be parsed, false
is returned.
+ * If the structure of an element is unknown, navigations will return reasonable
+ * defaults. For example, getChildren
will return an empty collection.
+ * true
if the structure of this element is known
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ boolean isStructureKnown() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElementDelta.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElementDelta.java
new file mode 100644
index 00000000000..680d2f5698c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElementDelta.java
@@ -0,0 +1,187 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import org.eclipse.core.resources.IResourceDelta;
+
+/**
+ * A C element delta describes changes in C element between two discrete
+ * points in time. Given a delta, clients can access the element that has
+ * changed, and any children that have changed.
+ * getKind
)
+ * and its meaning:
+ *
+ *
+ * ADDED
- The element described by the delta
+ * has been added.
+ * REMOVED
- The element described by the delta
+ * has been removed.
+ * CHANGED
- The element described by the delta
+ * has been changed in some way.
+ * REMOVED
,
+ * with change flag F_MOVED_TO
. In this case,
+ * getMovedToElement
on delta A will return the handle for B.
+ * The delta for B will have status ADDED
, with change flag
+ * F_MOVED_FROM
, and getMovedFromElement
on delta
+ * B will return the handle for A. (Note, the handle to A in this case represents
+ * an element that no longer exists).
+ * getMovedFromElement
.
+ */
+ public int F_MOVED_FROM = 0x0010;
+
+ /**
+ * Change flag indicating that the element was moved to another location.
+ * The location of the new element can be retrieved using getMovedToElement
.
+ */
+ public int F_MOVED_TO = 0x0020;
+
+ /**
+ * Change flag indicating that the underlying IProject
has been
+ * opened.
+ */
+ public int F_OPENED = 0x0200;
+
+ /**
+ * Change flag indicating that the underlying IProject
has been
+ * closed.
+ */
+ public int F_CLOSED = 0x0400;
+
+ //public int F_ADDED_TO_CLASSPATH = 0x0040;
+ //public int F_REMOVED_FROM_CLASSPATH = 0x0080;
+ //public int F_CLASSPATH_REORDER = 0x0100;
+ //public int F_SUPER_TYPES = 0x0800;
+
+ /**
+ * Change flag indicating that a source jar has been attached to a binary jar.
+ */
+ public int F_SOURCEATTACHED = 0x1000;
+
+ /**
+ * Change flag indicating that a source jar has been detached to a binary jar.
+ */
+ public int F_SOURCEDETACHED = 0x2000;
+
+ /**
+ * Change flag indicating that this is a fine-grained delta, i.e. an analysis down
+ * to the members level was done to determine if there were structural changes to
+ * members.
+ */
+ public int F_FINE_GRAINED = 0x4000;
+
+ /**
+ * Returns deltas for the children that have been added.
+ */
+ public ICElementDelta[] getAddedChildren();
+
+ /**
+ * Returns deltas for the affected (added, removed, or changed) children.
+ */
+ public ICElementDelta[] getAffectedChildren();
+
+ /**
+ * Returns deltas for the children which have changed.
+ */
+ public ICElementDelta[] getChangedChildren();
+
+ /**
+ * Returns the element that this delta describes a change to.
+ */
+ public ICElement getElement();
+
+ /**
+ * Returns flags that describe how an element has changed.
+ *
+ * @see ICElementDelta#F_CHILDREN
+ * @see ICElementDelta#F_CONTENT
+ * @see ICElementDelta#F_MODIFIERS
+ * @see ICElementDelta#F_MOVED_FROM
+ * @see ICElementDelta#F_MOVED_TO
+ */
+ public int getFlags();
+
+ /**
+ * Returns the kind of this delta - one of ADDED
, REMOVED
,
+ * or CHANGED
.
+ */
+ public int getKind();
+
+ /**
+ * Returns an element describing this element before it was moved
+ * to its current location, or null
if the
+ * F_MOVED_FROM
change flag is not set.
+ */
+ public ICElement getMovedFromElement();
+
+ /**
+ * Returns an element describing this element in its new location,
+ * or null
if the F_MOVED_TO
change
+ * flag is not set.
+ */
+ public ICElement getMovedToElement();
+
+ /**
+ * Returns deltas for the children which have been removed.
+ */
+ public ICElementDelta[] getRemovedChildren();
+
+ /**
+ * Returns the collection of resource deltas.
+ * null
if none
+ */
+ public IResourceDelta[] getResourceDeltas();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java
new file mode 100644
index 00000000000..ef747add31e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFile.java
@@ -0,0 +1,22 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+
+/**
+ * A C File Resource.
+ */
+public interface ICFile extends IParent, ICElement {
+
+ public boolean isBinary();
+
+ public boolean isArchive();
+
+ public boolean isTranslationUnit();
+
+ public IFile getFile();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java
new file mode 100644
index 00000000000..42eefe863d7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICFolder.java
@@ -0,0 +1,16 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFolder;
+
+/**
+ * A C Folder Resource.
+ */
+public interface ICFolder extends IParent, ICElement {
+
+ public IFolder getFolder();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java
new file mode 100644
index 00000000000..512e88573c9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelMarker.java
@@ -0,0 +1,35 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.internal.CCorePlugin;
+
+
+/**
+ * Markers used by the C model.
+ * "org.eclipse.cdt.core.problem"
).
+ * This can be used to recognize those markers in the workspace that flag problems
+ * detected by the C ompilers.
+ */
+ public static final String C_MODEL_PROBLEM_MARKER = CCorePlugin.PLUGIN_ID + ".problem"; //$NON-NLS-1$
+
+ /**
+ * C model extension to the marker problem markers which may hold a hint on
+ * the variable name that caused the error. Used by the ui to highlight the variable
+ * itself if it can be found.
+ */
+ public static final String C_MODEL_MARKER_VARIABLE = "problem.variable"; //$NON-NLS-1$
+}
+
+
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatus.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatus.java
new file mode 100644
index 00000000000..f62c6d50faa
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatus.java
@@ -0,0 +1,79 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Represents the outcome of an C model operation. Status objects are
+ * used inside CModelException
objects to indicate what went
+ * wrong.
+ * getPlugin
returns "org.eclipse.cdt.core"
.
+ * getCode
returns one of the status codes declared in
+ * ICModelStatusConstants
.
+ * IStatus
):
+ *
+ *
+ * null
if the failure is not
+ * one of DEVICE_PATH
, INVALID_PATH
,
+ * PATH_OUTSIDE_PROJECT
, or RELATIVE_PATH
.
+ *
+ * @return the path that caused the failure, or null
if none
+ * @see ICModelStatusConstants#DEVICE_PATH
+ * @see ICModelStatusConstants#INVALID_PATH
+ * @see ICModelStatusConstants#PATH_OUTSIDE_PROJECT
+ * @see ICModelStatusConstants#RELATIVE_PATH
+ */
+ IPath getPath();
+
+ /**
+ * Returns the string associated with the failure (see specification
+ * of the status code), or null
if no string is related to this
+ * particular status code.
+ *
+ * @return the string culprit, or null
if none
+ * @see ICModelStatusConstants
+ */
+ String getString();
+
+ /**
+ * Returns whether this status indicates that a C model element does not exist.
+ * This convenience method is equivalent to
+ * getCode() == ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST
.
+ *
+ * @return true
if the status code indicates that a C model
+ * element does not exist
+ * @see ICModelStatusConstants#ELEMENT_DOES_NOT_EXIST
+ */
+ boolean doesNotExist();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java
new file mode 100644
index 00000000000..21fe3c6a202
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICModelStatusConstants.java
@@ -0,0 +1,224 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Status codes used with C model status objects.
+ * getException
to retrieve a CoreException
.
+ */
+ public static final int CORE_EXCEPTION = 966;
+
+ /**
+ * Status constant indicating one or more of the elements
+ * supplied are not of a valid type for the operation to
+ * process.
+ * The element(s) can be retrieved using getElements
on the status object.
+ */
+ public static final int INVALID_ELEMENT_TYPES = 967;
+
+ /**
+ * Status constant indicating that no elements were
+ * provided to the operation for processing.
+ */
+ public static final int NO_ELEMENTS_TO_PROCESS = 968;
+
+ /**
+ * Status constant indicating that one or more elements
+ * supplied do not exist.
+ * The element(s) can be retrieved using getElements
on the status object.
+ *
+ * @see ICModelStatus#isDoesNotExist
+ */
+ public static final int ELEMENT_DOES_NOT_EXIST = 969;
+
+ /**
+ * Status constant indicating that a null
path was
+ * supplied to the operation.
+ */
+ public static final int NULL_PATH = 970;
+
+ /**
+ * Status constant indicating that a path outside of the
+ * project was supplied to the operation. The path can be retrieved using
+ * getPath
on the status object.
+ */
+ public static final int PATH_OUTSIDE_PROJECT = 971;
+
+ /**
+ * Status constant indicating that a relative path
+ * was supplied to the operation when an absolute path is
+ * required. The path can be retrieved using getPath
on the
+ * status object.
+ */
+ public static final int RELATIVE_PATH = 972;
+
+ /**
+ * Status constant indicating that a path specifying a device
+ * was supplied to the operation when a path with no device is
+ * required. The path can be retrieved using getPath
on the
+ * status object.
+ */
+ public static final int DEVICE_PATH = 973;
+
+ /**
+ * Status constant indicating that a string
+ * was supplied to the operation that was null
.
+ */
+ public static final int NULL_STRING = 974;
+
+ /**
+ * Status constant indicating that the operation encountered
+ * a read-only element.
+ * The element(s) can be retrieved using getElements
on the status object.
+ */
+ public static final int READ_ONLY = 976;
+
+ /**
+ * Status constant indicating that a naming collision would occur
+ * if the operation proceeded.
+ */
+ public static final int NAME_COLLISION = 977;
+
+ /**
+ * Status constant indicating that a destination provided for a copy/move/rename operation
+ * is invalid.
+ * The destination element can be retrieved using getElements
on the status object.
+ */
+ public static final int INVALID_DESTINATION = 978;
+
+ /**
+ * Status constant indicating that a path provided to an operation
+ * is invalid. The path can be retrieved using getPath
on the
+ * status object.
+ */
+ public static final int INVALID_PATH = 979;
+
+ /**
+ * Status constant indicating the given source position is out of bounds.
+ */
+ public static final int INDEX_OUT_OF_BOUNDS = 980;
+
+ /**
+ * Status constant indicating there is an update conflict
+ * for a working copy. The translation unit on which the
+ * working copy is based has changed since the working copy
+ * was created.
+ */
+ public static final int UPDATE_CONFLICT = 981;
+
+ /**
+ * Status constant indicating that null
was specified
+ * as a name argument.
+ */
+ public static final int NULL_NAME = 982;
+
+ /**
+ * Status constant indicating that a name provided is not syntactically correct.
+ * The name can be retrieved from getString
.
+ */
+ public static final int INVALID_NAME = 983;
+
+ /**
+ * Status constant indicating that the specified contents
+ * are not valid.
+ */
+ public static final int INVALID_CONTENTS = 984;
+
+ /**
+ * Status constant indicating that an java.io.IOException
+ * occurred.
+ */
+ public static final int IO_EXCEPTION = 985;
+
+ /**
+ * Status constant indicating that a DOMException
+ * occurred.
+ */
+ public static final int DOM_EXCEPTION = 986;
+
+ /**
+ * Status constant indicating that a TargetException
+ * occurred.
+ */
+ public static final int TARGET_EXCEPTION = 987;
+
+ /**
+ * Status constant indicating that the C builder
+ * could not be initialized.
+ */
+ public static final int BUILDER_INITIALIZATION_ERROR = 990;
+
+ /**
+ * Status constant indicating that the C builder's last built state
+ * could not be serialized or deserialized.
+ */
+ public static final int BUILDER_SERIALIZATION_ERROR = 991;
+
+ /**
+ * Status constant indicating that an error was encountered while
+ * trying to evaluate a code snippet, or other item.
+ */
+ public static final int EVALUATION_ERROR = 992;
+
+ /**
+ * Status constant indicating that a sibling specified is not valid.
+ */
+ public static final int INVALID_SIBLING = 993;
+
+ /**
+ * Status indicating that a C element could not be created because
+ * the underlying resource is invalid.
+ * @see CCore
+ */
+ public static final int INVALID_RESOURCE = 995;
+
+ /**
+ * Status indicating that a C element could not be created because
+ * the underlying resource is not of an appropriate type.
+ * @see CCore
+ */
+ public static final int INVALID_RESOURCE_TYPE = 996;
+
+ /**
+ * Status indicating that a C element could not be created because
+ * the project owning underlying resource does not have the C nature.
+ * @see CCore
+ */
+ public static final int INVALID_PROJECT = 997;
+
+ //public static final int INVALID_NAMESPACE = 998;
+
+ /**
+ * Status indicating that the corresponding resource has no local contents yet.
+ * This might happen when attempting to use a resource before its contents
+ * has been made locally available.
+ */
+ public static final int NO_LOCAL_CONTENTS = 999;
+
+ ///**
+ //* Status constant indicating that a classpath entry was invalid
+ //*/
+ //public static final int INVALID_CLASSPATH = 964;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java
new file mode 100644
index 00000000000..26648b46920
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICProject.java
@@ -0,0 +1,43 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * A C project represents a view of a project resource in terms of C
+ * elements such as ICFile, ICFolder ....
+ * CCore.create(project)
.
+ *
ICElement
corresponding to the given
+ * path, or null
if no such
+ * ICElement
is found.
+ *
+ * @exception CModelException if the given path is null
+ * or absolute
+ */
+ ICElement findElement(IPath path) throws CModelException;
+
+ /**
+ * Return the ArchiveContainer of this Project.
+ */
+ IArchiveContainer getArchiveContainer();
+
+ /**
+ * Return the BinaryContainer of this Project.
+ */
+ IBinaryContainer getBinaryContainer();
+
+ IProject getProject();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java
new file mode 100644
index 00000000000..2c44ce1c002
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICRoot.java
@@ -0,0 +1,179 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Represent the root C element corresponding to the workspace.
+ * Since there is only one such root element, it is commonly referred to as
+ * the C model element.
+ * The C model element needs to be opened before it can be navigated or manipulated.
+ * The C model element has no parent (it is the root of the C element
+ * hierarchy). Its children are ICProject
s.
+ * + * This interface provides methods for performing copy, move, rename, and + * delete operations on multiple C elements. + *
+ * + * @see CCore#create(org.eclipse.core.resources.IWorkspaceRoot) + */ +public interface ICRoot extends ICElement, IParent { + /** + * Copies the given elements to the specified container(s). + * If one container is specified, all elements are copied to that + * container. If more than one container is specified, the number of + * elements and containers must match, and each element is copied to + * its associated container. + *
+ * Optionally, each copy can positioned before a sibling
+ * element. If null
is specified for a given sibling, the copy
+ * is inserted as the last child of its associated container.
+ *
+ * Optionally, each copy can be renamed. If
+ * null
is specified for the new name, the copy
+ * is not renamed.
+ *
+ * Optionally, any existing child in the destination container with
+ * the same name can be replaced by specifying true
for
+ * force. Otherwise an exception is thrown in the event that a name
+ * collision occurs.
+ *
null
; or null
+ * @param renamings the list of new names any of which may be
+ * null
; or null
+ * @param replace true
if any existing child in a target container
+ * with the target name should be replaced, and false
to throw an
+ * exception in the event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if an element could not be copied. Reasons include:
+ * CoreException
occurred while updating an underlying resource
+ * INVALID_DESTINATION
)
+ * INVALID_SIBLING
)
+ * INVALID_NAME
)
+ * replace
has been specified as false
(NAME_COLLISION
)
+ * READ_ONLY
)
+ * CoreException
occurred while updating an underlying resource
+ * READ_ONLY
)
+ *
+ * Optionally, each element can positioned before a sibling
+ * element. If null
is specified for sibling, the element
+ * is inserted as the last child of its associated container.
+ *
+ * Optionally, each element can be renamed. If
+ * null
is specified for the new name, the element
+ * is not renamed.
+ *
+ * Optionally, any existing child in the destination container with
+ * the same name can be replaced by specifying true
for
+ * force. Otherwise an exception is thrown in the event that a name
+ * collision occurs.
+ *
null
; or null
+ * @param renamings the list of new names any of which may be
+ * null
; or null
+ * @param replace true
if any existing child in a target container
+ * with the target name should be replaced, and false
to throw an
+ * exception in the event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if an element could not be moved. Reasons include:
+ * CoreException
occurred while updating an underlying resource
+ * INVALID_DESTINATION
)
+ * INVALID_SIBLING
)
+ * INVALID_NAME
)
+ * replace
has been specified as false
(NAME_COLLISION
)
+ * READ_ONLY
)
+ * null
+ */
+ void move(ICElement[] elements, ICElement[] containers, ICElement[] siblings, String[] renamings, boolean replace, IProgressMonitor monitor) throws CModelException;
+
+ /**
+ * Renames the given elements as specified.
+ * If one container is specified, all elements are renamed within that
+ * container. If more than one container is specified, the number of
+ * elements and containers must match, and each element is renamed within
+ * its associated container.
+ *
+ * @param elements the elements to rename
+ * @param destinations the container, or list of containers
+ * @param names the list of new names
+ * @param replace true
if an existing child in a target container
+ * with the target name should be replaced, and false
to throw an
+ * exception in the event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if an element could not be renamed. Reasons include:
+ * CoreException
occurred while updating an underlying resource
+ * INVALID_NAME
)
+ * replace
has been specified as false
(NAME_COLLISION
)
+ * READ_ONLY
)
+ * For example, a source method declaring "void f(int a) throw (x2, x3);"
,
+ * would return the array {"x2", "x3"}
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ */
+ public String[] getExceptions() throws CModelException;
+
+ /**
+ * Returns the number of parameters of this method.
+ */
+ public int getNumberOfParameters();
+
+ /**
+ * Returns the initializer of parameters pos for this method.
+ * Returns an empty string if this argument has no initializer.
+ *
+ *
For example, a method declared as void foo(String text, int length=9)
+ * would return the array {"9"}
.
+ *
+ * @exception CModelException if this argument does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public String getParameterInitializer(int pos);
+
+ /**
+ * Returns the type signatures for the parameters of this method.
+ * Returns an empty array if this method has no parameters.
+ * This is a handle-only method.
+ *
+ *
For example, a source method declared as void foo(string text, int length)
+ * would return the array {"string","int"}
.
+ *
+ * @see Signature
+ */
+ public String[] getParameterTypes();
+
+ /**
+ * Returns the type signature of the return value of this method.
+ * For constructors, this returns the signature for void.
+ *
+ *
For example, a source method declared as int getName()
+ * would return "int"
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ public String getReturnType() throws CModelException;
+
+ /**
+ * Returns the access Control of the member. The value can be
+ * can be examined using class Flags
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @see Flags
+ */
+ public int getAccessControl() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunctionDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunctionDeclaration.java
new file mode 100644
index 00000000000..53272f1eff8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IFunctionDeclaration.java
@@ -0,0 +1,80 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a function
+ */
+public interface IFunctionDeclaration extends ICElement, ISourceReference, ISourceManipulation {
+
+ /**
+ * Returns the type signatures of the exceptions this method throws,
+ * in the order declared in the source. Returns an empty array
+ * if this method throws no exceptions.
+ *
+ *
For example, a source method declaring "void f(int a) throw (x1, x2);"
,
+ * would return the array {"x1", "x2"}
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String[] getExceptions() throws CModelException;
+
+ /**
+ * Returns the number of parameters of this method.
+ */
+ int getNumberOfParameters();
+
+ /**
+ * Returns the initializer of parameters position for this method.
+ * Returns an empty string if this argument has no initializer.
+ *
+ *
For example, a method declared as public void foo(String text, int length=9)
+ * would return the array {"9"}
.
+ *
+ * @exception CModelException if this argument does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ String getParameterInitializer(int pos);
+
+ /**
+ * Returns the type signatures for the parameters of this method.
+ * Returns an empty array if this method has no parameters.
+ * This is a handle-only method.
+ *
+ *
For example, a source method declared as void foo(string text, int length)
+ * would return the array {"string","int"}
.
+ *
+ * @see Signature
+ */
+ String[] getParameterTypes();
+
+ /**
+ * Returns the type signature of the return value of this method.
+ * For constructors, this returns the signature for void.
+ *
+ *
For example, a source method declared as public String getName()
+ * would return "String"
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String getReturnType() throws CModelException;
+
+ /**
+ * Returns the access Control of the member. The access qualifier
+ * can be examine using the AccessControl class.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @see IAccessControl
+ */
+ int getAccessControl() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java
new file mode 100644
index 00000000000..e6e22ecc7c9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInclude.java
@@ -0,0 +1,25 @@
+package org.eclipse.cdt.core.model;
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents an include declaration in a C translation unit.
+ */
+public interface IInclude extends ICElement, ISourceReference, ISourceManipulation {
+ /**
+ * Returns the name that of the included file.
+ * For example, for the statement "#include
,
+ * this returns "stdio.h"
.
+ */
+ String getIncludeName();
+
+ /**
+ * Returns whether the included was search on "standard places" like /usr/include first .
+ * An include is standard if it starts with "\<"
.
+ * For example, "#include \
returns true and
+ * "#include "foobar.h"
returns false.
+ */
+ boolean isStandard();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInheritance.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInheritance.java
new file mode 100644
index 00000000000..ae8f968cda3
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IInheritance.java
@@ -0,0 +1,21 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Place holder of the inherited class from struct or class(IStructure).
+ */
+public interface IInheritance {
+ /**
+ * Return the inherited structures.
+ */
+ public IStructure [] getBaseTypes() throws CModelException;
+
+ /**
+ * Return the access control for each inherited structure.
+ */
+ public int getAccessControl(int pos) throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java
new file mode 100644
index 00000000000..43c12887f82
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILibraryReference.java
@@ -0,0 +1,11 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ */
+public interface ILibraryReference extends IParent, ICElement {
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacro.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacro.java
new file mode 100644
index 00000000000..6c6445347ee
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMacro.java
@@ -0,0 +1,14 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a field declared in a type.
+ */
+public interface IMacro extends ICElement, ISourceManipulation, ISourceReference {
+ String getIdentifierList();
+ String getTokenSequence();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMember.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMember.java
new file mode 100644
index 00000000000..a0667250b8c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMember.java
@@ -0,0 +1,48 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Common protocol for C elements that can be members of types.
+ * This set consists of IType
, IMethod
,
+ * IField
.
+ */
+public interface IMember extends ICElement, ISourceReference, ISourceManipulation {
+
+ ///**
+ //* Returns the structure in which this member is declared, or null
+ //* if this member is not declared in a type (for example, a top-level type).
+ //*/
+ //IStructure belongsTo() throws CModelException;
+
+ /**
+ * Returns true if the member as class scope.
+ * For example static methods in C++ have class scope
+ *
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean hasClassScope() throws CModelException;
+
+ /**
+ * Returns whether this method/field is declared constant.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean isConst() throws CModelException;
+
+ /**
+ * Returns the access Control of the member. The access qualifier
+ * can be examine using the AccessControl class.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @see IAccessControl
+ */
+ public int getAccessControl() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethod.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethod.java
new file mode 100644
index 00000000000..196287c1f4c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethod.java
@@ -0,0 +1,117 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents the definition method of a class.
+ */
+public interface IMethod extends IMember {
+
+ /**
+ * Returns the type signatures of the exceptions this method throws,
+ * in the order declared in the source. Returns an empty array
+ * if this method throws no exceptions.
+ *
+ *
For example, a source method declaring "throws IOException"
,
+ * would return the array {"QIOException;"}
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String[] getExceptions() throws CModelException;
+
+ /**
+ * Returns the number of parameters of this method.
+ */
+ int getNumberOfParameters();
+
+ /**
+ * Returns the initializer of parameters pos for this method.
+ * Returns an empty string if this argument has no initializer.
+ *
+ *
For example, a method declared as public void foo(String text, int length=9)
+ * would return the array {"9"}
.
+ *
+ * @exception CModelException if this argument does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ String getParameterInitializer(int pos);
+
+ /**
+ * Returns the type signatures for the parameters of this method.
+ * Returns an empty array if this method has no parameters.
+ * This is a handle-only method.
+ *
+ *
For example, a source method declared as void foo(String text, int length)
+ * would return the array {"String","int"}
.
+ *
+ * @see Signature
+ */
+ String[] getParameterTypes();
+
+ /**
+ * Returns the type signature of the return value of this method.
+ * For constructors, this returns the signature for void.
+ *
+ *
For example, a source method declared as public String getName()
+ * would return "String"
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String getReturnType() throws CModelException;
+
+ /**
+ * Returns whether this method is a constructor.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isConstructor() throws CModelException;
+
+ /**
+ * Returns whether this method is a destructor.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isDestructor() throws CModelException;
+
+ /**
+ * Returns whether this method is an operator method.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isOperator() throws CModelException;
+
+ /**
+ * Returns whether this method is declared pure virtual.
+ *
+ *
For example, a source method declared as virtual void m() = 0;
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isAbstract() throws CModelException;
+
+ /**
+ * Returns whether this method is declared virtual.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isVirtual() throws CModelException;
+
+ /**
+ * return true if the member is a friend.
+ */
+ public boolean isFriend() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethodDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethodDeclaration.java
new file mode 100644
index 00000000000..9a2fac2bf45
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IMethodDeclaration.java
@@ -0,0 +1,117 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents the declaration method of a class
+ */
+public interface IMethodDeclaration extends IMember {
+
+ /**
+ * Returns the type signatures of the exceptions this method throws,
+ * in the order declared in the source. Returns an empty array
+ * if this method throws no exceptions.
+ *
+ *
For example, a source method declaring "throws IOException"
,
+ * would return the array {"QIOException;"}
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String[] getExceptions() throws CModelException;
+
+ /**
+ * Returns the number of parameters of this method.
+ */
+ int getNumberOfParameters();
+
+ /**
+ * Returns the initializer of parameters pos for this method.
+ * Returns an empty string if this argument has no initializer.
+ *
+ *
For example, a method declared as public void foo(String text, int length=9)
+ * would return the array {"9"}
.
+ *
+ * @exception CModelException if this argument does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ String getParameterInitializer(int pos);
+
+ /**
+ * Returns the type signatures for the parameters of this method.
+ * Returns an empty array if this method has no parameters.
+ * This is a handle-only method.
+ *
+ *
For example, a source method declared as void foo(String text, int length)
+ * would return the array {"String","int"}
.
+ *
+ * @see Signature
+ */
+ String[] getParameterTypes();
+
+ /**
+ * Returns the type signature of the return value of this method.
+ * For constructors, this returns the signature for void.
+ *
+ *
For example, a source method declared as public String getName()
+ * would return "String"
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ *
+ * @see Signature
+ */
+ String getReturnType() throws CModelException;
+
+ /**
+ * Returns whether this method is a constructor.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isConstructor() throws CModelException;
+
+ /**
+ * Returns whether this method is a destructor.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isDestructor() throws CModelException;
+
+ /**
+ * Returns whether this method is an operator method.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isOperator() throws CModelException;
+
+ /**
+ * Returns whether this method is declared pure virtual.
+ *
+ *
For example, a source method declared as virtual void m() = 0;
.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isAbstract() throws CModelException;
+
+ /**
+ * Returns whether this method is declared virtual.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ boolean isVirtual() throws CModelException;
+
+ /**
+ * return true if the member is a friend.
+ */
+ public boolean isFriend() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/INamespace.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/INamespace.java
new file mode 100644
index 00000000000..e43b046cedd
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/INamespace.java
@@ -0,0 +1,16 @@
+package org.eclipse.cdt.core.model;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a package declaration in a C translation unit.
+ */
+public interface INamespace extends ICElement, ISourceManipulation, ISourceReference {
+ /**
+ * Returns the name of the package the statement refers to.
+ * This is a handle-only method.
+ */
+ String getElementName();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java
new file mode 100644
index 00000000000..a31077e022f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java
@@ -0,0 +1,31 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Common protocol for C elements that contain other C elements.
+ */
+public interface IParent {
+
+ /**
+ * Returns the immediate children of this element.
+ * The children are in no particular order.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ ICElement[] getChildren(); //throws CModelException;
+
+ /**
+ * Returns whether this element has one or more immediate children.
+ * This is a convenience method, and may be more efficient than
+ * testing whether getChildren
is an empty array.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ boolean hasChildren(); //throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceManipulation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceManipulation.java
new file mode 100644
index 00000000000..2cf3f0b2870
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ISourceManipulation.java
@@ -0,0 +1,109 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Common protocol for C elements that support source code manipulations such
+ * as copy, move, rename, and delete.
+ */
+public interface ISourceManipulation {
+ /**
+ * Copies this element to the given container.
+ *
+ * @param container the container
+ * @param sibling the sibling element before which the copy should be inserted,
+ * or null
if the copy should be inserted as the last child of
+ * the container
+ * @param rename the new name for the element, or null
if the copy
+ * retains the name of this element
+ * @param replace true
if any existing child in the container with
+ * the target name should be replaced, and false
to throw an
+ * exception in the event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if this element could not be copied. Reasons include:
+ *
CoreException
occurred while updating an underlying resource
+ * replace
has been specified as false
+ * null
+ */
+ void copy(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor) throws CModelException;
+
+ /**
+ * Deletes this element, forcing if specified and necessary.
+ *
+ * @param force a flag controlling whether underlying resources that are not
+ * in sync with the local file system will be tolerated (same as the force flag
+ * in IResource operations).
+ * @param monitor a progress monitor
+ * @exception CModelException if this element could not be deleted. Reasons include:
+ * CoreException
occurred while updating an underlying resource (CORE_EXCEPTION)null
if the element should be inserted as the last child of
+ * the container
+ * @param rename the new name for the element, or null
if the
+ * element retains its name
+ * @param replace true
if any existing child in the container with
+ * the target name should be replaced, and false
to throw an
+ * exception in the event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if this element could not be moved. Reasons include:
+ * CoreException
occurred while updating an underlying resource
+ * replace
has been specified as false
+ * null
+ */
+
+ void move(ICElement container, ICElement sibling, String rename, boolean replace, IProgressMonitor monitor) throws CModelException;
+
+ /**
+ * Renames this element to the given name.
+ *
+ * @param name the new name for the element
+ * @param replace true
if any existing element with the target name
+ * should be replaced, and false
to throw an exception in the
+ * event of a name collision
+ * @param monitor a progress monitor
+ * @exception CModelException if this element could not be renamed. Reasons include:
+ * CoreException
occurred while updating an underlying resource
+ * replace
has been specified as false
+ *
+ * Note: For IBinary
, IArchive
and other members
+ * derived from a binary type, the implementation returns source iff the
+ * element has attached source code and debuging information.
+ *
+ */
+
+public interface ISourceReference {
+
+ /**
+ * Returns the source code associated with this element.
+ *
+ * For binary files, this returns the source of the entire translation unit + * associated with the binary file (if there is one). + *
+ * + * @return the source code, ornull
if this element has no
+ * associated source code
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ String getSource() throws CModelException;
+
+ /**
+ * Returns the source range associated with this element.
+ * + * For binary files, this returns the range of the entire translation unit + * associated with the binary file (if there is one). + *
+ * + * @return the source range, ornull
if if this element has no
+ * associated source code
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ ISourceRange getSourceRange() throws CModelException;
+
+ /**
+ * Returns the translation unit in which this member is declared, or null
+ * if this member is not declared in a translation unit (for example, a binary type).
+ */
+ ITranslationUnit getTranslationUnit();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java
new file mode 100644
index 00000000000..c0cacfe885d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IStructure.java
@@ -0,0 +1,27 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represent struct(ure), class or union.
+ */
+public interface IStructure extends IInheritance, IParent, ICElement, IVariable {
+ //public String instantiatesTemplate();
+
+ public IField getField(String name);
+ public IField[] getFields();
+
+ public IMethod getMethod(String name);
+ public IMethod [] getMethods();
+
+ public boolean isUnion();
+
+ public boolean isClass();
+
+ public boolean isStruct();
+
+ public boolean isAbstract();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
new file mode 100644
index 00000000000..888fcb3b55e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
@@ -0,0 +1,120 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * Represents an entire C translation unit (.c
source file).
+ * The children are of type IStructureElement
,
+ * IInclude
, etc..
+ * and appear in the order in which they are declared in the source.
+ * If a .c
file cannot be parsed, its structure remains unknown.
+ * Use ICElement.isStructureKnown
to determine whether this is
+ * the case.
+ */
+public interface ITranslationUnit extends ICFile , ISourceReference, ISourceManipulation {
+ /**
+ * Creates and returns an include declaration in this translation unit
+ * with the given name.
+ * + * Optionally, the new element can be positioned before the specified + * sibling. If no sibling is specified, the element will be inserted + * as the last import declaration in this translation unit. + *
+ * If the translation unit already includes the specified include declaration,
+ * the import is not generated (it does not generate duplicates).
+ *
+ * @param name the name of the include declaration to add (For example: "stdio.h"
or
+ * "sys/types.h"
)
+ * @param sibling the existing element which the include declaration will be inserted immediately before (if
+ * null
, then this include will be inserted as the last include declaration.
+ * @param monitor the progress monitor to notify
+ * @return the newly inserted include declaration (or the previously existing one in case attempting to create a duplicate)
+ *
+ * @exception CModelException if the element could not be created. Reasons include:
+ *
CoreException
occurred while updating an underlying resource
+ * If the translation unit already includes the specified package declaration,
+ * it is not generated (it does not generate duplicates).
+ *
+ * @param name the name of the namespace declaration to add (For example, "std"
)
+ * @param monitor the progress monitor to notify
+ * @return the newly inserted namespace declaration (or the previously existing one in case attempting to create a duplicate)
+ *
+ * @exception CModelException if the element could not be created. Reasons include:
+ *
CoreException
occurred while updating an underlying resource
+ * null
if there is no element other than the translation
+ * unit itself at the given position, or if the given position is not
+ * within the source range of this translation unit.
+ *
+ * @param position a source position inside the translation unit
+ * @return the innermost C element enclosing a given source position or null
+ * if none (excluding the translation unit).
+ * @exception CModelException if the translation unit does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ ICElement getElementAtLine(int line) throws CModelException;
+
+ ICElement getElement(String name) throws CModelException;
+
+ /**
+ * Returns the include declaration in this translation unit with the given name.
+ *
+ * @param the name of the include to find (For example: "stdio.h"
+ * or "sys/types.h"
)
+ * @return a handle onto the corresponding include declaration. The include declaration may or may not exist.
+ */
+ IInclude getInclude(String name) ;
+
+ /**
+ * Returns the include declarations in this translation unit
+ * in the order in which they appear in the source.
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ IInclude[] getIncludes() throws CModelException;
+
+ /**
+ * Returns the first namespace declaration in this translation unit with the given package name
+ * This is a handle-only method. The namespace declaration may or may not exist.
+ *
+ * @param name the name of the namespace declaration (For example, "std"
)
+ */
+ IUsing getUsing(String name);
+
+ /**
+ * Returns the namespace declarations in this translation unit
+ * in the order in which they appear in the source.
+ *
+ * @return an array of namespace declaration (normally of size one)
+ *
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource
+ */
+ IUsing[] getUsings() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java
new file mode 100644
index 00000000000..eae2e26fbcc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java
@@ -0,0 +1,16 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a field declared in a type.
+ */
+public interface ITypeDef extends ICElement, ISourceManipulation, ISourceReference {
+ /**
+ * Return the type beeing alias.
+ */
+ String getType() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java
new file mode 100644
index 00000000000..2002f55a0e0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IUsing.java
@@ -0,0 +1,16 @@
+package org.eclipse.cdt.core.model;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a "using" declaration in C translation unit.
+ */
+public interface IUsing extends ICElement, ISourceManipulation, ISourceReference {
+ /**
+ * Returns the name of the package the statement refers to.
+ * This is a handle-only method.
+ */
+ String getElementName();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariable.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariable.java
new file mode 100644
index 00000000000..5708996a27d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariable.java
@@ -0,0 +1,15 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a global variable.
+ */
+public interface IVariable extends ICElement , ISourceManipulation, ISourceReference {
+ public String getType();
+ public String getInitializer();
+ public int getAccessControl() throws CModelException;
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableDeclaration.java
new file mode 100644
index 00000000000..ea79d61beb8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableDeclaration.java
@@ -0,0 +1,15 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents the declaration of a variable.
+ */
+public interface IVariableDeclaration extends ICElement, ISourceManipulation, ISourceReference {
+
+ public String getType ();
+ public int getAccesControl();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableLocal.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableLocal.java
new file mode 100644
index 00000000000..f88ee6452d6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IVariableLocal.java
@@ -0,0 +1,12 @@
+package org.eclipse.cdt.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Represents a static variable.
+ */
+public interface IVariableLocal extends IVariable {
+}
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
new file mode 100644
index 00000000000..14a515fdf98
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java
@@ -0,0 +1,44 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IArchive;
+import org.eclipse.cdt.core.model.IBinary;
+
+public class Archive extends CFile implements IArchive {
+
+ public Archive(ICElement parent, IFile file) {
+ super(parent, file);
+ }
+
+ public Archive(ICElement parent, IPath path) {
+ super (parent, path);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ public boolean isArchive() {
+ return true;
+ }
+
+ public IBinary[] getBinaries() {
+ return (IBinary[])getChildren();
+ }
+
+ public CElementInfo createElementInfo() {
+ return new ArchiveInfo(this);
+ }
+
+ protected ArchiveInfo getArchiveInfo() {
+ return (ArchiveInfo)getElementInfo();
+ }
+}
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
new file mode 100644
index 00000000000..ad1261403a6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainer.java
@@ -0,0 +1,87 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+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.cdt.core.model.IArchive;
+import org.eclipse.cdt.core.model.IArchiveContainer;
+import org.eclipse.cdt.core.model.ICElement;
+
+public class ArchiveContainer extends Parent implements IArchiveContainer {
+
+ CProject cProject;
+ private long modificationStamp;
+
+ public ArchiveContainer (CProject cProject) {
+ super (cProject, null, "lib", CElement.C_CONTAINER);
+ this.cProject = cProject;
+ IProject project = cProject.getProject();
+ IFolder folder = project.getFolder("Virtual.lib");
+ setUnderlyingResource(folder);
+ }
+
+ public IArchive[] getArchives() {
+ ICElement[] e = getChildren(false);
+ IArchive[] a = new IArchive[e.length];
+ System.arraycopy(e, 0, a, 0, e.length);
+ return a;
+ }
+
+ public boolean hasChildren() {
+ return (getChildren().length > 0);
+ }
+
+ public ICElement [] getChildren() {
+ return getChildren(true);
+ }
+
+ public ICElement [] getChildren(boolean sync) {
+ if (!cProject.hasRunElf()) {
+ // It is vital to set this to true first, if not we are going to loop
+ cProject.setRunElf(true);
+ ElfRunner runner = new ElfRunner(cProject);
+ Thread thread = new Thread(runner, "Archive Runner");
+ // thread.setPriority(Thread.NORM_PRIORITY - 1);
+ thread.setDaemon(true);
+ thread.start();
+ if (sync) {
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ return super.getChildren();
+ }
+
+ //public IResource getUnderlyingResource() {
+ // return null;
+ //}
+
+ public IResource getCorrespondingResource() {
+ return null;
+ }
+
+ void addChildIfLib(IFile file) {
+ CModelManager factory = CModelManager.getDefault();
+ if (factory.isArchive(file)) {
+ ICElement celement = factory.create(file);
+ if (celement != null) {
+ if (celement instanceof IArchive) {
+ addChild (celement);
+ }
+ }
+ }
+ }
+
+ public CElementInfo createElementInfo() {
+ return new CElementInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..3aac72d6fbf
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveInfo.java
@@ -0,0 +1,77 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+
+import org.eclipse.cdt.utils.elf.AR;
+import org.eclipse.cdt.utils.elf.ElfHelper;
+
+/**
+ * Info for ICProject.
+ */
+
+class ArchiveInfo extends CFileInfo {
+
+ /**
+ */
+ public ArchiveInfo(CElement element) {
+ super(element);
+ }
+
+ public ICElement [] getChildren() {
+ init();
+ return super.getChildren();
+ }
+
+ public void init() {
+ if (hasChanged()) {
+ removeChildren();
+ loadInfo();
+ }
+ }
+
+ public boolean isArchive() {
+ return true;
+ }
+
+ protected void loadInfo() {
+ IPath location = ((CFile)getElement()).getLocation();
+ IFile file = ((CFile)getElement()).getFile();
+ try {
+ AR ar = new AR(location.toOSString());
+ AR.ARHeader[] header = ar.getHeaders();
+ for (int i = 0; i < header.length; i++) {
+ ElfHelper helper = new ElfHelper(header[i].getElf());
+ //IPath path = new Path(header[i].getObjectName());
+ // FIXME: We should create a special IResource for this files
+ // but for now, just bypass.
+ Binary binary = new Binary(getElement(), file, header[i].getObjectName()) {
+ public IResource getCorrespondingResource() {
+ return null;
+ }
+ };
+ // Force the loading so we can dispose;
+ ((BinaryInfo)(binary.getElementInfo())).elfHelper = helper;
+ // Force the loading of the chidren right away so we can
+ // dispose of the elf Elper.
+ binary.getChildren();
+ ((BinaryInfo)(binary.getElementInfo())).elfHelper = null;
+ helper.dispose();
+ addChild(binary);
+ }
+ ar.dispose();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ }
+}
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
new file mode 100644
index 00000000000..f0bb5fe6884
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Binary.java
@@ -0,0 +1,80 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IBinary;
+
+public class Binary extends CFile implements IBinary {
+
+ public Binary(ICElement parent, IFile file) {
+ super(parent, file);
+ }
+
+ public Binary(ICElement parent, IPath path) {
+ super (parent, path);
+ }
+
+ public Binary(ICElement parent, IFile file, String name) {
+ super(parent, file, name);
+ }
+
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ public boolean isBinary() {
+ return true;
+ }
+
+ public boolean hasDebug () {
+ return ((BinaryInfo)getElementInfo()).hasDebug();
+ }
+
+ public boolean isExecutable() {
+ return ((BinaryInfo)getElementInfo()).isExecutable();
+ }
+
+ public boolean isObject() {
+ return ((BinaryInfo)getElementInfo()).isObject();
+ }
+
+ public boolean isSharedLib() {
+ return ((BinaryInfo)getElementInfo()).isSharedLib();
+ }
+
+ public String [] getNeededSharedLibs() {
+ return ((BinaryInfo)getElementInfo()).getNeededSharedLibs();
+ }
+
+ public String getCPU() {
+ return ((BinaryInfo)getElementInfo()).getCPU();
+ }
+
+ public long getText() {
+ return ((BinaryInfo)getElementInfo()).getText();
+ }
+
+ public long getData() {
+ return ((BinaryInfo)getElementInfo()).getData();
+ }
+
+ public long getBSS() {
+ return ((BinaryInfo)getElementInfo()).getBSS();
+ }
+
+ public String getSoname() {
+ return ((BinaryInfo)getElementInfo()).getSoname();
+ }
+
+ public CElementInfo createElementInfo() {
+ return new BinaryInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..02962288bcb
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainer.java
@@ -0,0 +1,147 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+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.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICRoot;
+
+public class BinaryContainer extends Parent implements IBinaryContainer {
+
+ CProject cProject;
+ private long modificationStamp;
+
+ public BinaryContainer (CProject cProject) {
+ this (cProject, "bin");
+ }
+
+ public BinaryContainer (CProject cProject, String name) {
+ super (cProject, null, name, CElement.C_CONTAINER);
+ this.cProject = cProject;
+ IProject project = cProject.getProject();
+ IFolder folder = project.getFolder("Virtual.bin");
+ setUnderlyingResource(folder);
+ }
+
+ public IBinary[] getBinaries() {
+ ICElement[] e = getChildren(false);
+ IBinary[] b = new IBinary[e.length];
+ System.arraycopy(e, 0, b, 0, e.length);
+ return b;
+ }
+
+ public boolean hasChildren() {
+ return (getChildren().length > 0);
+ }
+
+ public ICElement [] getChildren() {
+ return getChildren(true);
+ }
+
+ public ICElement [] getChildren(boolean sync) {
+ // The first time probe the entire project to discover binaries.
+ if (!cProject.hasRunElf()) {
+ cProject.setRunElf(true);
+ ElfRunner runner = new ElfRunner(cProject);
+ Thread thread = new Thread(runner, "Elf Runner");
+ // thread.setPriority(Thread.NORM_PRIORITY - 1);
+ thread.setDaemon(true);
+ thread.start();
+ if (sync) {
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ return super.getChildren();
+ }
+
+ public IResource getCorrespondingResource() {
+ return null;
+ }
+
+ //public IResource getUnderlyingResource() {
+ // return null;
+ //}
+
+ void addChildIfExec(CoreModel factory, IFile file) {
+ // Attempt to speed things up by rejecting up front
+ // Things we know should not be Elf/Binary files.
+ if (!factory.isTranslationUnit(file)) {
+ ICElement celement = factory.create(file);
+ if (celement != null) {
+ if (celement instanceof IBinary) {
+ IBinary bin = (IBinary)celement;
+ if (bin.isExecutable() || bin.isSharedLib()) {
+ addChild (bin);
+ }
+ }
+ }
+ }
+ }
+
+ public CElementInfo createElementInfo() {
+ return new CElementInfo(this);
+ }
+
+ class Visitor implements IResourceVisitor {
+ CoreModel factory = CoreModel.getDefault();
+ BinaryContainer cbin;
+
+ public Visitor (BinaryContainer element) {
+ cbin = element;
+ }
+
+ public boolean visit(IResource res) throws CoreException {
+ if (res instanceof IFile) {
+ cbin.addChildIfExec(factory, (IFile)res);
+ return false;
+ }
+ return true;
+ }
+ }
+
+ class BinaryRunnable implements Runnable {
+ BinaryContainer cbin;
+
+ public BinaryRunnable(BinaryContainer element) {
+ cbin = element;
+ }
+
+ public void run() {
+ try {
+ ((IProject)cbin.getCProject().getUnderlyingResource()).accept(new Visitor(cbin));
+ } catch (CoreException e) {
+ //e.printStackTrace();
+ }
+ // Fired the event.
+ ICElement[] children = cbin.getChildren();
+ if (children.length > 0) {
+ CModelManager factory = CModelManager.getDefault();
+ ICElement root = (ICRoot)factory.getCRoot();
+ CElementDelta cdelta = new CElementDelta(root);
+ cdelta.added(cbin.getCProject());
+ cdelta.added(cbin);
+ for (int i = 0; i < children.length; i++) {
+ ICElement child = children[i];
+ cdelta.added(child);
+ }
+ factory.registerCModelDelta(cdelta);
+ factory.fire();
+ }
+ }
+ }
+}
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
new file mode 100644
index 00000000000..b47cacafeab
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryInfo.java
@@ -0,0 +1,253 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.cdt.core.model.ICElement;
+
+import org.eclipse.cdt.utils.elf.Elf;
+import org.eclipse.cdt.utils.elf.ElfHelper;
+
+class BinaryInfo extends CFileInfo {
+
+ String [] needed;
+ ElfHelper.Sizes sizes;
+ Elf.Attribute attribute;
+ String soname;
+ Map hash;
+ ElfHelper elfHelper = null;
+
+ public BinaryInfo(CElement element) {
+ super(element);
+ needed = new String[0];
+ sizes = null;
+ attribute = null;
+ soname = "";
+ hash = new HashMap();
+ }
+
+ public boolean isBinary() {
+ return true;
+ }
+
+ public ICElement [] getChildren() {
+ initChildren();
+ return super.getChildren();
+ }
+
+ public String getCPU() {
+ init();
+ String cpu = null;
+ if (attribute != null)
+ cpu = attribute.getCPU();
+ return (cpu == null) ? "" : cpu;
+ }
+
+ public boolean isSharedLib() {
+ init();
+ if (attribute != null)
+ return attribute.getType() == attribute.ELF_TYPE_SHLIB;
+ return false;
+ }
+
+ public boolean isExecutable() {
+ init();
+ if (attribute != null)
+ return attribute.getType() == attribute.ELF_TYPE_EXE;
+ return false;
+ }
+
+ public boolean isObject() {
+ init();
+ if (attribute != null)
+ return attribute.getType() == attribute.ELF_TYPE_OBJ;
+ return false;
+ }
+
+ public boolean hasDebug () {
+ init();
+ if (attribute != null)
+ return attribute.hasDebug();
+ return false;
+ }
+
+ public String [] getNeededSharedLibs() {
+ init();
+ return needed;
+ }
+
+ public long getText() {
+ init();
+ if (sizes != null) {
+ return sizes.text;
+ }
+ return 0;
+ }
+
+ public long getData() {
+ init();
+ if (sizes != null) {
+ return sizes.data;
+ }
+ return 0;
+ }
+
+ public long getBSS() {
+ init();
+ if (sizes != null) {
+ return sizes.bss;
+ }
+ return 0;
+ }
+
+ public String getSoname() {
+ init();
+ return soname;
+ }
+
+ private void addFunction(Elf.Symbol [] symbol, boolean external) {
+ for (int i = 0; i < symbol.length; i++) {
+ ICElement parent = getElement();
+ String filename = null;
+ try {
+ filename = symbol[i].getFilename();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ Function function = null;
+
+ // Addr2line returns the funny "??" when it can find the file.
+ if (filename != null && !filename.equals("??")) {
+ TranslationUnit tu = null;
+ IPath path = new Path(filename);
+ if (hash.containsKey(path)) {
+ tu = (TranslationUnit)hash.get(path);
+ } else {
+ tu = new TranslationUnit(parent, path);
+ hash.put(path, tu);
+ addChild(tu);
+ }
+ function = new Function(tu, symbol[i].toString());
+ tu.addChild(function);
+ } else {
+ function = new Function(parent, symbol[i].toString());
+ addChild(function);
+ }
+ if (function != null)
+ if (!external)
+ function.getFunctionInfo().setAccessControl(IConstants.AccStatic);
+ }
+ }
+
+ private void addVariable(Elf.Symbol[] symbol, boolean external) {
+ for (int i = 0; i < symbol.length; i++) {
+ String filename = null;
+ try {
+ filename = symbol[i].getFilename();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ ICElement parent = getElement();
+ Variable variable = null;
+ // Addr2line returns the funny "??" when it can not find the file.
+ if (filename != null && !filename.equals("??")) {
+ TranslationUnit tu = null;
+ IPath path = new Path(filename);
+ if (hash.containsKey(path)) {
+ tu = (TranslationUnit)hash.get(path);
+ } else {
+ tu = new TranslationUnit(parent, path);
+ hash.put(path, tu);
+ addChild(tu);
+ }
+ variable = new Variable(tu, symbol[i].toString());
+ tu.addChild(variable);
+ } else {
+ variable = new Variable(parent, symbol[i].toString());
+ addChild(variable);
+ }
+ if (variable != null)
+ if (!external)
+ variable.getVariableInfo().setAccessControl(IConstants.AccStatic);
+ }
+ }
+
+ protected void init() {
+ if (hasChanged()) {
+ loadInfo();
+ }
+ }
+
+ protected void initChildren() {
+ if (hasChanged() || !isStructureKnown()) {
+ removeChildren();
+ loadInfoChildren();
+ }
+ }
+
+
+ protected ElfHelper getElfHelper() throws IOException {
+ if (elfHelper != null) {
+ return elfHelper;
+ }
+ CFile file = (CFile)getElement();
+ if (file != null) {
+ IPath path = ((CFile)getElement()).getLocation();
+ if (path == null)
+ path = new Path("");
+ return new ElfHelper(path.toOSString());
+ }
+ throw new IOException("No file assiocated with Binary");
+ }
+
+ protected void loadInfo() {
+ try {
+ ElfHelper helper = this.getElfHelper();
+ Elf.Dynamic[] sharedlibs = helper.getNeeded();
+ needed = new String[sharedlibs.length];
+ for (int i = 0; i < sharedlibs.length; i++) {
+ needed[i] = sharedlibs[i].toString();
+ }
+
+ sizes = helper.getSizes();
+ soname = helper.getSoname();
+ attribute = helper.getElf().getAttributes();
+ helper.dispose();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ }
+
+ protected void loadInfoChildren() {
+ try {
+ setIsStructureKnown(true);
+ ElfHelper helper = this.getElfHelper();
+ addFunction(helper.getExternalFunctions(), true);
+ addFunction(helper.getLocalFunctions(), false);
+ addVariable(helper.getExternalObjects(), true);
+ addVariable(helper.getLocalObjects(), false);
+
+ Elf.Dynamic[] sharedlibs = helper.getNeeded();
+ needed = new String[sharedlibs.length];
+ for (int i = 0; i < sharedlibs.length; i++) {
+ needed[i] = sharedlibs[i].toString();
+ }
+
+ sizes = helper.getSizes();
+ soname = helper.getSoname();
+ attribute = helper.getElf().getAttributes();
+ helper.dispose();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ }
+}
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
new file mode 100644
index 00000000000..c66ebbe2ebc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java
@@ -0,0 +1,267 @@
+package org.eclipse.cdt.internal.core.model;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICRoot;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.CModelException;
+
+public abstract class CElement extends PlatformObject implements ICElement {
+
+ protected int fType;
+
+ protected ICElement fParent;
+
+ protected CElementInfo fCElementInfo;
+
+ protected String fName;
+
+ protected int fStartPos;
+ protected int fLength;
+ protected int fIdStartPos;
+ protected int fIdLength;
+ protected int fStartLine;
+ protected int fEndLine;
+
+ protected CElement[] empty = new CElement[0];
+
+ protected CElement(ICElement parent, String name, int type) {
+ fParent= parent;
+ fName= name;
+ fType= type;
+ fCElementInfo = null;
+ }
+
+ // 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() {
+ try {
+ IResource res = getUnderlyingResource();
+ if (res != null)
+ return res.getFullPath();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public boolean exists() {
+ try {
+ return getCorrespondingResource() != null;
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ public boolean isStructureKnown() throws CModelException {
+ return getElementInfo().isStructureKnown();
+ }
+
+ public ICRoot getCRoot () {
+ return getParent().getCRoot();
+ }
+
+ public ICProject getCProject() {
+ return getParent().getCProject();
+ }
+
+ protected void addChild(ICElement e) {
+ }
+
+ 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 abstract IResource getUnderlyingResource() throws CModelException;
+
+ public abstract IResource getCorrespondingResource() throws CModelException;
+
+ protected abstract CElementInfo createElementInfo();
+
+ /**
+ * Finds a member corresponding to a give element.
+ */
+ //public ICElement findEqualMember(ICElement elem) {
+ // if (this instanceof IParent) {
+ // ICElement[] members = ((IParent)this).getChildren();
+ // if (members != null) {
+ // for (int i= members.length - 1; i >= 0; i--) {
+ // ICElement curr= members[i];
+ // if (curr.equals(elem)) {
+ // return curr;
+ // } else {
+ // ICElement res= curr.findEqualMember(elem);
+ // if (res != null) {
+ // return res;
+ // }
+ // }
+ // }
+ // }
+ // return null;
+ //}
+
+ /**
+ * 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;
+ try {
+ IResource tres = getCorrespondingResource();
+ IResource ores = other.getCorrespondingResource();
+ if (ores != null && tres != null) {
+ return tres.equals(ores);
+ }
+ } catch (CModelException e) {
+ //e.printStackTrace();
+ }
+ 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 () {
+ if (fCElementInfo == null) {
+ fCElementInfo = createElementInfo();
+ }
+ return fCElementInfo;
+ }
+
+ public String toString() {
+ return getElementName();
+ }
+
+ public String toDebugString() {
+ return getElementName() + " " + getTypeString(getElementType());
+ }
+
+ // util
+ public static String getTypeString(int type) {
+ switch (type) {
+ case C_ROOT:
+ return "CROOT";
+ case C_PROJECT:
+ return "CPROJECT";
+ case C_FOLDER:
+ return "CFOLDER";
+ case C_FILE:
+ return "CFILE";
+ case C_FUNCTION:
+ return "C_FUNCTION";
+ case C_FUNCTION_DECLARATION:
+ return "C_FUNCTION_DECLARATION";
+ case C_VARIABLE:
+ return "C_VARIABLE";
+ case C_VARIABLE_DECLARATION:
+ return "C_VARIABLE_DECLARATION";
+ case C_INCLUDE:
+ return "C_INCLUDE";
+ case C_MACRO:
+ return "C_MACRO";
+ case C_STRUCT:
+ return "C_STRUCT";
+ case C_CLASS:
+ return "C_CLASS";
+ case C_UNION:
+ return "C_UNION";
+ case C_FIELD:
+ return "C_FIELD";
+ case C_METHOD:
+ return "C_METHOD";
+ default:
+ return "UNKNOWN";
+ }
+ }
+
+ /**
+ * Runs a C Model Operation
+ */
+ protected void runOperation(CModelOperation operation, IProgressMonitor monitor) throws CModelException {
+ CModelManager.getDefault().runOperation(operation, monitor);
+ }
+}
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
new file mode 100644
index 00000000000..ad99aaa2e2f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementDelta.java
@@ -0,0 +1,736 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IResourceDelta;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IArchive;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.CModelException;
+
+
+/**
+ * @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).
+ * added(ICElement)
+ * changed(ICElement)
+ * moved(ICElement, ICElement)
+ * removed(ICElement)
+ * renamed(ICElement, ICElement)
+ * CElementDelta
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, null
+ * 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 = ((CElementDelta)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 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_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/CElementInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
new file mode 100644
index 00000000000..333c15e2ac0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
@@ -0,0 +1,184 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+
+import org.eclipse.core.resources.IResource;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.CModelException;
+
+/**
+ * Holds cached structure and properties for a C element.
+ * Subclassed to carry properties for specific kinds of elements.
+ */
+class CElementInfo {
+
+ protected CElement element;
+
+ /**
+ * Collection of handles of immediate children of this
+ * object. This is an empty array if this element has
+ * no children.
+ */
+ protected ICElement[] fChildren;
+
+ /**
+ * Shared empty collection used for efficiency.
+ */
+ protected static ICElement[] fgEmptyChildren = new ICElement[]{};
+ /**
+ * 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;
+ fChildren = fgEmptyChildren;
+ }
+
+ protected CElement getElement() {
+ return element;
+ }
+
+ protected void addChild(ICElement child) {
+ if (fChildren == fgEmptyChildren) {
+ setChildren(new ICElement[] {child});
+ } else {
+ if (!includesChild(child)) {
+ setChildren(growAndAddToArray(fChildren, child));
+ }
+ }
+ }
+
+ protected ICElement[] getChildren() {
+ return fChildren;
+ }
+
+ /**
+ * Adds the new element to a new array that contains all of the elements of the old array.
+ * Returns the new array.
+ */
+ protected ICElement[] growAndAddToArray(ICElement[] array, ICElement addition) {
+ ICElement[] old = array;
+ array = new ICElement[old.length + 1];
+ System.arraycopy(old, 0, array, 0, old.length);
+ array[old.length] = addition;
+ return array;
+ }
+
+ /**
+ * Returns true
if this child is in my children collection
+ */
+ protected boolean includesChild(ICElement child) {
+
+ for (int i= 0; i < fChildren.length; i++) {
+ if (fChildren[i].equals(child)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see ICElement.isStructureKnown()
+ */
+ protected boolean isStructureKnown() {
+ return fIsStructureKnown;
+ }
+
+ /**
+ * Returns an array with all the same elements as the specified array except for
+ * the element to remove. Assumes that the deletion is contained in the array.
+ */
+ protected ICElement[] removeAndShrinkArray(ICElement[] array, ICElement deletion) {
+ ICElement[] old = array;
+ array = new ICElement[old.length - 1];
+ int j = 0;
+ for (int i = 0; i < old.length; i++) {
+ if (!old[i].equals(deletion)) {
+ array[j] = old[i];
+ } else {
+ System.arraycopy(old, i + 1, array, j, old.length - (i + 1));
+ return array;
+ }
+ j++;
+ }
+ return array;
+ }
+
+ protected void removeChild(ICElement child) {
+ if (includesChild(child)) {
+ setChildren(removeAndShrinkArray(fChildren, child));
+ }
+ }
+
+ protected void removeChildren () {
+ fChildren = fgEmptyChildren;
+ }
+
+ protected void setChildren(ICElement[] children) {
+ fChildren = children;
+ }
+
+ protected boolean hasChildren() {
+ return fChildren.length > 0;
+ }
+
+ protected void setChanged() {
+ modificationStamp = 0;
+ }
+
+ protected boolean hasChanged () {
+ IResource r = null;
+ boolean b = false;
+ try {
+ r = getElement().getUnderlyingResource();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ 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/CFile.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java
new file mode 100644
index 00000000000..5ac68f0a25d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFile.java
@@ -0,0 +1,76 @@
+package org.eclipse.cdt.internal.core.model;
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+//import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICFile;
+
+public class CFile extends CResource implements ICFile {
+
+ IPath location;
+
+ public CFile(ICElement parent, IFile file) {
+ this(parent, file, file.getLocation(), file.getName());
+ }
+
+ public CFile(ICElement parent, IFile file, String name) {
+ this(parent, file, file.getLocation(), name);
+ }
+
+ public CFile(ICElement parent, IPath location) {
+ this(parent, ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(location),
+ location, location.lastSegment());
+ }
+
+ public CFile(ICElement parent, IResource res, IPath location, String name) {
+ super(parent, res, name, CElement.C_FILE);
+ this.location = location;
+ }
+
+
+ public IPath getLocation () {
+ return location;
+ }
+
+ public void setLocation(IPath location) {
+ this.location = location;
+ }
+
+ public IFile getFile () {
+ try {
+ return (IFile)getUnderlyingResource();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public boolean isBinary() {
+ return getCFileInfo().isBinary();
+ }
+
+ public boolean isArchive() {
+ return getCFileInfo().isArchive();
+ }
+
+ public boolean isTranslationUnit() {
+ return getCFileInfo().isTranslationUnit();
+ }
+
+ protected CFileInfo getCFileInfo() {
+ return (CFileInfo)getElementInfo();
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new CFileInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..b31f3745031
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFileInfo.java
@@ -0,0 +1,32 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+public class CFileInfo extends CResourceInfo {
+
+ /**
+ * Constructs a new C Model Info
+ */
+ protected CFileInfo(CElement element) {
+ super(element);
+ }
+
+ protected boolean hasChildren() {
+ return false;
+ }
+
+ public boolean isBinary() {
+ return false;
+ }
+
+ public boolean isArchive() {
+ return false;
+ }
+
+ public boolean isTranslationUnit() {
+ return (this instanceof TranslationUnitInfo);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java
new file mode 100644
index 00000000000..a7547a12ef9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolder.java
@@ -0,0 +1,32 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFolder;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICFolder;
+import org.eclipse.cdt.core.model.CModelException;
+
+public class CFolder extends CResource implements ICFolder {
+
+ public CFolder (ICElement parent, IFolder folder) {
+ super (parent, folder, ICElement.C_FOLDER);
+ }
+
+ public IFolder getFolder () {
+ try {
+ return (IFolder)getUnderlyingResource();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new CFolderInfo(this);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolderInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolderInfo.java
new file mode 100644
index 00000000000..c95dbc0ed66
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CFolderInfo.java
@@ -0,0 +1,18 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ */
+public class CFolderInfo extends CResourceInfo {
+
+ /**
+ * Constructs a new C Model Info
+ */
+ protected CFolderInfo(CElement element) {
+ super(element);
+ }
+}
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
new file mode 100644
index 00000000000..4910f547dc8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java
@@ -0,0 +1,701 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Arrays;
+import java.util.Iterator;
+
+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.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IArchive;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.model.IElementChangedListener;
+import org.eclipse.cdt.core.model.ElementChangedEvent;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.CModelException;
+
+import org.eclipse.cdt.core.model.CoreModel;
+
+import org.eclipse.cdt.utils.elf.Elf;
+import org.eclipse.cdt.utils.elf.AR;
+
+public class CModelManager implements IResourceChangeListener {
+
+ // FIXME: Get it from the plugin class.
+ private static String C_NATURE_ID = CoreModel.getCNatureId();
+ private static String CC_NATURE_ID = CoreModel.getCCNatureId();
+
+ private HashMap fParsedResources = new HashMap();
+
+ /**
+ * Used to convert IResourceDelta
s into IJavaElementDelta
s.
+ */
+ protected DeltaProcessor fDeltaProcessor= new DeltaProcessor();
+
+ /**
+ * Queue of deltas created explicily by the C Model that
+ * have yet to be fired.
+ */
+ private ArrayList fCModelDeltas= new ArrayList();
+
+ /**
+ * Turns delta firing on/off. By default it is on.
+ */
+ protected boolean fFire= true;
+
+ /**
+ * Collection of listeners for C element deltas
+ */
+ protected ArrayList fElementChangedListeners= new ArrayList();
+
+ public static final String [] cExtensions = {"c", "cxx", "cc", "C", "cpp", "h", "hh"};
+
+ 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.PRE_AUTO_BUILD
+ | IResourceChangeEvent.POST_CHANGE
+ | IResourceChangeEvent.PRE_DELETE
+ | IResourceChangeEvent.PRE_CLOSE);
+ }
+ return factory;
+ }
+
+ /**
+ * Returns the CRoot for the given workspace, creating
+ * it if it does not yet exist.
+ */
+ public ICElement getCRoot(IWorkspaceRoot root) {
+ return create(root);
+ }
+
+ public ICElement getCRoot () {
+ return create(ResourcesPlugin.getWorkspace().getRoot());
+ }
+
+ 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 getCRoot(root);
+ res = root.getContainerForLocation(path);
+ if (res == null)
+ res = root.getFileForLocation(path);
+ }
+ return create (res);
+ }
+
+ public ICElement create (IResource resource) {
+ 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);
+ case IResource.FOLDER :
+ return create((IFolder)resource);
+ case IResource.ROOT :
+ return create((IWorkspaceRoot)resource);
+ default :
+ return null;
+ }
+ }
+
+ public ICElement create(ICElement parent, IResource resource) {
+ int type = resource.getType();
+ switch (type) {
+ case IResource.PROJECT :
+ return create(parent, (IProject)resource);
+ case IResource.FILE :
+ return create(parent, (IFile)resource);
+ case IResource.FOLDER :
+ return create(parent, (IFolder)resource);
+ case IResource.ROOT :
+ return create(parent, (IWorkspaceRoot)resource);
+ default :
+ return null;
+ }
+ }
+
+ public ICElement create(IFile file) {
+ IResource parent = file.getParent();
+ ICElement celement = null;
+ if (parent instanceof IFolder) {
+ celement = create ((IFolder)parent);
+ } else if (parent instanceof IProject) {
+ celement = create ((IProject)parent);
+ }
+ if (celement != null)
+ return create (celement, file);
+ return celement;
+ }
+
+ public synchronized ICElement create(ICElement parent, IFile file) {
+ ICElement celement = (ICElement)fParsedResources.get(file);
+ if (celement == null) {
+ if (file.exists()) {
+ if (isArchive(file)) {
+ celement = new Archive(parent, file);
+ } else if (isBinary(file)) {
+ celement = new Binary(parent, file);
+ } else if (isTranslationUnit(file)) {
+ celement = new TranslationUnit(parent, file);
+ } else {
+ celement = new CFile(parent, file);
+ }
+ fParsedResources.put(file, celement);
+ }
+ }
+ // Added also to the Containers
+ if (celement != null) {
+ if (celement instanceof IArchive) {
+ CProject cproj = (CProject)celement.getCProject();
+ ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer();
+ container.addChild(celement);
+ } else if (celement instanceof IBinary) {
+ IBinary bin = (IBinary)celement;
+ if (bin.isExecutable() || bin.isSharedLib()) {
+ CProject cproj = (CProject)celement.getCProject();
+ BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
+ container.addChild(bin);
+ }
+ }
+ }
+ return celement;
+ }
+
+ public ICElement create(IFolder folder) {
+ IResource parent = folder.getParent();
+ ICElement celement = null;
+ if (parent instanceof IFolder) {
+ celement = create ((IFolder)parent);
+ } else if (parent instanceof IProject) {
+ celement = create ((IProject)parent);
+ }
+ if (celement != null)
+ return create (celement, folder);
+ return celement;
+ }
+
+ public synchronized ICElement create(ICElement parent, IFolder folder) {
+ ICElement celement = (ICElement)fParsedResources.get(folder);
+ if (celement == null) {
+ celement = new CFolder(parent, folder);
+ fParsedResources.put(folder, celement);
+ }
+ return celement;
+ }
+
+ public ICElement create(IProject project) {
+ IResource parent = project.getParent();
+ ICElement celement = null;
+ if (parent instanceof IWorkspaceRoot) {
+ celement = create ((IWorkspaceRoot)parent);
+ }
+ return create(celement, project);
+ }
+
+ public synchronized ICElement create(ICElement parent, IProject project) {
+ ICElement celement = (ICElement)fParsedResources.get(project);
+ if (celement == null) {
+ if (hasCNature(project)) {
+ celement = new CProject(parent, project);
+ fParsedResources.put(project, celement);
+ }
+ }
+ return celement;
+ }
+
+ public ICElement create(IWorkspaceRoot root) {
+ ICElement celement = (ICElement)fParsedResources.get(root);
+ if (celement == null) {
+ celement = new CRoot(root);
+ fParsedResources.put(root, celement);
+ }
+ return celement;
+ }
+
+ public static void addCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ addNature(project, C_NATURE_ID, monitor);
+ }
+
+ public static void addCCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ addNature(project, CC_NATURE_ID, monitor);
+ }
+
+ public static void removeCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ removeNature(project, C_NATURE_ID, monitor);
+ }
+
+ public static void removeCCNature(IProject project, IProgressMonitor monitor) throws CModelException {
+ removeNature(project, CC_NATURE_ID, monitor);
+ }
+
+ /**
+ * Utility method for adding a nature to a project.
+ *
+ * @param proj the project to add the nature
+ * @param natureId the id of the nature to assign to the project
+ * @param monitor a progress monitor to indicate the duration of the operation, or
+ * null
if progress reporting is not required.
+ *
+ */
+ public static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CModelException {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] prevNatures= description.getNatureIds();
+ for (int i= 0; i < prevNatures.length; i++) {
+ if (natureId.equals(prevNatures[i]))
+ return;
+ }
+ String[] newNatures= new String[prevNatures.length + 1];
+ System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+ newNatures[prevNatures.length]= natureId;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, monitor);
+ } catch (CoreException e) {
+ throw new CModelException(e);
+ }
+ }
+
+ /**
+ * Utility method for removing a project nature from a project.
+ *
+ * @param proj the project to remove the nature from
+ * @param natureId the nature id to remove
+ * @param monitor a progress monitor to indicate the duration of the operation, or
+ * null
if progress reporting is not required.
+ */
+ public static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CModelException {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] prevNatures= description.getNatureIds();
+ List newNatures = new ArrayList(Arrays.asList(prevNatures));
+ newNatures.remove(natureId);
+ description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()]));
+ project.setDescription(description, monitor);
+ } catch (CoreException e) {
+ throw new CModelException(e);
+ }
+ }
+
+ private void removeChildrenContainer(Parent container, IResource resource) {
+ ICElement[] children = container.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ try {
+ IResource r = children[i].getUnderlyingResource();
+ if (r.equals(resource)) {
+//System.out.println("RELEASE Archive/binary " + children[i].getElementName());
+ container.removeChild(children[i]);
+ break;
+ }
+ } catch (CModelException e) {
+ }
+ }
+ }
+
+
+ public void releaseCElement(IResource resource) {
+ ICElement celement = getCElement(resource);
+ if (celement == null) {
+ if (resource.exists()) {
+ celement = create(resource);
+ } else {
+ // Make sure they are not in the Containers.
+ CProject cproj = (CProject)create(resource.getProject());
+ if (cproj != null) {
+ Parent container = (Parent)cproj.getArchiveContainer();
+ removeChildrenContainer(container, resource);
+ container = (Parent)cproj.getBinaryContainer();
+ removeChildrenContainer(container, resource);
+ }
+ }
+ }
+ releaseCElement(celement);
+ }
+
+ public void releaseCElement(ICElement celement) {
+
+ // Guard.
+ if (celement == null)
+ return;
+
+//System.out.println("RELEASE " + celement.getElementName());
+
+ // Remove from the containers.
+ if (celement.getElementType() == ICElement.C_FILE) {
+ CFile cfile = (CFile)celement;
+ if (cfile.isArchive()) {
+//System.out.println("RELEASE Archive " + cfile.getElementName());
+ CProject cproj = (CProject)cfile.getCProject();
+ ArchiveContainer container = (ArchiveContainer)cproj.getArchiveContainer();
+ container.removeChild(cfile);
+ } else if (cfile.isBinary()) {
+ if (! ((IBinary)celement).isObject()) {
+//System.out.println("RELEASE Binary " + cfile.getElementName());
+ CProject cproj = (CProject)cfile.getCProject();
+ BinaryContainer container = (BinaryContainer)cproj.getBinaryContainer();
+ container.removeChild(cfile);
+ }
+ }
+ }
+
+ Parent parent = (Parent)celement.getParent();
+ if (parent != null) {
+ parent.removeChild(celement);
+ }
+ fParsedResources.remove(celement);
+ }
+
+ public ICElement getCElement(IResource res) {
+ return (ICElement)fParsedResources.get(res);
+ }
+
+ public ICElement getCElement(IPath path) {
+ Iterator iterator = fParsedResources.keySet().iterator();
+ while (iterator.hasNext()) {
+ IResource res = (IResource)iterator.next();
+ if (res.getFullPath().equals(path)) {
+ return (ICElement)fParsedResources.get(res);
+ }
+ }
+ return null;
+ }
+
+ public static boolean isSharedLib(IFile file) {
+ try {
+ Elf.Attribute attribute = Elf.getAttributes(file.getLocation().toOSString());
+ if (attribute.getType() == Elf.Attribute.ELF_TYPE_SHLIB) {
+ return true;
+ }
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ public static boolean isObject(IFile file) {
+ try {
+ Elf.Attribute attribute = Elf.getAttributes(file.getLocation().toOSString());
+ if (attribute.getType() == Elf.Attribute.ELF_TYPE_OBJ) {
+ return true;
+ }
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ public static boolean isExecutable(IFile file) {
+ try {
+ Elf.Attribute attribute = Elf.getAttributes(file.getLocation().toOSString());
+ if (attribute.getType() == Elf.Attribute.ELF_TYPE_EXE) {
+ return true;
+ }
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ public static boolean isBinary(IFile file) {
+ try {
+ Elf.Attribute attribute = Elf.getAttributes(file.getLocation().toOSString());
+ if (attribute.getType() == Elf.Attribute.ELF_TYPE_EXE
+ || attribute.getType() == Elf.Attribute.ELF_TYPE_OBJ
+ || attribute.getType() == Elf.Attribute.ELF_TYPE_SHLIB) {
+ return true;
+ }
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ return false;
+ }
+
+ public static boolean isArchive(IFile file) {
+ AR ar = null;
+ try {
+ ar = new AR(file.getLocation().toOSString());
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ if (ar != null) {
+ ar.dispose();
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isTranslationUnit(IFile file) {
+ return isValidTranslationUnitName(file.getName());
+ }
+
+ public static boolean isValidTranslationUnitName(String name){
+ if (name == null) {
+ return false;
+ }
+ int index = name.lastIndexOf('.');
+ if (index == -1) {
+ return false;
+ }
+ String ext = name.substring(index + 1);
+ for (int i = 0; i < cExtensions.length; i++) {
+ if (ext.equals(cExtensions[i]))
+ return true;
+ }
+ return false;
+ }
+
+ /* Only project with C nature and Open. */
+ public static boolean hasCNature (IProject p) {
+ boolean ok = false;
+ try {
+ ok = (p.isOpen() && p.hasNature(C_NATURE_ID));
+ } catch (CoreException e) {
+ //throws exception if the project is not open.
+ //System.out.println (e);
+ //e.printStackTrace();
+ }
+ return ok;
+ }
+
+ /* Only project with C++ nature and Open. */
+ public static boolean hasCCNature (IProject p) {
+ boolean ok = false;
+ try {
+ ok = (p.isOpen() && p.hasNature(CC_NATURE_ID));
+ } catch (CoreException e) {
+ //throws exception if the project is not open.
+ //System.out.println (e);
+ //e.printStackTrace();
+ }
+ return ok;
+ }
+
+ /**
+ * addElementChangedListener method comment.
+ */
+ public synchronized void addElementChangedListener(IElementChangedListener listener) {
+ if (fElementChangedListeners.indexOf(listener) < 0) {
+ fElementChangedListeners.add(listener);
+ }
+ }
+
+ /**
+ * removeElementChangedListener method comment.
+ */
+ public synchronized void removeElementChangedListener(IElementChangedListener listener) {
+ 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 IResourceDeltas
+ * are to be registered with #registerResourceDelta
.
+ */
+ public synchronized 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 IResourceDeltas
into ICElementDeltas
.
+ *
+ * @see IResourceDelta
+ * @see IResource
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+
+ if (event.getSource() instanceof IWorkspace) {
+ IResource resource = event.getResource();
+ IResourceDelta delta = event.getDelta();
+ switch(event.getType()){
+ case IResourceChangeEvent.PRE_DELETE :
+ if(resource.getType() == IResource.PROJECT
+ && hasCNature((IProject)resource)) {
+ releaseCElement(resource);
+ }
+ break;
+
+ case IResourceChangeEvent.PRE_AUTO_BUILD :
+ // will close project if affected by the property file change
+ break;
+
+ case IResourceChangeEvent.POST_CHANGE :
+ if (delta != null) {
+ try {
+ ICElementDelta[] translatedDeltas = fDeltaProcessor.processResourceDelta(delta);
+ if (translatedDeltas.length > 0) {
+ for (int i= 0; i < translatedDeltas.length; i++) {
+ registerCModelDelta(translatedDeltas[i]);
+ }
+ }
+ fire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Note that the project is about to be deleted.
+ *
+ * fix for 1FW67PA
+ */
+ public void deleting(IResource resource) {
+ deleting(getCElement(resource));
+ }
+
+ public void deleting(ICElement celement) {
+ releaseCElement(celement);
+ }
+
+ /**
+ * Fire C Model deltas, flushing them after the fact.
+ * If the firing mode has been turned off, this has no effect.
+ */
+ public synchronized void fire() {
+ if (fFire) {
+ mergeDeltas();
+ try {
+ Iterator iterator = fCModelDeltas.iterator();
+ while (iterator.hasNext()) {
+ ICElementDelta delta= (ICElementDelta) iterator.next();
+
+ // Refresh internal scopes
+
+ ElementChangedEvent event= new ElementChangedEvent(delta);
+ // Clone the listeners since they could remove themselves when told about the event
+ // (eg. a type hierarchy becomes invalid (and thus it removes itself) when the type is removed
+ ArrayList listeners= (ArrayList) fElementChangedListeners.clone();
+ for (int i= 0; i < listeners.size(); i++) {
+ IElementChangedListener listener= (IElementChangedListener) listeners.get(i);
+ listener.elementChanged(event);
+ }
+ }
+ } finally {
+ // empty the queue
+ this.flush();
+ }
+ }
+ }
+
+ /**
+ * Flushes all deltas without firing them.
+ */
+ protected synchronized void flush() {
+ fCModelDeltas= new ArrayList();
+ }
+
+ /**
+ * Merged all awaiting deltas.
+ */
+ private void mergeDeltas() {
+ if (fCModelDeltas.size() <= 1)
+ return;
+
+ Iterator deltas = fCModelDeltas.iterator();
+ ICElement cRoot = getCRoot();
+ CElementDelta rootDelta = new CElementDelta(cRoot);
+ boolean insertedTree = false;
+ while (deltas.hasNext()) {
+ CElementDelta delta = (CElementDelta)deltas.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){
+ fCModelDeltas = new ArrayList(1);
+ fCModelDeltas.add(rootDelta);
+ } else {
+ fCModelDeltas = new ArrayList(0);
+ }
+ }
+
+ /**
+ * 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
+ getCRoot().getUnderlyingResource().getWorkspace().run(operation, 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();
+ } // else deltas are fired while processing the resource delta
+ }
+ }
+}
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
new file mode 100644
index 00000000000..95117b3699c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelOperation.java
@@ -0,0 +1,553 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ICRoot;
+import org.eclipse.cdt.core.model.ICModelStatus;
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.CModelException;
+
+/**
+ * Defines behavior common to all C Model operations
+ */
+public abstract class CModelOperation implements IWorkspaceRunnable, IProgressMonitor {
+ /**
+ * The elements this operation operates on,
+ * or null
if this operation
+ * does not operate on specific elements.
+ */
+ protected ICElement[] fElementsToProcess;
+
+ /**
+ * The parent elements this operation operates with
+ * or null
if this operation
+ * does not operate with specific parent elements.
+ */
+ protected ICElement[] fParentElements;
+
+ /**
+ * An empty collection of ICElement
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 ICElementDelta
s created by this operation.
+ * This collection starts out null
and becomes an
+ * array of ICElementDelta
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;
+
+ /**
+ * 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;
+ }
+ }
+
+ /**
+ * @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 #verify
and
+ * executeOperation
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 null
if not applicable.
+ */
+ protected ICElement[] getElementsToProcess() {
+ return fElementsToProcess;
+ }
+
+ /**
+ * Returns the element to which this operation applies,
+ * or null
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 ICRoot getCRoot() {
+ if (fElementsToProcess == null || fElementsToProcess.length == 0) {
+ return getParentElement().getCRoot();
+ } else {
+ return fElementsToProcess[0].getCRoot();
+ }
+ }
+
+ /**
+ * Returns the parent element to which this operation applies,
+ * or null
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 null
if not applicable.
+ */
+ protected ICElement[] getParentElements() {
+ return fParentElements;
+ }
+
+ /**
+ * Returns the elements created by this operation.
+ */
+ public ICElement[] getResultElements() {
+ return fResultElements;
+ }
+
+ /**
+ * 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 IWorkspace
this operation is working in, or
+ * null
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.getCRoot().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 true
if this operation performs no resource modifications,
+ * otherwise false
. 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 ICElementDelta
+ * on the C Model.
+ */
+ public CElementDelta newCElementDelta() {
+ return new CElementDelta(getCRoot());
+ }
+
+ /**
+ * 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 {
+ try {
+ fMonitor = monitor;
+ execute();
+ } finally {
+ registerDeltas();
+ }
+ }
+
+ /**
+ * @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
new file mode 100644
index 00000000000..0e9588f6ea8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelStatus.java
@@ -0,0 +1,259 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.resources.IResourceStatus;
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+import org.eclipse.cdt.core.model.ICModelStatus;
+import org.eclipse.cdt.core.model.ICElement;
+
+import org.eclipse.cdt.core.model.CoreModel;
+
+/**
+ * @see ICModelStatus
+ */
+
+public class CModelStatus extends Status implements ICModelStatus, ICModelStatusConstants, IResourceStatus {
+
+ // FIXME: Use the value in the plugin.
+ private static String PLUGIN_ID = CoreModel.getPluginId();
+
+ /**
+ * The elements related to the failure, or null
+ * if no elements are involved.
+ */
+ protected ICElement[] fElements = new ICElement[0];
+ /**
+ * The path related to the failure, or null
+ * if no path is involved.
+ */
+ protected IPath fPath;
+ /**
+ * The String
related to the failure, or null
+ * if no String
is involved.
+ */
+ protected String fString;
+ /**
+ * Empty children
+ */
+ protected final static IStatus[] fgEmptyChildren = new IStatus[] {};
+ protected IStatus[] fChildren= fgEmptyChildren;
+
+ /**
+ * Singleton OK object
+ */
+ public static final ICModelStatus VERIFIED_OK = new CModelStatus(OK);
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus() {
+ // no code for an multi-status
+ super(ERROR, PLUGIN_ID, 0, "CModelStatus", null); //$NON-NLS-1$
+ }
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus(int code) {
+ super(ERROR, PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
+ //fElements= CElementInfo.fgEmptyChildren;
+ }
+
+ /**
+ * Constructs an C model status with the given corresponding
+ * elements.
+ */
+ public CModelStatus(int code, ICElement[] elements) {
+ super(ERROR, PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
+ fElements= elements;
+ fPath= null;
+ }
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus(int code, String string) {
+ super(ERROR, PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
+ //fElements= CElementInfo.fgEmptyChildren;
+ fPath= null;
+ fString = string;
+ }
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus(int code, Throwable throwable) {
+ super(ERROR, PLUGIN_ID, code, "CModelStatus", throwable); //$NON-NLS-1$
+ //fElements= CElementInfo.fgEmptyChildren;
+ }
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus(int code, IPath path) {
+ super(ERROR, PLUGIN_ID, code, "CModelStatus", null); //$NON-NLS-1$
+ //fElements= CElementInfo.fgEmptyChildren;
+ 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;
+ }
+
+ /**
+ * Constructs an C model status with no corresponding elements.
+ */
+ public CModelStatus(CoreException coreException) {
+ super(ERROR, PLUGIN_ID, CORE_EXCEPTION, "CModelStatus", coreException); //$NON-NLS-1$
+ //fElements= CElementInfo.fgEmptyChildren;
+ }
+
+ 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() {
+ return "Error in C Plugin";
+ }
+ /**
+ * @see IOperationStatus
+ */
+ public IPath getPath() {
+ 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() {
+ return fString;
+ }
+
+ /**
+ * @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 ICModelStatus
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
new file mode 100644
index 00000000000..c41784556fd
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProject.java
@@ -0,0 +1,69 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+import org.eclipse.cdt.core.model.IArchiveContainer;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+
+public class CProject extends CResource implements ICProject {
+
+ boolean elfDone = false;
+
+ public CProject (ICElement parent, IProject project) {
+ super (parent, project, CElement.C_PROJECT);
+ }
+
+ public IBinaryContainer getBinaryContainer() {
+ return getCProjectInfo().getBinaryContainer();
+ }
+
+ public IArchiveContainer getArchiveContainer() {
+ return getCProjectInfo().getArchiveContainer();
+ }
+
+ public IProject getProject() {
+ try {
+ return getUnderlyingResource().getProject();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public ICProject getCProject() {
+ return this;
+ }
+
+ public ICElement findElement(IPath path) throws CModelException {
+ ICElement celem = CModelManager.getDefault().create(path);
+ if (celem == null)
+ new CModelStatus(ICModelStatusConstants.INVALID_PATH, path);
+ return celem;
+ }
+
+ synchronized protected boolean hasRunElf() {
+ return elfDone;
+ }
+
+ synchronized protected void setRunElf(boolean done) {
+ elfDone = done;
+ }
+
+ protected CProjectInfo getCProjectInfo() {
+ return (CProjectInfo)getElementInfo();
+ }
+
+ protected CElementInfo createElementInfo() {
+ return new CProjectInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..0a0e1e3e62e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CProjectInfo.java
@@ -0,0 +1,52 @@
+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.IArchiveContainer;
+import org.eclipse.cdt.core.model.IBinaryContainer;
+
+/**
+ * Info for ICProject.
+ */
+
+class CProjectInfo extends CResourceInfo {
+
+ private BinaryContainer vBin;
+ private ArchiveContainer vLib;
+
+ public IBinaryContainer getBinaryContainer() {
+ if (vBin == null) {
+ vBin = new BinaryContainer((CProject)getElement());
+ addChild(vBin);
+ }
+ return vBin;
+ }
+
+ public IArchiveContainer getArchiveContainer() {
+ if (vLib == null) {
+ vLib = new ArchiveContainer((CProject)getElement());
+ addChild(vLib);
+ }
+ return vLib;
+ }
+
+ public ICElement[] getChildren() {
+ // ensure that BinaryContqainer and ArchiveContainer
+ // have been added as children. Side affect of get methods!
+ getBinaryContainer();
+ getArchiveContainer();
+ return super.getChildren();
+ }
+
+ /**
+ */
+ public CProjectInfo(CElement element) {
+ super(element);
+ vBin = null;
+ vLib = null;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResource.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResource.java
new file mode 100644
index 00000000000..abb010c5ff1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResource.java
@@ -0,0 +1,40 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.CModelException;
+
+public abstract class CResource extends Parent {
+
+ public CResource (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 CResource (ICElement parent, IResource resource, int type) {
+ this (parent, resource, resource.getName(), type);
+ }
+
+ public CResource (ICElement parent, IResource resource, String name, int type) {
+ super (parent, resource, name, type);
+ }
+
+ public IResource getUnderlyingResource() throws CModelException {
+ return resource;
+ }
+
+ public IResource getCorrespondingResource() throws CModelException {
+ return resource;
+ }
+
+ protected abstract CElementInfo createElementInfo ();
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java
new file mode 100644
index 00000000000..41ec313a1b4
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CResourceInfo.java
@@ -0,0 +1,70 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.cdt.core.model.ICElement;
+
+/**
+ */
+public class CResourceInfo extends CElementInfo {
+
+ /**
+ * Constructs a new C Model Info
+ */
+ protected CResourceInfo(CElement element) {
+ super(element);
+ }
+
+ // Always return true, save the unnecessary probing from the Treeviewer.
+ protected boolean hasChildren () {
+ return true;
+ }
+
+ protected ICElement [] getChildren () {
+ try {
+ IResource[] resources = null;
+ IResource res = getElement().getUnderlyingResource();
+ if (res != null) {
+ //System.out.println (" Resource: " + res.getFullPath().toOSString());
+ switch(res.getType()) {
+ case IResource.ROOT:
+ case IResource.PROJECT:
+ case IResource.FOLDER:
+ IContainer container = (IContainer)res;
+ resources = container.members(false);
+ break;
+
+ case IResource.FILE:
+ break;
+ }
+ }
+
+ if (resources != null) {
+ CModelManager factory = CModelManager.getDefault();
+ for (int i = 0; i < resources.length; i++) {
+ // Check for Valid C projects only.
+ if(resources[i].getType() == IResource.PROJECT) {
+ IProject proj = (IProject)resources[i];
+ if (!factory.hasCNature(proj)) {
+ continue;
+ }
+ }
+ addChild(factory.create(getElement(), resources[i]));
+ }
+ }
+ } catch (CoreException e) {
+ //System.out.println (e);
+ //CPlugin.log (e);
+ e.printStackTrace();
+ }
+ return super.getChildren();
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java
new file mode 100644
index 00000000000..8d573a8b6c7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRoot.java
@@ -0,0 +1,113 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ICRoot;
+import org.eclipse.cdt.core.model.CModelException;
+
+public class CRoot extends CResource implements ICRoot {
+
+ public CRoot(IWorkspaceRoot root) {
+ super (null, root, root.getName(), ICElement.C_ROOT);
+ }
+
+ public ICRoot getCModel() {
+ return this;
+ }
+ public ICProject getCProject(String name) {
+ CModelManager factory = CModelManager.getDefault();
+ return (ICProject)factory.create(getWorkspace().getRoot().getProject(name));
+ }
+
+ public ICProject[] getCProjects() {
+ return (ICProject[])getChildren();
+ }
+
+ public IWorkspace getWorkspace() {
+ try {
+ return getUnderlyingResource().getWorkspace();
+ } catch (CModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public IWorkspaceRoot getRoot() {
+ try {
+ return (IWorkspaceRoot)getUnderlyingResource();
+ } catch (CModelException e) {
+ }
+ return null;
+ }
+
+ 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].getCorrespondingResource() != null ) {
+ 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].getCorrespondingResource() != null) {
+ 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].getCorrespondingResource() == null) {
+ 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].getCorrespondingResource() == null) {
+ 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 MultiOperation
.
+ */
+ 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 CRootInfo(this);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java
new file mode 100644
index 00000000000..7baefdef5c6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CRootInfo.java
@@ -0,0 +1,19 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * @see ICModel
+ */
+public class CRootInfo extends CResourceInfo {
+
+ /**
+ * Constructs a new C Model Info
+ */
+ protected CRootInfo(CElement element) {
+ super(element);
+ }
+}
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
new file mode 100644
index 00000000000..80fe7b62e8c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CopyElementsOperation.java
@@ -0,0 +1,218 @@
+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.IParent;
+import org.eclipse.cdt.core.model.ICModelStatus;
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+import org.eclipse.cdt.core.model.CModelException;
+
+/**
+ * This operation copies/moves a collection of elements from their current
+ * container to a new container, optionally renaming the
+ * elements.
+ * Notes:
String
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:
+ * element
or its specified destination is
+ * is null
or does not exist. If a null
element is
+ * supplied, no element is provided in the status, otherwise, the non-existant element
+ * is supplied in the status.
+ * element
is not contained within a compilation unit.
+ * This operation only operates on elements contained within compilation units.
+ * element
is read only.
+ * element
+ * 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 element
.
+ * element
does not have valid syntax.
+ * In this case the element and name are provided in the status.
+
+ * Notes:
CElementDelta
for cProject
,
+ * creating it and putting it in fDeltasPerProject
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 operationnewName
+ * to the destination package.processResource
or
+ * processPackageFragmentResource
, depending on the type of
+ * element
.
+ */
+ protected void processElement(ICElement element) throws CModelException {
+ ICElement dest = getDestinationParent(element);
+ if (element.getCorrespondingResource() != null) {
+ 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 CElementDelta
s
+ * and fResultElements
.
+ */
+ 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:
+ * This abstract class implements behavior common to CreateElementInCUOperations
.
+ * 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.
+ *
+ *
The element being created can be positioned relative to an existing
+ * element in the compilation unit via the methods #createAfter
+ * and #createBefore
. 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 fAnchorElement
.
+ */
+ protected static final int INSERT_AFTER = 2;
+
+ /**
+ * A constant meaning to position the new element
+ * before the element defined by fAnchorElement
.
+ */
+ 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
+ * fInsertPosition
, or null
+ * 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 false
. 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 null
.
+ */
+ 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 null
.
+ */
+ 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();
+ insertElement();
+ if (fCreationOccurred) {
+ //a change has really occurred
+ IFile file = (IFile)unit.getCorrespondingResource();
+ StringBuffer buffer = getContent(file);
+ switch (fReplacementLength) {
+ case -1 :
+ // element is append at the end
+ buffer.append(fCreatedElement.getSource());
+ break;
+
+ case 0 :
+ // element is inserted
+ buffer.insert(fInsertionPosition, fCreatedElement.getSource());
+ break;
+
+ default :
+ // element is replacing the previous one
+ buffer.replace(fInsertionPosition, fReplacementLength, fCreatedElement.getSource());
+ }
+ save(buffer, file);
+ 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 DOMNode
that will be used to
+ * create this new element.
+ * Used by the CopyElementsOperation
for renaming.
+ * Only used for CreateTypeMemberOperation
+ */
+ 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 null
. The position
+ * 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:
null
.
+ * This operation creates a field declaration in a type. + * + *
Required Attributes:
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 new file mode 100644 index 00000000000..d00f25c0167 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateFunctionDeclarationOperation.java @@ -0,0 +1,96 @@ +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; + +/** + *
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). + * + *
Required Attributes:
"stdio.h"
+ * null
.
+ * 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). + * + *
Required Attributes:
"stdio.h"
+ * null
.
+ * DOMNode
that may be used to
+ * create this new element.
+ * Used by the CopyElementsOperation
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 DOMNode
that will be used to
+ * create this new element.
+ * Used by the CopyElementsOperation
for renaming
+ */
+ protected void setAlteredName(String newName) {
+ fAlteredName = newName;
+ }
+
+ /**
+ * Possible failures: null
.
+ * null
or has serious syntax errors.
+ * This operation creates an instance method. + * + *
Required Attributes:
null
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 deleteResource
or
+ * deletePackageFragment
depending on the type of element
.
+ */
+ protected void processElement(ICElement element) throws CModelException {
+ deleteResource(element.getCorrespondingResource(), 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
new file mode 100644
index 00000000000..8e336fcb61c
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
@@ -0,0 +1,388 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICElementDelta;
+import org.eclipse.cdt.core.model.ICRoot;
+import org.eclipse.cdt.core.model.ICModelStatusConstants;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+
+/**
+ * This class is used by CModelManager
to convert
+ * IResourceDelta
s into ICElementDelta
s.
+ * It also does some processing on the CElement
s involved
+ * (e.g. closing them or updating classpaths).
+ */
+public class DeltaProcessor {
+
+ /**
+ * The CElementDelta
corresponding to the IResourceDelta
being translated.
+ */
+ protected CElementDelta fCurrentDelta;
+
+ /* 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;
+
+ /**
+ * Generic processing for elements with changed contents:basicElementAdded
.
+ * 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) { + + if (element.getElementType() == ICElement.C_PROJECT) { + // treat project closing as removal + elementRemoved(element, delta); + } else { + fCurrentDelta.closed(element); + } + } + + /** + * Processing for the opening of an element - there are two cases:
CElementDelta
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;
+ } else {
+ 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.getDefault().hasCNature(project);
+ }
+ return false;
+ }
+
+
+ private CModelException newInvalidElementType() {
+ return new CModelException(new CModelStatus(ICModelStatusConstants.INVALID_ELEMENT_TYPES));
+ }
+
+ /**
+ * Converts a IResourceDelta
rooted in a Workspace
into
+ * the corresponding set of ICElementDelta
, rooted in the
+ * relevant CRoot
s.
+ */
+ public ICElementDelta[] processResourceDelta(IResourceDelta changes) {
+
+ try {
+ ICElement root = (ICRoot)CModelManager.getDefault().getCRoot();
+ currentElement = null;
+
+/*
+ try {
+ changes.accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) {
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED :
+ // handle added resource
+ System.out.print("ADDED ");
+ break;
+ case IResourceDelta.REMOVED :
+ // handle removed resource
+ System.out.print("REMOVED ");
+ break;
+ case IResourceDelta.CHANGED :
+ // handle changed resource
+ System.out.print("CHANGED ");
+ break;
+ }
+ System.out.println(delta.getResource());
+ return true;
+ }
+ });
+ } catch (CoreException e) {
+ }
+*/
+ // get the workspace delta, and start processing there.
+ IResourceDelta[] deltas = changes.getAffectedChildren();
+ ICElementDelta[] translatedDeltas = new CElementDelta[deltas.length];
+ for (int i = 0; i < deltas.length; i++) {
+ IResourceDelta delta = deltas[i];
+ fCurrentDelta = new CElementDelta(root);
+ traverseDelta(delta); // traverse delta
+ translatedDeltas[i] = fCurrentDelta;
+ }
+ return filterRealDeltas(translatedDeltas);
+ } finally {
+ }
+ }
+
+ /**
+ * Converts an IResourceDelta
and its children into
+ * the corresponding ICElementDelta
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(IResourceDelta delta) {
+ try {
+ if (!updateCurrentDeltaAndIndex(delta)) {
+ fCurrentDelta.addResourceDelta(delta);
+ }
+ } catch (CModelException e) {
+ }
+ IResourceDelta [] children = delta.getAffectedChildren();
+ for (int i = 0; i < children.length; i++) {
+ traverseDelta(children[i]);
+ }
+ }
+
+ /*
+ * 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(IResourceDelta delta) throws CModelException {
+
+ ICElement element = null;
+ IResource resource = delta.getResource();
+
+ boolean isProcess = false;
+
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED :
+ element = createElement(resource);
+ if (element == null)
+ throw newInvalidElementType();
+ updateIndexAddResource(element, delta);
+ elementAdded(element, delta);
+ isProcess = true;
+ break;
+
+ case IResourceDelta.REMOVED :
+ element = getElement(resource);
+ if (element != null) {
+ updateIndexRemoveResource(element, delta);
+ elementRemoved(element, delta);
+ isProcess = true;
+ } else {
+ releaseCElement(resource);
+ }
+ break;
+
+ case IResourceDelta.CHANGED :
+ element = createElement(resource);
+ if (element == null)
+ throw newInvalidElementType();
+ int flags = delta.getFlags();
+ if ((flags & IResourceDelta.CONTENT) != 0) {
+ // content has changed
+ contentChanged(element, delta);
+ updateIndexAddResource(element, delta);
+ } else if ((flags & IResourceDelta.OPEN) != 0) {
+ // project has been opened or closed
+ IProject res = (IProject)resource;
+ if (res.isOpen()) {
+ elementOpened(element, delta);
+ updateIndexAddResource(element, delta);
+ } else {
+ elementClosed(element, delta);
+ updateIndexRemoveResource(element, delta);
+ }
+ // when a project is open/closed don't process children
+ } else if ((flags & IResourceDelta.DESCRIPTION) != 0) {
+ elementAdded(element, delta);
+ } // else if ((flags * IResourceDelta.MARKERS) != 0) {}
+ // else if ((flags * IResourceDelta.TYPE) != 0) {}
+ // else if ((flags * IResourceDelta.SYNC) != 0) {}
+ isProcess = true;
+ break;
+ }
+ return isProcess;
+ }
+
+ protected void updateIndexAddResource(ICElement element, IResourceDelta delta) {
+ //CModelManager.getDefault().getIndexManager().addResource(delta.getResource());
+ }
+
+ protected void updateIndexRemoveResource(ICElement element, IResourceDelta delta) {
+ //CModelManager.getDefault().getIndexManager().removeResource(delta.getResource());
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElfRunner.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElfRunner.java
new file mode 100644
index 00000000000..9d2fdc928e7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ElfRunner.java
@@ -0,0 +1,99 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+
+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.ICElement;
+import org.eclipse.cdt.core.model.ICRoot;
+
+public class ElfRunner implements Runnable {
+ ArchiveContainer clib;
+ BinaryContainer cbin;
+ CProject cproject;
+
+ public ElfRunner(CProject cprj) {
+ cproject = cprj;
+ cbin = (BinaryContainer)cprj.getBinaryContainer();
+ clib = (ArchiveContainer)cprj.getArchiveContainer();
+ }
+
+ public void run() {
+ cproject.setRunElf(true);
+ clib.removeChildren();
+ cbin.removeChildren();
+ try {
+ cproject.getProject().accept(new Visitor(this));
+ } catch (CoreException e) {
+ //e.printStackTrace();
+ }
+ fireEvents(cbin);
+ fireEvents(clib);
+ }
+
+ public void fireEvents(Parent container) {
+ // Fired the event.
+ ICElement[] children = container.getChildren();
+ if (children.length > 0) {
+ CModelManager factory = CModelManager.getDefault();
+ ICElement root = (ICRoot)factory.getCRoot();
+ 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();
+ }
+ }
+
+ void addChildIfElf(CoreModel factory, IFile file) {
+ // Attempt to speed things up by rejecting up front
+ // Things we know should not be Elf/Binary files.
+ if (!factory.isTranslationUnit(file)) {
+ if (factory.isBinary(file)) {
+ ICElement celement = factory.create(file);
+ if (celement != null) {
+ if (celement instanceof IBinary) {
+ IBinary bin = (IBinary)celement;
+ if (bin.isExecutable() || bin.isSharedLib()) {
+ cbin.addChild(bin);
+ }
+ }
+ }
+ } else if (factory.isArchive(file)) {
+ ICElement celement = factory.create(file);
+ if (celement instanceof IArchive) {
+ clib.addChild(celement);
+ }
+ }
+ }
+ }
+
+ class Visitor implements IResourceVisitor {
+ CoreModel factory = CoreModel.getDefault();
+ ElfRunner runner;
+
+ public Visitor (ElfRunner r) {
+ runner = r;
+ }
+
+ public boolean visit(IResource res) throws CoreException {
+ if (res instanceof IFile) {
+ runner.addChildIfElf(factory, (IFile)res);
+ return false;
+ }
+ return true;
+ }
+ }
+}
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
new file mode 100644
index 00000000000..8ed88891b6e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Field.java
@@ -0,0 +1,74 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IField;
+
+public class Field extends SourceManipulation implements IField {
+
+ public Field(ICElement parent, String name) {
+ super(parent, name, CElement.C_FIELD);
+ }
+
+ public boolean isMutable() throws CModelException {
+ return false;
+ }
+
+ /*
+ * @IVariable
+ */
+ public String getType() {
+ return "";
+ }
+
+ /*
+ * @IVariable
+ */
+ public String getInitializer() {
+ return "";
+ }
+
+ /**
+ * Returns true if the member as class scope.
+ * For example static methods in C++ have class scope
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean hasClassScope() throws CModelException {
+ return false;
+ }
+
+ /**
+ * Returns whether this method/field is declared constant.
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean isConst() throws CModelException {
+ return false;
+ }
+
+ /**
+ * Returns the access Control of the member. The access qualifier
+ * can be examine using the AccessControl class.
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public int getAccessControl() throws CModelException {
+ return 0;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..64dffe6a9e5
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Function.java
@@ -0,0 +1,49 @@
+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.IFunction;
+
+public class Function extends SourceManipulation implements IFunction {
+
+ public Function(ICElement parent, String name) {
+ super(parent, name, CElement.C_FUNCTION);
+ }
+
+ public String[] getExceptions() throws CModelException {
+ return new String[] {};
+ }
+
+ public int getNumberOfParameters() {
+ return 0;
+ }
+
+ public String getParameterInitializer(int pos) {
+ return "";
+ }
+
+ public String[] getParameterTypes() {
+ return new String[0];
+ }
+
+ public String getReturnType() throws CModelException {
+ return "";
+ }
+
+ public int getAccessControl() throws CModelException {
+ return getFunctionInfo().getAccessControl();
+ }
+
+ public FunctionInfo getFunctionInfo() {
+ return (FunctionInfo)getElementInfo();
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new FunctionInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..123013ba0f8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionDeclaration.java
@@ -0,0 +1,45 @@
+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 {
+
+ public FunctionDeclaration(ICElement parent, String name) {
+ super(parent, name, CElement.C_FUNCTION_DECLARATION);
+ }
+
+ public String[] getExceptions() throws CModelException {
+ return new String[] {};
+ }
+
+ public int getNumberOfParameters() {
+ return 0;
+ }
+
+ public String getParameterInitializer(int pos) {
+ return "";
+ }
+
+ public String[] getParameterTypes() {
+ return new String[0];
+ }
+
+ public String getReturnType() throws CModelException {
+ return "";
+ }
+
+ public int getAccessControl() throws CModelException {
+ return 0;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..73a4e69f8ea
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionInfo.java
@@ -0,0 +1,24 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+class FunctionInfo extends SourceManipulationInfo {
+
+ protected int flags;
+
+ protected FunctionInfo (CElement element) {
+ super(element);
+ flags = 0;
+ }
+
+ protected int getAccessControl() {
+ return flags;
+ }
+
+ protected void setAccessControl(int flags) {
+ this.flags = flags;
+ }
+}
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
new file mode 100644
index 00000000000..b9d20660da9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IConstants.java
@@ -0,0 +1,39 @@
+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/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java
new file mode 100644
index 00000000000..39952fc68e6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java
@@ -0,0 +1,28 @@
+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 {
+
+ public Include(ICElement parent, String name) {
+ super(parent, name, CElement.C_INCLUDE);
+ }
+
+ public String getIncludeName() {
+ return "";
+ }
+
+ public boolean isStandard() {
+ return true;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..7c5ca6fae54
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Macro.java
@@ -0,0 +1,28 @@
+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 "";
+ }
+
+ public String getTokenSequence() {
+ return "";
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(this);
+ }
+}
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
new file mode 100644
index 00000000000..61f09dc93a1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Method.java
@@ -0,0 +1,124 @@
+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.IMethod;
+
+public class Method extends SourceManipulation implements IMethod {
+
+ public Method(ICElement parent, String name) {
+ super(parent, name, CElement.C_METHOD);
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isConstructor() throws CModelException {
+ return getElementName().equals(getParent().getElementName());
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isDestructor() throws CModelException {
+ return getElementName().startsWith("~");
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isOperator() throws CModelException {
+ return getElementName().startsWith("operator");
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isAbstract() throws CModelException {
+ return false;
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isVirtual() throws CModelException {
+ return false;
+ }
+
+ /**
+ * @see IMethod
+ */
+ public boolean isFriend() throws CModelException {
+ return false;
+ }
+
+ /**
+ * @see IMethod
+ */
+ public String[] getExceptions() {
+ return new String[0];
+ }
+
+ /**
+ * @see IMethod
+ */
+ public int getNumberOfParameters() {
+ return 0;
+ }
+
+ public String getParameterInitializer(int pos) {
+ return "";
+ }
+
+ public String[] getParameterTypes() {
+ return new String[0];
+ }
+
+ public String getReturnType() throws CModelException {
+ return "";
+ }
+
+ /**
+ * Returns true if the member as class scope.
+ * For example static methods in C++ have class scope
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean hasClassScope() throws CModelException {
+ return false;
+ }
+
+ /**
+ * Returns whether this method/field is declared constant.
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public boolean isConst() throws CModelException {
+ return false;
+ }
+
+ /**
+ * Returns the access Control of the member. The access qualifier
+ * can be examine using the AccessControl class.
+ *
+ * @see IMember
+ * @exception CModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ */
+ public int getAccessControl() throws CModelException {
+ return 0;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(this);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java
new file mode 100644
index 00000000000..fe00f7d662b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ModelBuilder.java
@@ -0,0 +1,183 @@
+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.internal.parser.IStructurizerCallback;
+
+public class ModelBuilder implements IStructurizerCallback {
+
+ private TranslationUnit fCurrFile;
+ private CElement fCurrElement;
+
+ public ModelBuilder(TranslationUnit file) {
+ fCurrFile = file;
+ fCurrElement = file;
+ }
+
+ private final int fixLength(int startPos, int endPos) {
+ if (endPos < startPos) {
+ return 0;
+ } else {
+ return endPos - startPos + 1;
+ }
+ }
+
+ public void includeDecl(String name, int startPos, int endPos, int startLine, int endLine) {
+ Include elem= new Include(fCurrFile, name);
+ elem.setPos(startPos, fixLength(startPos, endPos));
+ elem.setIdPos(startPos, fixLength(startPos, endPos));
+ elem.setLines(startLine, endLine);
+
+ fCurrFile.addChild(elem);
+ }
+
+ public void defineDecl(String name, int startPos, int endPos, int startLine, int endLine) {
+ Macro elem= new Macro(fCurrFile, name);
+ elem.setPos(startPos, fixLength(startPos, endPos));
+ elem.setIdPos(startPos, fixLength(startPos, endPos));
+ elem.setLines(startLine, endLine);
+ fCurrFile.addChild(elem);
+ }
+
+ public void functionDeclBegin(String name, int nameStartPos, int nameEndPos,
+ int declStartPos, int startPos, int type, int modifiers) {
+ //if (!assertCurrElement( new int[] { CElement.C_FILE, CElement.C_STRUCTURE, CElement.C_UNION, CElement.C_CLASS})) {
+ // return;
+ //}
+
+ CElement elem;
+ if (fCurrElement instanceof IStructure) {
+ elem = new Method(fCurrElement, name);
+ } else {
+ if(type == ICElement.C_FUNCTION_DECLARATION) {
+ elem = new FunctionDeclaration(fCurrElement, name);
+ } else {
+ elem= new Function(fCurrElement, name);
+ }
+ }
+ elem.setPos(declStartPos, 0);
+ elem.setIdPos(nameStartPos, fixLength(nameStartPos, nameEndPos));
+ elem.setLines(startPos, -1);
+
+ fCurrElement.addChild(elem);
+ fCurrElement= elem;
+ }
+
+ public void functionDeclEnd(int declEndPos, int endLine, boolean prototype) {
+ //if (!assertCurrElement( new int[] { CElement.C_FUNCTION })) {
+ // return;
+ //}
+ if(prototype == true && fCurrElement.getParent() instanceof Parent) {
+ // Need to delete the current function and create a new object
+ CElement elem, oldElem = fCurrElement;
+ elem = new FunctionDeclaration(fCurrElement.getParent(), fCurrElement.getElementName());
+ elem.setPos(oldElem.getStartPos(), 0);
+ elem.setIdPos(oldElem.getIdStartPos(), oldElem.getIdLength());
+ elem.setLines(oldElem.getStartLine(), -1);
+ ((Parent)fCurrElement.getParent()).addChild(elem);
+ ((Parent)fCurrElement.getParent()).removeChild(oldElem);
+ fCurrElement = elem;
+ }
+ int declStartPos= fCurrElement.getStartPos();
+ fCurrElement.setPos(declStartPos, fixLength(declStartPos, declEndPos));
+ int startLine = fCurrElement.getStartLine();
+ fCurrElement.setLines(startLine, endLine);
+ fCurrElement= (CElement)fCurrElement.getParent();
+ }
+
+ public void fieldDecl(String name, int nameStartPos, int nameEndPos, int declStartPos,
+ int declEndPos, int startLine, int endLine, int modifiers) {
+
+ CElement elem;
+ if (fCurrElement instanceof IStructure) {
+ elem = new Field(fCurrElement, name);
+ } else {
+ elem = new Variable(fCurrElement, name);
+ }
+//System.out.println(elem.toDebugString() + " --> " + fCurrElement.toDebugString());
+ elem.setPos(declStartPos, fixLength(declStartPos, declEndPos));
+ elem.setIdPos(nameStartPos, fixLength(nameStartPos, nameEndPos));
+ elem.setLines(startLine, endLine);
+
+ fCurrElement.addChild(elem);
+ }
+
+ public void structDeclBegin(String name, int kind, int nameStartPos, int nameEndPos,
+ int declStartPos, int startLine, int modifiers) {
+ //if (!assertCurrElement( new int[] { CElement.C_FILE, CElement.C_STRUCTURE, CElement.C_UNION, CElement.C_CLASS })) {
+ // return;
+ //}
+
+ if(isAnonymousStructure(name)) {
+ name = new String("[anonymous]");
+ }
+
+ Structure elem= new Structure(fCurrElement, kind, name);
+ elem.setPos(declStartPos, 0);
+ elem.setIdPos(nameStartPos, fixLength(nameStartPos, nameEndPos));
+ elem.setLines(startLine, -1);
+
+ fCurrElement.addChild(elem);
+ fCurrElement= elem;
+//System.out.println(elem.toDebugString() + " --> " + fCurrElement.toDebugString());
+ }
+
+
+ public void structDeclEnd(int declEndPos, int endLine) {
+ //assertCurrElement( new int[] { CElement.C_STRUCTURE, CElement.C_UNION, CElement.C_CLASS });
+ int declStartPos= fCurrElement.getStartPos();
+ fCurrElement.setPos(declStartPos, fixLength(declStartPos, declEndPos));
+ int startLine= fCurrElement.getStartLine();
+ fCurrElement.setLines(startLine, endLine);
+ fCurrElement= (CElement)fCurrElement.getParent();
+ }
+
+ public void superDecl(String name) {
+ //assertCurrElement( new int[] { CElement.C_STRUCTURE, CElement.C_UNION, CElement.C_CLASS });
+ if (fCurrElement instanceof IStructure) {
+ ((Structure)fCurrElement).addSuperClass(name);
+ }
+ }
+
+ public void reportError(Throwable throwable) {
+ // System.out.println("ModelBuilder: error " + throwable.getMessage());
+ }
+
+ private boolean assertCurrElement(int[] acceptedTypes) {
+ boolean isOk= false;
+ int currType= fCurrElement.getElementType();
+ for (int i= 0; i < acceptedTypes.length; i++) {
+ if (currType == acceptedTypes[i]) {
+ isOk= true;
+ }
+ }
+
+ if (!isOk) {
+ StringBuffer buf= new StringBuffer();
+ buf.append("ModelBuilder: type check failed, is: ");
+ buf.append(CElement.getTypeString(currType));
+ buf.append(", should be [ ");
+ for (int i= 0; i < acceptedTypes.length; i++) {
+ buf.append(CElement.getTypeString(acceptedTypes[i]));
+ buf.append(" ");
+ }
+ buf.append("]");
+
+ //CPlugin.getPlugin().logErrorStatus(buf.toString(), null);
+ }
+ return isOk;
+ }
+
+ private boolean isAnonymousStructure(String name) {
+ if (Character.isJavaIdentifierStart(name.charAt(0))) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
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
new file mode 100644
index 00000000000..8152f58e0e0
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MoveResourceElementsOperation.java
@@ -0,0 +1,40 @@
+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.
+ * 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
new file mode 100644
index 00000000000..4ae5aaec649
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MultiOperation.java
@@ -0,0 +1,297 @@
+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 ICElement
.
+ * It is responible for running each operation in turn, collecting
+ * the errors and merging the corresponding CElementDelta
s.
+ *
+ * If several errors occured, they are collected in a multi-status
+ * CModelStatus
. Otherwise, a simple CModelStatus
+ * 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 fRenamingList
in a more
+ * convenient way.
+ */
+ protected Map fRenamings;
+
+ /**
+ * Creates a new MultiOperation
.
+ */
+ 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 MultiOperation
on elementsToProcess
.
+ */
+ protected MultiOperation(ICElement[] elementsToProcess, boolean force) {
+ super(elementsToProcess, force);
+ }
+
+ /**
+ * Convenience method to create a CModelException
+ * embending a CModelStatus
.
+ */
+ 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 CModelStatus
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 element
, or null
+ * 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 true
if this operation represents a move or rename, false
+ * if this operation represents a copy.
+ * Note: a rename is just a move within the same parent with a name change.
+ */
+ protected boolean isMove() {
+ return false;
+ }
+
+ /**
+ * Returns true
if this operation represents a rename, false
+ * 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 ICElement
.
+ */
+ protected abstract void processElement(ICElement element) throws CModelException;
+
+ /**
+ * Processes all the ICElement
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 null
, 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 null
entry in the list indicates that an element
+ * is not to be renamed.
+ *
+ *
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 ICElement
before
+ * processElement
. It should check that this element
+ * can be processed.
+ */
+ protected abstract void verify(ICElement element) throws CModelException;
+
+ /**
+ * Verifies that the destination
specified for the element
is valid for the types of the
+ * element
and destination
.
+ */
+ 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 element
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 element
is exists and
+ * its parent is the destination container of this element
.
+ */
+ 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/Parent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java
new file mode 100644
index 00000000000..95f4fb7c7b6
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Parent.java
@@ -0,0 +1,98 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IParent;
+import org.eclipse.cdt.core.model.CModelException;
+
+public abstract class Parent extends CElement implements IParent {
+
+ protected IResource resource;
+
+ public Parent (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 Parent (ICElement parent, String name, int type) {
+ this (parent, null, name, type);
+ }
+
+ public Parent (ICElement parent, IResource resource, String name, int type) {
+ super (parent, name, type);
+ this.resource = resource;
+ }
+
+ // members
+
+ /**
+ * Adds a child to the current element.
+ * Implementations override this method to support children
+ */
+ protected void addChild(ICElement member) {
+ getElementInfo().addChild(member);
+ }
+
+ /**
+ * Removes a child to the current element.
+ * Implementations override this method to support children
+ */
+ protected void removeChild(ICElement member) {
+ getElementInfo().removeChild(member);
+ }
+
+ protected void removeChildren () {
+ 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() {
+ return getElementInfo().getChildren();
+ }
+
+ public boolean hasChildren () {
+ return getElementInfo().hasChildren();
+ }
+
+ public void setUnderlyingResource(IResource res) {
+ resource = res;
+ }
+
+ public IResource getUnderlyingResource() throws CModelException {
+ if (resource == null) {
+ ICElement p = getParent();
+ if (p != null) {
+ return p.getUnderlyingResource();
+ }
+ }
+ return resource;
+ }
+
+ public IResource getCorrespondingResource() throws CModelException {
+ return null;
+ }
+
+ protected void setChanged () {
+ getElementInfo().setChanged();
+ }
+
+ protected boolean hasChanged () {
+ return getElementInfo().hasChanged();
+ }
+
+ protected abstract CElementInfo createElementInfo ();
+}
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
new file mode 100644
index 00000000000..6c4da177eff
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/RenameResourceElementsOperation.java
@@ -0,0 +1,52 @@
+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).
+ *
+ *
Notes:
String
+ */
+ protected int fSourceLength;
+
+ /**
+ * Timestamp of original resource at the time this element
+ * was opened or last updated.
+ */
+ protected long fTimestamp;
+
+ protected TranslationUnitInfo (CElement element) {
+ super(element);
+ }
+
+ protected boolean hasChildren() {
+ return true;
+ }
+
+ protected ICElement [] getChildren() {
+ if (hasChanged()) {
+ InputStream in = null;
+ try {
+ IResource res = getElement().getUnderlyingResource();
+ if (res != null && res.getType() == IResource.FILE) {
+ in = ((IFile)res).getContents();
+ parse(in);
+ }
+ } catch (CoreException e) {
+ //e.printStackTrace();
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ }
+ return super.getChildren();
+ }
+
+ protected void parse(InputStream in) {
+ try {
+ removeChildren();
+ ModelBuilder modelBuilder= new ModelBuilder((TranslationUnit)getElement());
+ CStructurizer.getCStructurizer().parse(modelBuilder, in);
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ }
+
+ /* 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/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
new file mode 100644
index 00000000000..89f9c8fb8a7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
@@ -0,0 +1,117 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+
+public class Util {
+
+ 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
+ }
+}
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
new file mode 100644
index 00000000000..13b870457e8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Variable.java
@@ -0,0 +1,36 @@
+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 SourceManipulation implements IVariable {
+
+ public Variable(ICElement parent, String name) {
+ super(parent, name, CElement.C_VARIABLE);
+ }
+
+ public String getType() {
+ return "";
+ }
+
+ public String getInitializer() {
+ return "";
+ }
+
+ public int getAccessControl() {
+ return getVariableInfo().getAccessControl();
+ }
+
+ protected VariableInfo getVariableInfo() {
+ 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/VariableDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java
new file mode 100644
index 00000000000..bc3fb29c075
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableDeclaration.java
@@ -0,0 +1,28 @@
+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.IVariableDeclaration;
+
+public class VariableDeclaration extends SourceManipulation implements IVariableDeclaration {
+
+ public VariableDeclaration(ICElement parent, String name) {
+ super(parent, name, CElement.C_VARIABLE_DECLARATION);
+ }
+
+ public String getType() {
+ return "";
+ }
+
+ public int getAccesControl() {
+ return 0;
+ }
+
+ protected CElementInfo createElementInfo () {
+ return new SourceManipulationInfo(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
new file mode 100644
index 00000000000..14ebea22877
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableInfo.java
@@ -0,0 +1,24 @@
+package org.eclipse.cdt.internal.core.model;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+class VariableInfo extends SourceManipulationInfo {
+
+ protected int flags;
+
+ protected VariableInfo (CElement element) {
+ super(element);
+ flags = 0;
+ }
+
+ protected int getAccessControl() {
+ return flags;
+ }
+
+ protected void setAccessControl(int flags) {
+ this.flags = flags;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/plugin.properties b/core/org.eclipse.cdt.core/plugin.properties
new file mode 100644
index 00000000000..6a5e3be2c8b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/plugin.properties
@@ -0,0 +1,12 @@
+#########################################
+# (c) Copyright IBM Corp. 2000, 2001.
+# All Rights Reserved.
+#########################################
+
+pluginName=C Development Tools Core
+
+cnature.name=C Nature
+ccnature.name=C++ Nature
+CProblemMarker.name=C Problem
+CBuildCommand.name=C Builder Command
+
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
new file mode 100644
index 00000000000..a3938f93df8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -0,0 +1,87 @@
+
+null
if progress reporting is not required.
+ *
+ */
+ public static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
+ IProjectDescription description = project.getDescription();
+ String[] prevNatures= description.getNatureIds();
+ for (int i= 0; i < prevNatures.length; i++) {
+ if (natureId.equals(prevNatures[i]))
+ return;
+ }
+ String[] newNatures= new String[prevNatures.length + 1];
+ System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
+ newNatures[prevNatures.length]= natureId;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, monitor);
+ }
+
+
+ /**
+ * Sets the path of the build command executable.
+ */
+ public void setBuildCommand(IPath locationPath, IProgressMonitor monitor) throws CoreException {
+ String newLocation= locationPath.toString();
+ String oldLocation= fBuildInfo.getBuildLocation();
+ if (!newLocation.equals(oldLocation)) {
+ fBuildInfo.setBuildLocation(newLocation);
+ }
+ }
+
+ /**
+ * Gets the path of the build command executable.
+ */
+ public IPath getBuildCommand() throws CoreException {
+ String buildLocation= fBuildInfo.getBuildLocation();
+ return new Path(buildLocation);
+ }
+
+ /**
+ * Sets the arguments for the full build.
+ */
+ public void setFullBuildArguments(String arguments, IProgressMonitor monitor) throws CoreException {
+ String oldArguments= fBuildInfo.getFullBuildArguments();
+ if (!arguments.equals(oldArguments)) {
+ fBuildInfo.setFullBuildArguments(arguments);
+ }
+ }
+
+ /**
+ * Gets the arguments for the full build
+ */
+ public String getFullBuildArguments() throws CoreException {
+ String buildArguments= fBuildInfo.getFullBuildArguments();
+ if (buildArguments == null) {
+ buildArguments= "";
+ }
+ return buildArguments;
+ }
+
+ /**
+ * Sets the arguments for the incremental build.
+ */
+ public void setIncrBuildArguments(String arguments, IProgressMonitor monitor) throws CoreException {
+ String oldArguments= fBuildInfo.getIncrementalBuildArguments();
+ if (!arguments.equals(oldArguments)) {
+ fBuildInfo.setIncrementalBuildArguments(arguments);
+ }
+ }
+
+ /**
+ * Gets the arguments for the incremental build
+ */
+ public String getIncrBuildArguments() throws CoreException {
+ String buildArguments= fBuildInfo.getIncrementalBuildArguments();
+ if (buildArguments == null) {
+ buildArguments= "";
+ }
+ return buildArguments;
+ }
+
+ /**
+ * Sets Stop on Error
+ */
+ public void setStopOnError(boolean on) throws CoreException {
+ boolean oldArgument= fBuildInfo.isStopOnError();
+ if (on != oldArgument) {
+ fBuildInfo.setStopOnError(on);
+ }
+ }
+
+ public void setBuildCommandOverride(boolean on) throws CoreException {
+ boolean oldArgument= fBuildInfo.isDefaultBuildCmd();
+ if (on != oldArgument) {
+ fBuildInfo.setUseDefaultBuildCmd(on);
+ }
+ }
+
+ /**
+ * Gets Stop on Error
+ */
+ public boolean isStopOnError() throws CoreException {
+ return fBuildInfo.isStopOnError();
+ }
+
+ public boolean isDefaultBuildCmd() throws CoreException {
+ return fBuildInfo.isDefaultBuildCmd();
+ }
+
+ public static boolean hasCBuildSpec(IProject project) {
+ boolean found= false;
+ try {
+ IProjectDescription description = project.getDescription();
+ ICommand[] commands= description.getBuildSpec();
+ for (int i= 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(BUILDER_ID)) {
+ found= true;
+ break;
+ }
+ }
+ } catch (CoreException e) {
+ }
+ return found;
+ }
+
+ public void addCBuildSpec(IProgressMonitor mon) throws CoreException {
+ addToBuildSpec(getBuilderID(), mon);
+ }
+
+ public static void addCBuildSpec(IProject project, IProgressMonitor mon) throws CoreException {
+ addToBuildSpec(project, getBuilderID(), mon);
+ }
+
+ public void addToBuildSpec(String builderID, IProgressMonitor mon) throws CoreException {
+ addToBuildSpec(getProject(), builderID, mon);
+ }
+
+ /**
+ * Adds a builder to the build spec for the given project.
+ */
+ public static void addToBuildSpec(IProject project, String builderID, IProgressMonitor mon) throws CoreException {
+ IProjectDescription description= project.getDescription();
+ ICommand[] commands= description.getBuildSpec();
+ boolean found= false;
+ for (int i= 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(builderID)) {
+ found= true;
+ break;
+ }
+ }
+ if (!found) {
+ ICommand command= description.newCommand();
+ command.setBuilderName(builderID);
+ ICommand[] newCommands= new ICommand[commands.length + 1];
+ // Add it before other builders. See 1FWJK7I: ITPJCORE:WIN2000
+ System.arraycopy(commands, 0, newCommands, 1, commands.length);
+ newCommands[0]= command;
+ description.setBuildSpec(newCommands);
+ project.setDescription(description, mon);
+ }
+ }
+
+ public void removeCBuildSpec(IProgressMonitor mon) throws CoreException {
+ removeFromBuildSpec(getBuilderID(), mon);
+ }
+
+ /**
+ * Removes the given builder from the build spec for the given project.
+ */
+ public void removeFromBuildSpec(String builderID, IProgressMonitor mon) throws CoreException {
+ IProjectDescription description= getProject().getDescription();
+ ICommand[] commands= description.getBuildSpec();
+ for (int i= 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(builderID)) {
+ ICommand[] newCommands= new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ return;
+ }
+ }
+ getProject().setDescription(description, mon);
+ }
+
+ /**
+ * Get the correct builderID
+ */
+ public static String getBuilderID() {
+ Plugin plugin = (Plugin)CCorePlugin.getDefault();
+ IPluginDescriptor descriptor = plugin.getDescriptor();
+ if (descriptor.getExtension(BUILDER_NAME) != null) {
+ return descriptor.getUniqueIdentifier() + "." + BUILDER_NAME;
+ }
+ return BUILDER_ID;
+ }
+
+ /**
+ * @see IProjectNature#configure
+ */
+ public void configure() throws CoreException {
+ addToBuildSpec(getBuilderID(), null);
+ IBuildInfo info = BuildInfoFactory.create();
+ fBuildInfo.setBuildLocation(info.getBuildLocation());
+ fBuildInfo.setFullBuildArguments("");
+ fBuildInfo.setIncrementalBuildArguments("");
+ }
+
+ /**
+ * @see IProjectNature#deconfigure
+ */
+ public void deconfigure() throws CoreException {
+ removeFromBuildSpec(getBuilderID(), null);
+ fBuildInfo.setBuildLocation(null);
+ fBuildInfo.setFullBuildArguments(null);
+ fBuildInfo.setIncrementalBuildArguments(null);
+ }
+
+ /**
+ * @see IProjectNature#getProject
+ */
+ public IProject getProject() {
+ return fProject;
+ }
+
+ /**
+ * @see IProjectNature#setProject
+ */
+ public void setProject(IProject project) {
+ fProject= project;
+ fBuildInfo = BuildInfoFactory.create(fProject);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
new file mode 100644
index 00000000000..12322b76dfa
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncher.java
@@ -0,0 +1,167 @@
+package org.eclipse.cdt.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.util.Properties;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.cdt.utils.spawner.EnvironmentReader;
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
+import org.eclipse.cdt.internal.core.*;
+
+
+public class CommandLauncher {
+
+ public final static int COMMAND_CANCELED= 1;
+ public final static int ILLEGAL_COMMAND= -1;
+ public final static int OK= 0;
+
+ protected Process fProcess;
+ protected boolean fShowCommand;
+ protected String[] fCommandArgs;
+
+ protected String fErrorMessage;
+
+ /**
+ * The number of milliseconds to pause
+ * between polling.
+ */
+ protected static final long DELAY = 50L;
+
+ /**
+ * Creates a new launcher
+ * Fills in stderr and stdout output to the given streams.
+ * Streams can be set to null
, if output not required
+ */
+ public CommandLauncher() {
+ fProcess= null;
+ fShowCommand= false;
+ }
+
+ /**
+ * Sets if the command should be printed out first before executing
+ */
+ public void showCommand(boolean show) {
+ fShowCommand= show;
+ }
+
+ public String getErrorMessage() {
+ return fErrorMessage;
+ }
+
+ public String[] getCommandArgs() {
+ return fCommandArgs;
+ }
+
+ public Properties getEnvironment() {
+ return EnvironmentReader.getEnvVars();
+ }
+
+ /**
+ * Constructs a command array that will be passed to the process
+ */
+ protected String[] constructCommandArray(String command, String[] commandArgs) {
+ String[] args = new String[1 + commandArgs.length];
+ args[0] = command;
+ System.arraycopy(commandArgs, 0, args, 1, commandArgs.length);
+ return args;
+ }
+
+ /**
+ * Execute a command
+ */
+ public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory) {
+ try {
+ // add platform specific arguments (shell invocation)
+ fCommandArgs= constructCommandArray(commandPath.toOSString(), args);
+ fProcess= ProcessFactory.getFactory().exec(fCommandArgs, env, changeToDirectory.toFile());
+ fErrorMessage= "";
+ } catch (IOException e) {
+ fErrorMessage= e.getMessage();
+ fProcess= null;
+ }
+ return fProcess;
+ }
+
+ /**
+ * Reads output form the process to the streams.
+ */
+ public int waitAndRead(OutputStream out, OutputStream err) {
+ if (fShowCommand) {
+ printCommandLine(fCommandArgs, out);
+ }
+
+ if (fProcess == null) {
+ return ILLEGAL_COMMAND;
+ }
+
+ ProcessClosure closure= new ProcessClosure(fProcess, out, err);
+ closure.runBlocking(); // a blocking call
+ return OK;
+ }
+
+ /**
+ * Reads output form the process to the streams. A progress monitor is polled to
+ * test if the cancel button has been pressed.
+ * Destroys the process if the monitor becomes canceled
+ * override to implement a different way to read the process inputs
+ */
+ public int waitAndRead(OutputStream out, OutputStream err, IProgressMonitor monitor) {
+ if (fShowCommand) {
+ printCommandLine(fCommandArgs, out);
+ }
+
+ if (fProcess == null) {
+ return ILLEGAL_COMMAND;
+ }
+
+ ProcessClosure closure= new ProcessClosure(fProcess, out, err);
+ closure.runNonBlocking();
+ while (!monitor.isCanceled() && closure.isAlive()) {
+ try {
+ Thread.sleep(DELAY);
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ int state = OK;
+
+ // Operation canceled by the user, terminate abnormally.
+ if (monitor.isCanceled()) {
+ closure.terminate();
+ state = COMMAND_CANCELED;
+ }
+
+ try {
+ fProcess.waitFor();
+ } catch (InterruptedException e) {
+ //System.err.println("Closure exception " +e);
+ //e.printStackTrace();
+ }
+
+ return state;
+ }
+
+ protected void printCommandLine(String[] commandArgs, OutputStream os) {
+ if (os != null) {
+ StringBuffer buf= new StringBuffer();
+ for (int i= 0; i < commandArgs.length; i++) {
+ buf.append(commandArgs[i]);
+ buf.append(' ');
+ }
+ buf.append('\n');
+ try {
+ os.write(buf.toString().getBytes());
+ os.flush();
+ } catch (IOException e) {
+ // ignore;
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ConsoleOutputStream.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ConsoleOutputStream.java
new file mode 100644
index 00000000000..d54770c55b4
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ConsoleOutputStream.java
@@ -0,0 +1,73 @@
+package org.eclipse.cdt.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * Output stream which storing the console output
+ */
+public class ConsoleOutputStream extends OutputStream {
+
+ protected StringBuffer fBuffer;
+
+ protected StringBuffer fContent;
+
+ protected int pos;
+
+ public ConsoleOutputStream() {
+ fBuffer= new StringBuffer(256);
+ fContent= new StringBuffer();
+ pos = 0;
+ }
+
+ /**
+ * @see OutputStream#flush
+ */
+ public synchronized void flush() throws IOException {
+ final String content= fBuffer.toString();
+ fBuffer.setLength(0);
+ fContent.append(content);
+ }
+
+ public String getContent(int len) {
+ String s = null;
+ try {
+ s = fContent.substring (len);
+ } catch (StringIndexOutOfBoundsException e) {
+ s = "";
+ }
+ return s;
+ }
+
+ public String getContent() {
+ // return fContent.toString();
+ if (pos >= fContent.length())
+ pos = 0;
+ String s = getContent(pos);
+ pos += s.length();
+ return s;
+ }
+
+ public void clear() {
+ fBuffer.setLength (0);
+ fContent.setLength (0);
+ pos = 0;
+ }
+
+ /**
+ * Implements buffered output at the lowest level
+ * @see OutputStream#write
+ */
+ public synchronized void write(int c) throws IOException {
+ fBuffer.append((char) c);
+ if (fBuffer.length() > 250) {
+ flush();
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java
new file mode 100644
index 00000000000..1c8e6bbee12
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java
@@ -0,0 +1,50 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+
+import org.eclipse.cdt.core.model.ICModelMarker;
+import org.eclipse.cdt.internal.CCorePlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.resources.IMarker;
+
+public abstract class ACBuilder extends IncrementalProjectBuilder {
+
+ /**
+ * Constructor for ACBuilder
+ */
+ public ACBuilder() {
+ super();
+ }
+
+ /*
+ * callback from Output Parser
+ */
+ //public void addMarker(IFile file, int lineNumber, String errorDesc, int severity) {
+ public void addMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
+ try {
+ IMarker marker= file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
+ marker.setAttribute(IMarker.LOCATION, lineNumber);
+ marker.setAttribute(IMarker.MESSAGE, errorDesc);
+ marker.setAttribute(IMarker.SEVERITY, severity);
+ marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
+ marker.setAttribute(IMarker.CHAR_START, -1);
+ marker.setAttribute(IMarker.CHAR_END, -1);
+ if(errorVar != null) {
+ marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, errorVar);
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e.getStatus());
+ }
+
+ }
+
+ public abstract IPath getWorkingDirectory();
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java
new file mode 100644
index 00000000000..4c3c1f49c6a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IBuildInfo.java
@@ -0,0 +1,25 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+public interface IBuildInfo {
+
+ String getBuildLocation();
+ String getFullBuildArguments();
+ String getIncrementalBuildArguments();
+ boolean isStopOnError();
+
+ void setBuildLocation(String location);
+ void setFullBuildArguments(String arguments);
+ void setIncrementalBuildArguments(String arguments);
+ void setStopOnError(boolean on);
+
+ boolean isClearBuildConsole();
+
+ boolean isDefaultBuildCmd();
+ void setUseDefaultBuildCmd(boolean on);
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ICPlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ICPlugin.java
new file mode 100644
index 00000000000..29599c55896
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ICPlugin.java
@@ -0,0 +1,15 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IAdaptable;
+
+public interface ICPlugin extends IAdaptable {
+ IMessageDialog getMessageDialog();
+ IPropertyStore getPropertyStore();
+ IConsole getConsole();
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IConsole.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IConsole.java
new file mode 100644
index 00000000000..7355b0e271d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IConsole.java
@@ -0,0 +1,15 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.core.ConsoleOutputStream;
+
+
+public interface IConsole {
+ void clear();
+ ConsoleOutputStream getOutputStream();
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IMessageDialog.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IMessageDialog.java
new file mode 100644
index 00000000000..18513b26e04
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IMessageDialog.java
@@ -0,0 +1,12 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+public interface IMessageDialog {
+ void openError(String title, String message);
+
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPropertyStore.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPropertyStore.java
new file mode 100644
index 00000000000..13fdaf516cc
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/IPropertyStore.java
@@ -0,0 +1,24 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+public interface IPropertyStore {
+ public static final boolean BOOLEAN_DEFAULT_DEFAULT = false;
+ public static final double DOUBLE_DEFAULT_DEFAULT = 0.0;
+ public static final float FLOAT_DEFAULT_DEFAULT = 0.0f;
+ public static final int INT_DEFAULT_DEFAULT = 0;
+ public static final long LONG_DEFAULT_DEFAULT = 0L;
+ public static final String STRING_DEFAULT_DEFAULT = new String();
+
+ public static final String TRUE = "true";
+ public static final String FALSE = "false";
+
+ String getString(String name);
+ void setDefault(String name, String def);
+ void putValue(String name, String value);
+
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/MakeUtil.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/MakeUtil.java
new file mode 100644
index 00000000000..be855aa1c18
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/MakeUtil.java
@@ -0,0 +1,171 @@
+package org.eclipse.cdt.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+
+public class MakeUtil {
+
+ final static String MAKE_GOALS = "goals";
+ final static String MAKE_DIR = "buildir";
+ final static String MAKE_CONSOLE_MODE = "consoleMode";
+ final static String TARGET_ID = "org.eclipse.cdt.make";
+
+ public static String [] decodeTargets (String property) {
+ BufferedReader reader= new BufferedReader(new StringReader(property));
+ ArrayList l= new ArrayList(5);
+ try {
+ String line= reader.readLine();
+ while (line != null && !"".equals(line)) {
+ l.add(line);
+ line = reader.readLine();
+ }
+ } catch (IOException e) {
+ // this should not happen, we're reading from a string.
+ }
+ String[]result = new String[l.size ()];
+ return (String[])l.toArray(result);
+ }
+
+ public static String encodeTargets(String[] targets) {
+ StringBuffer buf = new StringBuffer();
+ for (int i= 0; i < targets.length; i++) {
+ if (targets[i] != null) {
+ buf.append(targets[i]);
+ buf.append("\n");
+ }
+ }
+ return (buf.length () == 0) ? null : buf.toString();
+ }
+
+ public static QualifiedName getQualifiedNameTarget () {
+ return new QualifiedName(TARGET_ID, MAKE_GOALS);
+ }
+
+ public static QualifiedName getQualifiedNameDir () {
+ return new QualifiedName(TARGET_ID, MAKE_DIR);
+ }
+
+ public static QualifiedName getQualifiedNameConsoleMode () {
+ return new QualifiedName(TARGET_ID, MAKE_CONSOLE_MODE);
+ }
+
+
+ public static String getSessionTarget(IResource resource) {
+ try {
+ String property = (String)resource.getSessionProperty(getQualifiedNameTarget());
+ if (property != null)
+ return property;
+ } catch (CoreException e) {
+ }
+ return new String();
+ }
+
+ public static void setSessionTarget(IResource resource, String target) {
+ try {
+ resource.setSessionProperty(getQualifiedNameTarget(), target);
+ } catch (CoreException e) {
+ }
+ }
+
+ public static void removeSessionTarget(IResource resource) {
+ setSessionTarget (resource, null);
+ }
+
+ public static String getSessionBuildDir(IResource resource) {
+ try {
+ String dir = (String)resource.getSessionProperty(getQualifiedNameDir());
+ if (dir != null)
+ return dir;
+ } catch (CoreException e) {
+ }
+ return new String ();
+ }
+
+ public static void setSessionBuildDir(IResource resource, String dir) {
+ try {
+ resource.setSessionProperty(getQualifiedNameDir(), dir);
+ } catch (CoreException e) {
+ }
+ }
+
+ public static void removeSessionBuildDir(IResource resource) {
+ setSessionBuildDir (resource, null);
+ }
+
+ public static String[] getPersistentTargets(IResource resource) {
+ try {
+ String property = resource.getPersistentProperty(getQualifiedNameTarget());
+ if (property != null)
+ return decodeTargets (property);
+ } catch (CoreException e) {
+ }
+ return new String[0];
+ }
+
+ public static void setPersistentTargets(IResource resource, String[] targets) {
+ String property= null;
+ if (targets != null)
+ property = encodeTargets(targets);
+ //System.out.println ("PROPERTY " + property);
+ try {
+ resource.setPersistentProperty(getQualifiedNameTarget(), property);
+ } catch (CoreException e) {
+ }
+ }
+
+ public static void setSessionConsoleMode(IResource resource, boolean mode) {
+ try {
+ resource.setSessionProperty(getQualifiedNameConsoleMode(),
+ new Boolean(mode));
+ } catch (CoreException e) {
+ }
+ }
+
+ public static boolean getSessionConsoleMode(IResource resource) {
+ try {
+ Boolean b = (Boolean)resource.getSessionProperty(getQualifiedNameConsoleMode());
+ if(null != b)
+ return b.booleanValue();
+ } catch (CoreException e) {
+ }
+ return true; // Clean console before session
+ }
+
+ public static void addPersistentTarget(IResource resource, String target) {
+ String[] targets = MakeUtil.getPersistentTargets (resource);
+ for (int i = 0; i < targets.length; i++) {
+ if (targets[i].equals (target)) {
+ return;
+ }
+ }
+ String[] newTargets = new String[targets.length + 1];
+ System.arraycopy (targets, 0, newTargets, 0, targets.length);
+ newTargets[targets.length] = target;
+ MakeUtil.setPersistentTargets (resource, newTargets);
+ }
+
+ public static void removePersistentTarget (IResource resource, String target) {
+ String[] targets = MakeUtil.getPersistentTargets (resource);
+ String[] newTargets = new String[targets.length];
+ for (int i = 0; i < targets.length; i++) {
+ if (! targets[i].equals (target)) {
+ newTargets[i] = targets[i];
+ }
+ }
+ MakeUtil.setPersistentTargets (resource, newTargets);
+ }
+
+ private MakeUtil() {
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/AbstractPlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/AbstractPlugin.java
new file mode 100644
index 00000000000..754f0d65650
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/AbstractPlugin.java
@@ -0,0 +1,247 @@
+package org.eclipse.cdt.internal;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.cdt.core.resources.*;
+import org.eclipse.core.runtime.*;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+/**
+ * Abstract base class for plug-ins that integrate with the Eclipse platform UI.
+ * + * Subclasses obtain the following capabilities: + *
+ *+ * Preferences + *
getPreferenceStore
is
+ * called. FN_PREF_STORE
. A preference file is looked for in the plug-in's
+ * read/write state area.initializeDefaultPreferences
+ * to set up any default values for preferences. These are the values
+ * typically used if the user presses the Default button in a preference
+ * dialog. FN_DEFAULT_PREFERENCES
.
+ * This allows a plug-in to ship with a read-only copy of a preference file
+ * containing default values for certain settings different from the
+ * hard-wired default ones (perhaps as a result of localizing, or for a
+ * common configuration).savePreferenceStore
to cause
+ * non-default settings to be saved back to the file in the plug-in's
+ * read/write state area. getDialogSettings
is
+ * called.FN_DIALOG_STORE
. A dialog store file is first
+ * looked for in the plug-in's read/write state area; if not found there,
+ * the plug-in's install directory is checked.
+ * This allows a plug-in to ship with a read-only copy of a dialog store
+ * file containing initial values for certain settings.saveDialogSettings
to cause settings to
+ * be saved in the plug-in's read/write state area. A plug-in may opt to do
+ * this each time a wizard or dialog is closed to ensure the latest
+ * information is always safe on disk.
+ * For easy access to your plug-in object, use the singleton pattern. Declare a
+ * static variable in your plug-in class for the singleton. Store the first
+ * (and only) instance of the plug-in class in the singleton when it is created.
+ * Then access the singleton when needed through a static getDefault
+ * method.
+ *
"pref_store.ini"
).
+ */
+ private static final String FN_PREF_STORE= "pref_store.ini";//$NON-NLS-1$
+ /**
+ * The name of the default preference settings file (value
+ * "preferences.ini"
).
+ */
+ private static final String FN_DEFAULT_PREFERENCES= "preferences.ini";//$NON-NLS-1$
+
+ /**
+ * Storage for preferences; null
if not yet initialized.
+ */
+ private PreferenceStore preferenceStore = null;
+
+/**
+ * Creates an abstract plug-in runtime object for the given plug-in descriptor.
+ * + * Note that instances of plug-in runtime classes are automatically created + * by the platform in the course of plug-in activation. + *
+ * + * @param descriptor the plug-in descriptor + */ +public AbstractPlugin(IPluginDescriptor descriptor) { + super(descriptor); +} + +/** + * Returns the preference store for this UI plug-in. + * This preference store is used to hold persistent settings for this plug-in in + * the context of a workbench. Some of these settings will be user controlled, + * whereas others may be internal setting that are never exposed to the user. + *+ * If an error occurs reading the preference store, an empty preference store is + * quietly created, initialized with defaults, and returned. + *
+ *
+ * Subclasses should reimplement initializeDefaultPreferences
if
+ * they have custom graphic images to load.
+ *
+ * This method is called after the preference store is initially loaded + * (default values are never stored in preference stores). + *
+ * The default implementation of this method does nothing. + * Subclasses should reimplement this method if the plug-in has any preferences. + *
+ * + * @param store the preference store to fill + */ +protected void initializeDefaultPreferences(IPropertyStore store) { +} + +/** + * Sets default preferences defined in the plugin directory. + * If there are no default preferences defined, or some other + * problem occurs, we fail silently. + */ +private void initializePluginPreferences(IPropertyStore store) { + URL baseURL = getDescriptor().getInstallURL(); + + URL iniURL= null; + try { + iniURL = new URL(baseURL, FN_DEFAULT_PREFERENCES); + } catch (MalformedURLException e) { + return; + } + + Properties ini = new Properties(); + InputStream is = null; + try { + is = iniURL.openStream(); + ini.load(is); + } + catch (IOException e) { + // Cannot read ini file; + return; + } + finally { + try { + if (is != null) + is.close(); + } catch (IOException e) {} + } + + Enumeration enum = ini.propertyNames(); + while (enum.hasMoreElements()) { + String key = (String)enum.nextElement(); + store.setDefault(key, ini.getProperty(key)); + } +} + +/** + * Loads the preference store for this plug-in. + * The default implementation looks for a standard named file in the + * plug-in's read/write state area. If no file is found or a problem + * occurs, a new empty preference store is silently created. + *+ * This framework method may be overridden, although this is typically + * unnecessary. + *
+ */ +protected void loadPreferenceStore() { + String readWritePath = getStateLocation().append(FN_PREF_STORE).toOSString(); + preferenceStore = new PreferenceStore(readWritePath); + try { + preferenceStore.load(); + } + catch (IOException e) { + // Load failed, perhaps because the file does not yet exist. + // At any rate we just return and leave the store empty. + } + return; +} + +/** + * Saves this plug-in's preference store. + * Any problems which arise are silently ignored. + */ +protected void savePreferenceStore() { + if (preferenceStore == null) { + return; + } + try { + preferenceStore.save(); // the store knows its filename - no need to pass it + } + catch (IOException e) { + } +} + +/** + * TheAbstractPlugin
implementation of this Plugin
+ * method saves this plug-in's preference and dialog stores and shuts down
+ * its image registry (if they are in use). Subclasses may extend this method,
+ * but must send super first.
+ */
+public void shutdown() throws CoreException {
+ super.shutdown();
+ savePreferenceStore();
+ preferenceStore = null;
+}
+
+public Object getAdapter(Class adapter) {
+ return Platform.getAdapterManager().getAdapter(this, adapter);
+}
+
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePlugin.java
new file mode 100644
index 00000000000..503f961b35a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePlugin.java
@@ -0,0 +1,184 @@
+package org.eclipse.cdt.internal;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+
+import org.eclipse.cdt.core.resources.ICPlugin;
+import org.eclipse.cdt.core.resources.IConsole;
+import org.eclipse.cdt.core.resources.IMessageDialog;
+import org.eclipse.cdt.core.resources.IPropertyStore;
+import org.eclipse.cdt.core.ConsoleOutputStream;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.index.IndexModel;
+
+
+public class CCorePlugin extends AbstractPlugin implements ICPlugin {
+
+ public static final String PLUGIN_ID= "org.eclipse.cdt.core";
+ public static final String BUILDER_ID= PLUGIN_ID + ".cbuilder";
+
+ private static CCorePlugin fgCPlugin;
+ private static ResourceBundle fgResourceBundle;
+
+ // -------- static methods --------
+
+ static {
+ try {
+ fgResourceBundle= ResourceBundle.getBundle("org.eclipse.cdt.internal.CCorePluginResources");
+ } catch (MissingResourceException x) {
+ fgResourceBundle= null;
+ }
+ }
+
+ public static String getResourceString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";
+ } catch (NullPointerException e) {
+ return "#" + key + "#";
+ }
+ }
+
+ public static IWorkspace getWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ public static String getFormattedString(String key, String arg) {
+ return MessageFormat.format(getResourceString(key), new String[] { arg });
+ }
+
+ public static String getFormattedString(String key, String[] args) {
+ return MessageFormat.format(getResourceString(key), args);
+ }
+
+ public static ResourceBundle getResourceBundle() {
+ return fgResourceBundle;
+ }
+
+ public static Plugin getDefaultPlugin() {
+ return fgCPlugin;
+ }
+
+ public static ICPlugin getDefault() {
+ ICPlugin plugin;
+ if ((plugin = (ICPlugin)fgCPlugin.getAdapter(ICPlugin.class)) != null) {
+ return plugin;
+ }
+ return fgCPlugin;
+ }
+
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Error", e));
+ }
+
+ public static void log(IStatus status) {
+ ((Plugin)getDefault()).getLog().log(status);
+ }
+
+ public IPropertyStore getPropertyStore() {
+ return getPreferenceStore();
+ }
+
+ // ------ CPlugin
+
+ public IMessageDialog getMessageDialog() {
+ return new IMessageDialog() {
+ public void openError(String title, String msg) {
+ System.err.println(title +": " +msg);
+ }
+ };
+ }
+
+ private IConsole fConsoleDocument;
+
+ public CCorePlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ fgCPlugin= this;
+/*
+ fModel = new ACDebugModel() {
+ public Object createPresentation() {
+ return null;
+ }
+
+ public String getIdentifier() {
+ return PLUGIN_ID;
+ }
+
+ public IMarker createBreakpoint( final IResource resource,
+ final Map attributes,
+ final String markerType ) throws CoreException {
+ return null;
+ }
+ };
+*/
+ fConsoleDocument= new IConsole() {
+ public void clear() {
+ }
+
+ public ConsoleOutputStream getOutputStream() {
+ return new ConsoleOutputStream();
+ }
+ };
+ }
+
+
+ /**
+ * @see Plugin#shutdown
+ */
+ public void shutdown() throws CoreException {
+ super.shutdown();
+ }
+
+ /**
+ * @see Plugin#startup
+ */
+ public void startup() throws CoreException {
+ super.startup();
+
+ // Fired up the model.
+ getCoreModel();
+ // Fired up the indexer. It should delay itself for 10 seconds
+ getIndexModel();
+ }
+
+ /**
+ * @see AbstractPlugin#initializeDefaultPreferences
+ */
+ protected void initializeDefaultPreferences(IPropertyStore store) {
+ super.initializeDefaultPreferences(store);
+ }
+
+ public IConsole getConsole() {
+ return fConsoleDocument;
+ }
+
+ public CoreModel getCoreModel() {
+ return CoreModel.getDefault();
+ }
+
+ public IndexModel getIndexModel() {
+ return IndexModel.getDefault();
+ }
+
+/*
+ public ACDebugModel getDebugModel() {
+ return fModel;
+ }
+*/
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePluginResources.properties b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePluginResources.properties
new file mode 100644
index 00000000000..862be897e77
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/CCorePluginResources.properties
@@ -0,0 +1,10 @@
+################################################
+#
+# (c) Copyright QNX Software Systems Ltd. 2002.
+# All Rights Reserved.
+#
+################################################
+
+CApplicationLauncher.error.title=Error Launching Application
+CApplicationLauncher.error.message=Unable to Launch Application
+
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/PreferenceStore.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/PreferenceStore.java
new file mode 100644
index 00000000000..02af2b15c4e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/PreferenceStore.java
@@ -0,0 +1,504 @@
+package org.eclipse.cdt.internal;
+
/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.*;
+import java.util.*;
+import org.eclipse.cdt.core.resources.*;
+//import org.eclipse.jface.util.*;
+
+/**
+ * A concrete preference store implementation based on an internal
+ * java.util.Properties
object, with support for
+ * persisting the non-default preference values to files or streams.
+ * + * This class was not designed to be subclassed. + *
+ * + * @see IPreferenceStore + */ +public class PreferenceStore implements IPropertyStore { + + + /** + * The mapping from preference name to + * preference value (represented as strings). + */ + private Properties properties; + + /** + * The mapping from preference name to + * default preference value (represented as strings); + *null
if none.
+ */
+ private Properties defaultProperties;
+
+ /**
+ * Indicates whether a value as been changed by setToDefault
+ * or setValue
; initially true
.
+ */
+ private boolean dirty = true;
+
+ /**
+ * The file name used by the load
method to load a property
+ * file. This filename is used to save the properties file when save
+ * is called.
+ */
+ private String filename;
+/**
+ * Creates an empty preference store.
+ *
+ * Use the methods load(InputStream)
and
+ * save(InputStream)
to load and store this
+ * preference store.
+ *
+ * Use the methods load()
and save()
to load and store this
+ * preference store.
+ *
PreferenceStore(java.lang.String)
(or by setFileName
).
+ * Default preference values are not affected.
+ *
+ * @exception java.io.IOException if there is a problem loading this store
+ */
+public void load() throws IOException {
+ if (filename == null)
+ throw new IOException("File name not specified");//$NON-NLS-1$
+ FileInputStream in = new FileInputStream(filename);
+ load(in);
+ in.close();
+}
+/**
+ * Loads this preference store from the given input stream. Default preference
+ * values are not affected.
+ *
+ * @param in the input stream
+ * @exception java.io.IOException if there is a problem loading this store
+ */
+public void load(InputStream in) throws IOException {
+ properties.load(in);
+ dirty = false;
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public boolean needsSaving() {
+ return dirty;
+}
+/**
+ * Returns an enumeration of all preferences known to this store which
+ * have current values other than their default value.
+ *
+ * @return an array of preference names
+ */
+public String[] preferenceNames() {
+ ArrayList list = new ArrayList();
+ Enumeration enum = properties.propertyNames();
+ while (enum.hasMoreElements()) {
+ list.add(enum.nextElement());
+ }
+ return (String[])list.toArray(new String[list.size()]);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void putValue(String name, String value) {
+ setValue(properties, name, value);
+}
+
+/**
+ * Saves the non-default-valued preferences known to this preference
+ * store to the file from which they were originally loaded.
+ *
+ * @exception java.io.IOException if there is a problem saving this store
+ */
+public void save() throws IOException {
+ if (filename == null)
+ throw new IOException("File name not specified");//$NON-NLS-1$
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(filename);
+ save(out, null);
+ } finally {
+ if (out != null)
+ out.close();
+ }
+}
+/**
+ * Saves this preference store to the given output stream. The
+ * given string is inserted as header information.
+ *
+ * @param out the output stream
+ * @param header the header
+ * @exception java.io.IOException if there is a problem saving this store
+ */
+public void save(OutputStream out, String header) throws IOException {
+ properties.store(out, header);
+ dirty = false;
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, double value) {
+ setValue(defaultProperties, name, value);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, float value) {
+ setValue(defaultProperties, name, value);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, int value) {
+ setValue(defaultProperties, name, value);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, long value) {
+ setValue(defaultProperties, name, value);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, String value) {
+ setValue(defaultProperties, name, value);
+}
+/* (non-Javadoc)
+ * Method declared on IPreferenceStore.
+ */
+public void setDefault(String name, boolean value) {
+ setValue(defaultProperties, name, value);
+}
+/**
+ * Sets the name of the file used when loading and storing this preference store.
+ *
+ * Afterward, the methods load()
and save()
can be used
+ * to load and store this preference store.
+ *
null
, if
+ * not interested in reading the output
+ * @param errorStream prcess stderr is written to this stream. Can be null
, if
+ * not interested in reading the output
+ */
+ public ProcessClosure(Process process, OutputStream outputStream, OutputStream errorStream) {
+ fProcess= process;
+ fOutput= outputStream;
+ fError= errorStream;
+ }
+
+ /**
+ * Live links the launched process with the configured in/out streams using
+ * reader threads.
+ */
+ public void runNonBlocking() {
+ ThreadGroup group= new ThreadGroup("CBuilder" + fCounter++);
+
+ InputStream stdin= fProcess.getInputStream();
+ InputStream stderr= fProcess.getErrorStream();
+
+ fOutputReader= new ReaderThread(group, "OutputReader", stdin, fOutput);
+ fErrorReader= new ReaderThread(group, "ErrorReader", stderr, fError);
+
+ fOutputReader.start();
+ fErrorReader.start();
+ }
+
+ public void runBlocking() {
+ runNonBlocking();
+
+ boolean finished = false;
+ while (!finished) {
+ try {
+ fProcess.waitFor();
+ } catch (InterruptedException e) {
+ //System.err.println("Closure exception " +e);
+ }
+ try {
+ fProcess.exitValue();
+ finished = true;
+ } catch (IllegalThreadStateException e) {
+ //System.err.println("Closure exception " +e);
+ }
+ }
+
+ // @@@FIXME: Windows 2000 is screwed; double-check using output threads
+ if (!fOutputReader.finished()) {
+ fOutputReader.waitFor();
+ }
+
+ if (!fErrorReader.finished()) {
+ fErrorReader.waitFor();
+ }
+
+ // it seems that thread termination and stream closing is working without
+ // any help
+ fProcess= null;
+ fOutputReader= null;
+ fErrorReader= null;
+ }
+
+
+ public boolean isAlive() {
+ if (fProcess != null) {
+ if (fOutputReader.isAlive() && fErrorReader.isAlive()) {
+ return true;
+ } else {
+ fProcess= null;
+ fOutputReader= null;
+ fErrorReader= null;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Forces the termination the launched process
+ */
+ public void terminate() {
+ if (fProcess != null) {
+ fProcess.destroy();
+ fProcess= null;
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/ErrorParserManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/ErrorParserManager.java
new file mode 100644
index 00000000000..cbd8ea4d43a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/ErrorParserManager.java
@@ -0,0 +1,274 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.StringTokenizer;
+
+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;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.cdt.core.resources.ACBuilder;
+import org.eclipse.cdt.internal.CCorePlugin;
+public class ErrorParserManager {
+
+ private static String PREF_ERROR_PARSER= "errorOutputParser";
+
+ private ACBuilder fBuilder;
+ private Map fFilesInProject;
+ private List fNameConflicts;
+
+ private ArrayList fErrorParsers;
+
+ private Vector fDirectoryStack;
+ private IPath fBaseDirectory;
+
+ private String previousLine;
+
+ static String SEPARATOR = System.getProperty("file.separator");
+
+
+ public ErrorParserManager(ACBuilder builder) {
+ fBuilder= builder;
+ fFilesInProject= new HashMap();
+ fNameConflicts= new ArrayList();
+
+ fErrorParsers= new ArrayList();
+ fDirectoryStack = new Vector();
+ fBaseDirectory = null;
+ readPreferences();
+ }
+
+ public IPath getWorkingDirectory() {
+ if (fDirectoryStack.size() != 0) {
+ return (IPath)fDirectoryStack.lastElement();
+ }
+ return new Path("");
+ }
+
+ public void pushDirectory(IPath dir) {
+ if (dir != null) {
+ IPath pwd = null;
+ if (fBaseDirectory.isPrefixOf(dir)) {
+ int segments = fBaseDirectory.matchingFirstSegments(dir);
+ pwd = dir.removeFirstSegments(segments);
+ } else {
+ pwd = dir;
+ }
+ fDirectoryStack.addElement(pwd);
+ }
+ }
+
+ public IPath popDirectory() {
+ int i = fDirectoryStack.size();
+ IPath dir = (IPath)fDirectoryStack.lastElement();
+ if (i != 0) {
+ fDirectoryStack.removeElementAt(i-1);
+ }
+ return dir;
+ }
+
+ public int getDirectoryLevel() {
+ return fDirectoryStack.size();
+ }
+
+ protected void addParser(IErrorParser parser) {
+ fErrorParsers.add(parser);
+ }
+
+ private void readPreferences() {
+ fErrorParsers.clear();
+ String parserNames= CCorePlugin.getDefault().getPropertyStore().getString(PREF_ERROR_PARSER);
+ if (parserNames != null && parserNames.length() > 0) {
+ StringTokenizer tok= new StringTokenizer(parserNames, ";");
+ while (tok.hasMoreElements()) {
+ String clName= tok.nextToken();
+ try {
+ IErrorParser parser= (IErrorParser)getClass().forName(clName).newInstance();
+ fErrorParsers.add(parser);
+ } catch (ClassNotFoundException e) {
+ // not found
+ CCorePlugin.log(e);
+ } catch (InstantiationException e) {
+ CCorePlugin.log(e);
+ } catch (IllegalAccessException e) {
+ CCorePlugin.log(e);
+ } catch (ClassCastException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ }
+ if (fErrorParsers.size() == 0) {
+ initErrorParsersArray(fErrorParsers);
+ }
+ savePreferences();
+ }
+
+ private void initErrorParsersArray(List errorParsers) {
+ errorParsers.add(new VCErrorParser());
+ errorParsers.add(new GCCErrorParser());
+ errorParsers.add (new GLDErrorParser ());
+ errorParsers.add (new GASErrorParser ());
+ errorParsers.add (new MakeErrorParser ());
+ }
+
+
+ private void savePreferences() {
+ StringBuffer buf= new StringBuffer();
+ for (int i= 0; i < fErrorParsers.size(); i++) {
+ buf.append(fErrorParsers.get(i).getClass().getName());
+ buf.append(';');
+ }
+ CCorePlugin.getDefault().getPropertyStore().putValue(PREF_ERROR_PARSER, buf.toString());
+ }
+
+ protected void collectFiles(IContainer parent, List result) {
+ try {
+ IResource[] resources= parent.members();
+ for (int i= 0; i < resources.length; i++) {
+ IResource resource= resources[i];
+ if (resource instanceof IFile) {
+ result.add(resource);
+ } else if (resource instanceof IContainer) {
+ collectFiles((IContainer)resource, result);
+ }
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e.getStatus());
+ }
+ }
+
+ /**
+ * Parses the input and try to generate error or warning markers
+ */
+ public void parse(String output) {
+ // prepare file lists
+ fFilesInProject.clear();
+ fNameConflicts.clear();
+
+ List collectedFiles= new ArrayList();
+ fBaseDirectory = fBuilder.getProject().getLocation();
+ collectFiles(fBuilder.getProject(), collectedFiles);
+
+ for (int i= 0; i < collectedFiles.size(); i++) {
+ IFile curr= (IFile)collectedFiles.get(i);
+ Object existing= fFilesInProject.put(curr.getName(), curr);
+ if (existing != null) {
+ fNameConflicts.add(curr.getName());
+ }
+ }
+
+ BufferedReader rd= new BufferedReader(new StringReader(output));
+ try {
+ String line= rd.readLine();
+ while (line != null) {
+ processLine(line);
+ previousLine = line;
+ line= rd.readLine();
+ }
+ } catch (IOException e) {
+ CCorePlugin.log(e);
+ } finally {
+ try { rd.close(); } catch (IOException e) {}
+ }
+
+ fFilesInProject.clear();
+ fNameConflicts.clear();
+ fDirectoryStack.removeAllElements();
+ fBaseDirectory = null;
+ }
+
+ private void processLine(String line) {
+ int top= fErrorParsers.size()-1;
+ int i= top;
+ do {
+ IErrorParser curr= (IErrorParser)fErrorParsers.get(i);
+ if (curr.processLine(line, this)) {
+ if (i != top) {
+ // move to top
+ Object used= fErrorParsers.remove(i);
+ fErrorParsers.add(used);
+ savePreferences();
+ }
+ return;
+ }
+ i--;
+ } while (i >= 0);
+ }
+
+ /**
+ * Called by the error parsers.
+ */
+ public IFile findFileName(String fileName) {
+ IPath path= new Path(fileName);
+ return (IFile)fFilesInProject.get(path.lastSegment());
+ }
+
+
+ /**
+ * Called by the error parsers.
+ */
+ public boolean isConflictingName(String fileName) {
+ IPath path= new Path(fileName);
+ return fNameConflicts.contains(path.lastSegment());
+ }
+
+ /**
+ * Called by the error parsers.
+ */
+ public IFile findFilePath(String filePath) {
+ IPath path = null;
+ IPath fp = new Path(filePath);
+ if (fp.isAbsolute()) {
+ if (fBaseDirectory.isPrefixOf(fp)) {
+ int segments = fBaseDirectory.matchingFirstSegments(fp);
+ path = fp.removeFirstSegments(segments);
+ } else {
+ path = fp;
+ }
+ } else {
+ path = (IPath)getWorkingDirectory().append(filePath);
+ }
+ return (IFile)fBuilder.getProject().getFile(path);
+ }
+
+ /**
+ * Called by the error parsers.
+ */
+ public void generateMarker(IResource file, int lineNumber, String desc, int severity, String varName) {
+ if (file == null) {
+ fBuilder.addMarker (fBuilder.getProject(), lineNumber, desc, severity, varName);
+ } else {
+ fBuilder.addMarker(file, lineNumber, desc, severity, varName);
+ }
+ }
+
+ /**
+ * Called by the error parsers. Return the previous line, save in the working buffer.
+ */
+ public String getPreviousLine() {
+ return new String ((previousLine) == null ? "" : previousLine);
+ }
+
+ /**
+ * Called by the error parsers. Overload in Makebuilder.
+ */
+ public IPath getBuildCommand() {
+ return new Path("");
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GASErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GASErrorParser.java
new file mode 100644
index 00000000000..6c1af416591
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GASErrorParser.java
@@ -0,0 +1,54 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+
+public class GASErrorParser implements IErrorParser {
+
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ // cc -c x.c
+ // Only when the previous line sasys Assembler
+ // /tmp/cc8EXnKk.s: Assembler messages:
+ // /tmp/cc8EXnKk.s:46: Error: no such 386 instruction: `b'
+ try {
+ String previous = eoParser.getPreviousLine();
+ String fileName = "";
+ IFile file = null;
+ int num = 0;
+ int severity = IMarker.SEVERITY_ERROR;
+ String desc = line;
+ if (previous != null && previous.startsWith("Assembler")) {
+ if (! line.startsWith("FATAL")) {
+ int firstColon= line.indexOf(':');
+ if (firstColon != -1) {
+ fileName = line.substring(0, firstColon);
+ desc = line.substring(firstColon + 1);
+ int secondColon= line.indexOf(':', firstColon + 1);
+ if (secondColon != -1) {
+ String lineNumber = line.substring(firstColon + 1, secondColon);
+ try {
+ num = Integer.parseInt(lineNumber);
+ } catch (NumberFormatException e) {
+ }
+ if (num != 0) {
+ desc = line.substring(secondColon + 2);
+ }
+ }
+ file = eoParser.findFilePath(fileName);
+ }
+ }
+ if (file == null) {
+ desc = fileName + " " + desc;
+ }
+ eoParser.generateMarker(file, num, desc, severity, null);
+ }
+ } catch (IndexOutOfBoundsException e) {
+ }
+ return false;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GCCErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GCCErrorParser.java
new file mode 100644
index 00000000000..1112df7d664
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GCCErrorParser.java
@@ -0,0 +1,137 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+
+public class GCCErrorParser implements IErrorParser {
+
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ // gcc: "filename:linenumber: error_desc"
+ int firstColon = line.indexOf(':');
+
+ /* Guard against drive in Windows platform. */
+ if (firstColon == 1) {
+ try {
+ String os = System.getProperty("os.name");
+ if (os != null && os.startsWith("Win")) {
+ try {
+ if (Character.isLetter(line.charAt(0))) {
+ firstColon = line.indexOf(':', 2);
+ }
+ } catch (StringIndexOutOfBoundsException e) {
+ }
+ }
+ } catch (SecurityException e) {
+ }
+ }
+
+ if (firstColon != -1) {
+ try {
+ int secondColon= line.indexOf(':', firstColon + 1);
+ if (secondColon != -1) {
+ String fileName = line.substring(0, firstColon);
+ String lineNumber = line.substring(firstColon + 1, secondColon);
+ String varName = null;
+ String desc = line.substring(secondColon + 2);
+ int severity = IMarker.SEVERITY_ERROR;
+ int num = 0;
+
+ try {
+ num = Integer.parseInt(lineNumber);
+ } catch (NumberFormatException e) {
+ }
+
+ if (num == 0) {
+ // Maybe a bad option error or cc1(plus) error
+ if (fileName.startsWith("cc") || fileName.startsWith("gcc")
+ || fileName.startsWith("qcc") || fileName.startsWith("QCC")) {
+ // do nothing;
+ if(line.indexOf("caught signal") != -1) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ IFile file = eoParser.findFilePath(fileName);
+
+ if (file != null) {
+ // gnu c: filename:no: (Each undeclared identifier is reported
+ // only once. filename:no: for each function it appears in.)
+ if (desc.startsWith ("(Each undeclared")) {
+ // Do nothing.
+ return false;
+ } else {
+ String previous = eoParser.getPreviousLine();
+ if (desc.endsWith(")")
+ && previous.indexOf("(Each undeclared") >= 0 ) {
+ // Do nothing.
+ return false;
+ }
+ }
+ /* See if we can get a var name
+ * Look for:
+ * 'foo' undeclared
+ * 'foo' defined but not used
+ * conflicting types for 'foo'
+ *
+ */
+ int s;
+ if((s = desc.indexOf("\' undeclared")) != -1) {
+ int p = desc.indexOf("`");
+ if(p != -1) {
+ varName = desc.substring(p+1, s);
+ System.out.println("undex varName "+ varName);
+ }
+ } else if((s = desc.indexOf("\' defined but not used")) != -1) {
+ int p = desc.indexOf("`");
+ if(p != -1) {
+ varName = desc.substring(p+1, s);
+ System.out.println("unused varName "+ varName);
+ }
+ } else if((s = desc.indexOf("conflicting types for `")) != -1) {
+ int p = desc.indexOf("\'", s);
+ if(p != -1) {
+ varName = desc.substring(desc.indexOf("`") + 1, p);
+ System.out.println("confl varName "+ varName);
+ }
+ } else if((s = desc.indexOf("previous declaration of `")) != -1) {
+ int p = desc.indexOf("\'", s);
+ if(p != -1) {
+ varName = desc.substring(desc.indexOf("`") + 1, p);
+ System.out.println("prev varName "+ varName);
+ }
+ }
+ } else {
+ // Parse the entire project.
+ file = eoParser.findFileName(fileName);
+ if (file != null) {
+ // If there is a conflict set the error on the project.
+ if (eoParser.isConflictingName(fileName)) {
+ desc = "*" + desc;
+ file = null;
+ }
+ }
+
+ // Display the fileName.
+ if (file == null) {
+ desc = fileName + ": " + desc;
+ }
+ }
+ if (desc.startsWith("warning") || desc.startsWith("Warning")) {
+ severity = IMarker.SEVERITY_WARNING;
+ }
+ eoParser.generateMarker(file, num, desc, severity, varName);
+ }
+ } catch (StringIndexOutOfBoundsException e) {
+ } catch (NumberFormatException e) {
+ }
+ }
+ return false;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GLDErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GLDErrorParser.java
new file mode 100644
index 00000000000..2db11fa181e
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/GLDErrorParser.java
@@ -0,0 +1,57 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+
+public class GLDErrorParser implements IErrorParser {
+
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ // binutils linker error:
+ // 1- an error when trying to link
+ // tempfile: In function `function':
+ // tempfile(.text+0xhex): undefined reference to `symbol'
+ // 2-
+ // Something went wrong check if it is "ld" the linkeer bay cheching
+ // the last letter for "ld"
+ int firstColon= line.indexOf(':');
+ if (firstColon != -1) {
+ String buf= line.substring(0, firstColon);
+ String desc= line.substring(firstColon + 1);
+ int firstPara= buf.indexOf('(');
+ int secondPara= buf.indexOf(')');
+ if (firstPara >= 0 && secondPara >= 0) {
+ String fileName = buf.substring(0, firstPara);
+ String previous = eoParser.getPreviousLine();
+ if (previous == null)
+ previous = "";
+ int colon = previous.indexOf(':');
+ if (colon != -1) {
+ previous = previous.substring(colon + 1);
+ }
+
+ desc = "*" + previous + " " + desc;
+ // Since we do not have any way to know the name of the C file
+ // where the undefined reference is refering we set the error
+ // on the project.
+ IFile file = eoParser.findFilePath(fileName);
+ if (file == null) {
+ desc = fileName + " " + desc;
+ }
+ eoParser.generateMarker(file, 0, desc, IMarker.SEVERITY_ERROR, null);
+ } else if (buf.endsWith("ld")){
+ String fileName = line.substring(0, firstColon);
+ IFile file = eoParser.findFilePath(fileName);
+ if (file == null) {
+ desc = fileName + " " + desc;
+ }
+ eoParser.generateMarker(file, 0, desc, IMarker.SEVERITY_ERROR, null);
+ }
+ }
+ return false;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/IErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/IErrorParser.java
new file mode 100644
index 00000000000..903aeec01c1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/IErrorParser.java
@@ -0,0 +1,15 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+public interface IErrorParser {
+ /**
+ * Finds error or warnings on the given line
+ */
+ boolean processLine(String line, ErrorParserManager eoParser);
+
+}
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/MakeErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/MakeErrorParser.java
new file mode 100644
index 00000000000..15b12c397c9
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/MakeErrorParser.java
@@ -0,0 +1,60 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.Path;
+
+public class MakeErrorParser implements IErrorParser {
+
+ public MakeErrorParser() {
+ }
+
+ static int getDirectoryLevel(String line) {
+ int s = line.indexOf('[');
+ if (s != -1) {
+ int e = line.indexOf(']');
+ String number = line.substring(s + 1, e);
+ int num= Integer.parseInt(number);
+ return num;
+ }
+ return 0;
+ }
+
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ // make\[[0-9]*\]: error_desc
+ int firstColon= line.indexOf(':');
+ if (firstColon != -1 && line.startsWith("make")) {
+ boolean enter = false;
+ String msg= line.substring(firstColon + 1);
+ if ((enter = msg.startsWith(" Entering directory")) ||
+ (msg.startsWith(" Leaving directory"))) {
+ int s = msg.indexOf('`');
+ int e = msg.indexOf('\'');
+ if (s != -1 && e != -1) {
+ String dir = msg.substring(s+1, e);
+ if (enter) {
+ /* Sometimes make screws up the output, so
+ * "leave" events can't be seen. Double-check level
+ * here.
+ */
+ int level = getDirectoryLevel(line);
+ int parseLevel = eoParser.getDirectoryLevel();
+ if (level <= parseLevel) {
+ for ( ; level <= parseLevel; level++) {
+ eoParser.popDirectory();
+ }
+ }
+ eoParser.pushDirectory(new Path(dir));
+ } else {
+ eoParser.popDirectory();
+ /* Could check to see if they match */
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/VCErrorParser.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/VCErrorParser.java
new file mode 100644
index 00000000000..40c16aadb2a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/errorparsers/VCErrorParser.java
@@ -0,0 +1,52 @@
+package org.eclipse.cdt.internal.errorparsers;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+
+public class VCErrorParser implements IErrorParser {
+
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ // msdev: filname(linenumber) : error/warning error_desc
+ int firstColon= line.indexOf(':');
+ if (firstColon != -1) {
+ String firstPart= line.substring(0, firstColon);
+ StringTokenizer tok= new StringTokenizer(firstPart, "()");
+ if (tok.hasMoreTokens()) {
+ String fileName= tok.nextToken();
+ if (tok.hasMoreTokens()) {
+ String lineNumber= tok.nextToken();
+ try {
+ int num= Integer.parseInt(lineNumber);
+ int i= fileName.lastIndexOf(File.separatorChar);
+ if (i != -1) {
+ fileName= fileName.substring(i + 1);
+ }
+ IFile file= eoParser.findFileName(fileName);
+ if (file != null || eoParser.isConflictingName(fileName)) {
+ String desc= line.substring(firstColon + 1).trim();
+ if (file == null) {
+ desc= "*" + desc;
+ }
+ int severity= IMarker.SEVERITY_ERROR;
+ if (desc.startsWith("warning")) {
+ severity= IMarker.SEVERITY_WARNING;
+ }
+ eoParser.generateMarker(file, num, desc, severity, null);
+ return true;
+ }
+ } catch (NumberFormatException e) {
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CCodeFormatter.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CCodeFormatter.java
new file mode 100644
index 00000000000..0e9022d85ba
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CCodeFormatter.java
@@ -0,0 +1,24 @@
+package org.eclipse.cdt.internal.formatter;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+public class CCodeFormatter {
+ //public FormatterOptions options;
+
+ public CCodeFormatter() {
+ }
+
+// CCodeFormatter(FormatterOptions options) {
+// }
+
+ public String formatSourceString(String content) {
+ return content;
+ }
+
+
+}
+
+
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/parser/ASCII_CharStream.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/parser/ASCII_CharStream.java
new file mode 100644
index 00000000000..d844e6171c4
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/parser/ASCII_CharStream.java
@@ -0,0 +1,414 @@
+/* Generated By:JavaCC: Do not edit this line. ASCII_CharStream.java Version 0.7pre6 */
+package org.eclipse.cdt.internal.parser;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+/* fixed ASCII_CharStream: tab is counting only one character for column */
+
+
+/**
+ * An implementation of interface CharStream, where the stream is assumed to
+ * contain only ASCII characters (without unicode processing).
+ */
+public final class ASCII_CharStream {
+ public static final boolean staticFlag= true;
+ static int bufsize;
+ static int available;
+ static int tokenBegin;
+ static public int bufpos= -1;
+ static private int bufline[];
+ static private int bufcolumn[];
+
+
+ static private int column= 0;
+ static private int line= 1;
+
+
+ static private boolean prevCharIsCR= false;
+ static private boolean prevCharIsLF= false;
+
+
+ static private java.io.Reader inputStream;
+
+
+ static private char[] buffer;
+ static private int maxNextCharInd= 0;
+ static private int inBuf= 0;
+
+
+ static private final void ExpandBuff(boolean wrapAround) {
+ char[] newbuffer= new char[bufsize + 2048];
+ int newbufline[]= new int[bufsize + 2048];
+ int newbufcolumn[]= new int[bufsize + 2048];
+
+
+ try {
+ if (wrapAround) {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
+ buffer= newbuffer;
+
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
+ bufline= newbufline;
+
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
+ bufcolumn= newbufcolumn;
+
+
+ maxNextCharInd= (bufpos += (bufsize - tokenBegin));
+ } else {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer= newbuffer;
+
+
+ System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
+ bufline= newbufline;
+
+
+ System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
+ bufcolumn= newbufcolumn;
+
+
+ maxNextCharInd= (bufpos -= tokenBegin);
+ }
+ } catch (Throwable t) {
+ throw new Error(t.getMessage());
+ }
+
+
+ bufsize += 2048;
+ available= bufsize;
+ tokenBegin= 0;
+ }
+
+
+ static private final void FillBuff() throws java.io.IOException {
+ if (maxNextCharInd == available) {
+ if (available == bufsize) {
+ if (tokenBegin > 2048) {
+ bufpos= maxNextCharInd= 0;
+ available= tokenBegin;
+ } else
+ if (tokenBegin < 0)
+ bufpos= maxNextCharInd= 0;
+ else
+ ExpandBuff(false);
+ } else
+ if (available > tokenBegin)
+ available= bufsize;
+ else
+ if ((tokenBegin - available) < 2048)
+ ExpandBuff(true);
+ else
+ available= tokenBegin;
+ }
+
+
+ int i;
+ try {
+ if ((i= inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) {
+ inputStream.close();
+ throw new java.io.IOException();
+ } else {
+ maxNextCharInd += i;
+ }
+ return;
+ } catch (java.io.IOException e) {
+ --bufpos;
+ backup(0);
+ if (tokenBegin == -1)
+ tokenBegin= bufpos;
+ throw e;
+ }
+ }
+
+
+ static public final char BeginToken() throws java.io.IOException {
+ tokenBegin= -1;
+ char c= readChar();
+ tokenBegin= bufpos;
+
+
+ return c;
+ }
+
+
+ static private final void UpdateLineColumn(char c) {
+ column++;
+
+
+ if (prevCharIsLF) {
+ prevCharIsLF= false;
+ line += (column= 1);
+ } else
+ if (prevCharIsCR) {
+ prevCharIsCR= false;
+ if (c == '\n') {
+ prevCharIsLF= true;
+ } else
+ line += (column= 1);
+ }
+
+
+ switch (c) {
+ case '\r' :
+ prevCharIsCR= true;
+ break;
+ case '\n' :
+ prevCharIsLF= true;
+ break;
+ default :
+ break;
+ }
+
+
+ bufline[bufpos]= line;
+ bufcolumn[bufpos]= column;
+ }
+
+
+ static public final char readChar() throws java.io.IOException {
+ if (inBuf > 0) {
+ --inBuf;
+ return (char) ((char) 0xff & buffer[(bufpos == bufsize - 1) ? (bufpos= 0) : ++bufpos]);
+ }
+
+
+ if (++bufpos >= maxNextCharInd) {
+ FillBuff();
+ }
+
+
+ char c= (char) ((char) 0xff & buffer[bufpos]);
+
+ // Remove '\' line continuations
+ if(c == '\\') {
+ int pos = bufpos+1;
+ if((bufpos+1) >= maxNextCharInd) {
+ // Safe to do so here, we already have the character
+ FillBuff();
+ pos = bufpos;
+ }
+ char n = (char) ((char) 0xff & buffer[pos]);
+ if((n == '\n') || (n == '\r')) {
+ UpdateLineColumn(n);
+ // We eat the \\\n combo.
+ bufpos++;
+ if(n == '\r') {
+ while((c = readChar()) == '\n');
+ }
+ } else {
+ UpdateLineColumn(c);
+ }
+ } else {
+ UpdateLineColumn(c);
+ }
+ return (c);
+ }
+
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+
+
+ static public final int getColumn() {
+ return bufcolumn[bufpos];
+ }
+
+
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+
+
+ static public final int getLine() {
+ return bufline[bufpos];
+ }
+
+
+ static public final int getEndColumn() {
+ return bufcolumn[bufpos];
+ }
+
+
+ static public final int getEndLine() {
+ return bufline[bufpos];
+ }
+
+
+ static public final int getBeginColumn() {
+ return bufcolumn[tokenBegin];
+ }
+
+
+ static public final int getBeginLine() {
+ return bufline[tokenBegin];
+ }
+
+
+ static public final void backup(int amount) {
+
+
+ inBuf += amount;
+ if ((bufpos -= amount) < 0)
+ bufpos += bufsize;
+ }
+
+
+ public ASCII_CharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) {
+ if (inputStream != null)
+ throw new Error(
+ "\n ERROR: Second call to the constructor of a static ASCII_CharStream. You must\n"
+ + " either use ReInit() or set the JavaCC option STATIC to false\n"
+ + " during the generation of this class.");
+ inputStream= dstream;
+ line= startline;
+ column= startcolumn - 1;
+
+
+ available= bufsize= buffersize;
+ buffer= new char[buffersize];
+ bufline= new int[buffersize];
+ bufcolumn= new int[buffersize];
+ }
+
+
+ public ASCII_CharStream(java.io.Reader dstream, int startline, int startcolumn) {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+
+ static public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) {
+ inputStream= dstream;
+ line= startline;
+ column= startcolumn - 1;
+
+
+ if (buffer == null || buffersize != buffer.length) {
+ available= bufsize= buffersize;
+ buffer= new char[buffersize];
+ bufline= new int[buffersize];
+ bufcolumn= new int[buffersize];
+ }
+ prevCharIsLF= prevCharIsCR= false;
+ tokenBegin= inBuf= maxNextCharInd= 0;
+ bufpos= -1;
+ }
+
+
+ static public void ReInit(java.io.Reader dstream, int startline, int startcolumn) {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+
+ public ASCII_CharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) {
+ this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+
+
+ public ASCII_CharStream(java.io.InputStream dstream, int startline, int startcolumn) {
+ this(dstream, startline, startcolumn, 4096);
+ }
+
+
+ static public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) {
+ ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
+ }
+
+
+ static public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) {
+ ReInit(dstream, startline, startcolumn, 4096);
+ }
+
+
+ static public final String GetImage() {
+ if (bufpos >= tokenBegin)
+ return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
+ else
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1);
+ }
+
+
+ static public final char[] GetSuffix(int len) {
+ char[] ret= new char[len];
+
+
+ if ((bufpos + 1) >= len)
+ System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
+ else {
+ System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, len - bufpos - 1);
+ System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
+ }
+
+
+ return ret;
+ }
+
+
+ static public void Done() {
+ buffer= null;
+ bufline= null;
+ bufcolumn= null;
+ }
+
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.AR
class is used for parsing standard ELF archive (ar) files.
+ *
+ * Each object within the archive is represented by an ARHeader class. Each of
+ * of these objects can then be turned into an Elf object for performing Elf
+ * class operations.
+ * @see ARHeader
+ */
+public class AR {
+
+ private String filename;
+ private ERandomAccessFile efile;
+ private ARHeader[] headers;
+ private long strtbl_pos = -1;
+
+
+ public void dispose() {
+ try
+ {
+ efile.close();
+ }
+ catch( IOException e )
+ {}
+ }
+
+ /**
+ * The ARHeader
class is used to store the per-object file
+ * archive headers. It can also create an Elf object for inspecting
+ * the object file data.
+ */
+ public class ARHeader {
+
+ private String object_name;
+ private String modification_time;
+ private String uid;
+ private String gid;
+ private String mode;
+ private long size;
+ private long elf_offset;
+
+
+ /**
+ * Remove the padding from the archive header strings.
+ */
+ private String removeBlanks( String str ) {
+ while( str.charAt( str.length() - 1 ) == ' ' )
+ str = str.substring( 0, str.length() - 1 );
+ return str;
+ }
+
+
+ /**
+ * Look up the name stored in the archive's string table based
+ * on the offset given.
+ *
+ * Maintains efile
file location.
+ *
+ * @param offset
+ * Offset into the string table for first character of the name.
+ * @throws IOException
+ * offset
not in string table bounds.
+ */
+ private String nameFromStringTable( long offset ) throws IOException {
+ StringBuffer name = new StringBuffer( 0 );
+ long pos = efile.getFilePointer();
+
+ try
+ {
+ if( strtbl_pos != -1 )
+ {
+ byte temp;
+ efile.seek( strtbl_pos + offset );
+ while( ( temp = efile.readByte() ) != '\n' )
+ name.append( (char)temp );
+ }
+ }
+ finally
+ {
+ efile.seek( pos );
+ }
+
+ return name.toString();
+ }
+
+
+ /**
+ * Creates a new archive header object.
+ *
+ * Assumes that efile is already at the correct location in the file.
+ *
+ * @throws IOException
+ * There was an error processing the header data from the file.
+ */
+ public ARHeader() throws IOException {
+ byte[] object_name = new byte[16];
+ byte[] modification_time = new byte[12];
+ byte[] uid = new byte[6];
+ byte[] gid = new byte[6];
+ byte[] mode = new byte[8];
+ byte[] size = new byte[10];
+ byte[] trailer = new byte[2];
+
+ //
+ // Read in the archive header data. Fixed sizes.
+ //
+ efile.read( object_name );
+ efile.read( modification_time );
+ efile.read( uid );
+ efile.read( gid );
+ efile.read( mode );
+ efile.read( size );
+ efile.read( trailer );
+
+ //
+ // Save this location so we can create the Elf object later.
+ //
+ elf_offset = efile.getFilePointer();
+
+ //
+ // Convert the raw bytes into strings and numbers.
+ //
+ this.object_name = removeBlanks( new String( object_name ) );
+ this.modification_time = new String( modification_time );
+ this.uid = new String( uid );
+ this.gid = new String( gid );
+ this.mode = new String( mode );
+ this.size = Long.parseLong( removeBlanks( new String( size ) ) );
+
+ //
+ // If the name is of the format "/AR
object from the contents of
+ * the given file.
+ *
+ * @param filename The file to process.
+ * @throws IOException The file is not a valid archive.
+ */
+ public AR( String filename ) throws IOException {
+ this.filename = filename;
+ efile = new ERandomAccessFile( filename, "r" );
+ String hdr = efile.readLine();
+ if( hdr == null || hdr.compareTo( "!ElfHelper
is a wrapper class for the Elf
class
+ * to provide higher level API for sorting/searching the ELF data.
+ *
+ * @see Elf
+ */
+public class ElfHelper {
+
+ private Elf elf;
+ private Elf.ELFhdr hdr;
+ private Elf.Attribute attrib;
+ private Elf.Symbol[] dynsyms;
+ private Elf.Symbol[] symbols;
+ private Elf.Section[] sections;
+ private Elf.Dynamic[] dynamics;
+
+
+ public void dispose() {
+ if( elf != null )
+ {
+ elf.dispose();
+ elf = null;
+ }
+ }
+
+ public class Sizes {
+ public long text;
+ public long data;
+ public long bss;
+ public long total;
+ public Sizes( long t, long d, long b ) {
+ text = t;
+ data = d;
+ bss = b;
+ total = text+data+bss;
+ }
+ }
+
+
+ private void loadSymbols() throws IOException {
+ if( symbols == null )
+ {
+ elf.loadSymbols();
+ symbols = elf.getSymtabSymbols();
+ dynsyms = elf.getDynamicSymbols();
+
+ if( symbols.length <= 0 )
+ symbols = dynsyms;
+ if( dynsyms.length <= 0 )
+ dynsyms = symbols;
+ }
+ }
+
+ private void loadSections() throws IOException {
+ if( sections == null )
+ sections = elf.getSections();
+ }
+
+
+ private void loadDynamics() throws IOException {
+ loadSections();
+
+ if( dynamics == null )
+ {
+ dynamics = new Elf.Dynamic[0];
+ for( int i=0; iElf
+ * object.
+ * @param elf An existing Elf object to wrap.
+ * @throws IOException Error processing the Elf file.
+ */
+ public ElfHelper( Elf elf ) throws IOException {
+ this.elf = elf;
+ commonSetup();
+ }
+
+ /**
+ * Create a new ElfHelper
based on the given filename.
+ *
+ * @param filename The file to use for creating a new Elf object.
+ * @throws IOException Error processing the Elf file.
+ * @see Elf#Elf( String )
+ */
+ public ElfHelper( String filename ) throws IOException {
+ elf = new Elf( filename );
+ commonSetup();
+ }
+
+ public ElfHelper( String filename, boolean filton ) throws IOException {
+ elf = new Elf( filename, filton );
+ commonSetup();
+ }
+
+ /** Give back the Elf object that this helper is wrapping */
+ public Elf getElf() {
+ return elf;
+ }
+
+ public Elf.Symbol[] getExternalFunctions()
+ throws IOException
+ {
+ Vector v = new Vector();
+
+ loadSymbols();
+ loadSections();
+
+ for( int i=0; i