From 6d107cd42e7ff103990077ed23731619d04d0522 Mon Sep 17 00:00:00 2001
From: Pawel Piech
Date: Tue, 27 Mar 2012 14:18:32 -0700
Subject: [PATCH 01/22] Bug 374512 - breakpointContribution does not support
custom field editors
Also addresses:
Bug 374514 - breakpointContribution always add Widgets on top of
common properties page
Bug 374508 - breakpointContribution does not support restrictions
---
.../cdt/debug/core/model/ICBreakpoint.java | 4 +-
.../.settings/.api_filters | 7 +
.../schema/BreakpointUIContribution.exsd | 126 ++++++++++++++----
.../breakpoints/CBreakpointPropertyPage.java | 26 ++--
.../CBreakpointUIContributionFactory.java | 105 ++++++++++-----
...CEventBreakpointsLabelProviderFactory.java | 4 +-
.../DefaultCBreakpointUIContribution.java | 73 +++++++---
.../ICBreakpointsUIContribution.java | 28 ++++
.../ui/breakpoints/IFieldEditorFactory.java | 38 ++++++
.../META-INF/MANIFEST.MF | 3 +-
.../plugin.xml | 13 ++
...AWatchpointFunctionFieldEditorFactory.java | 26 ++++
.../PDABreakpointAttributeTranslator.java | 52 +++++++-
13 files changed, 411 insertions(+), 94 deletions(-)
create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/IFieldEditorFactory.java
create mode 100644 dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/breakpoints/PDAWatchpointFunctionFieldEditorFactory.java
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java
index 0d85e473e3e..565ac48f29e 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java
@@ -35,8 +35,8 @@ public interface ICBreakpoint extends IBreakpoint {
/**
* This debug model identifier can be returned by a debug implementation
* to indicate that a given debugger integration is using C Breakpoints.
- * This model ID will allow breakpoint actions to configure their default
- * selection.
+ * This model ID will allow toggle breakpoint actions to configure their
+ * default selection.
*
* @since 7.0
*/
diff --git a/debug/org.eclipse.cdt.debug.ui/.settings/.api_filters b/debug/org.eclipse.cdt.debug.ui/.settings/.api_filters
index 48c6c7be8f5..e8df87ef673 100644
--- a/debug/org.eclipse.cdt.debug.ui/.settings/.api_filters
+++ b/debug/org.eclipse.cdt.debug.ui/.settings/.api_filters
@@ -9,4 +9,11 @@
+
+
+
+
+
+
+
diff --git a/debug/org.eclipse.cdt.debug.ui/schema/BreakpointUIContribution.exsd b/debug/org.eclipse.cdt.debug.ui/schema/BreakpointUIContribution.exsd
index d9b6c850f5d..75e7f9ff50a 100644
--- a/debug/org.eclipse.cdt.debug.ui/schema/BreakpointUIContribution.exsd
+++ b/debug/org.eclipse.cdt.debug.ui/schema/BreakpointUIContribution.exsd
@@ -2,18 +2,26 @@
-
+
-
+
- This extension point provides a mechanism for contributing UI to view and edit breakpoint attributes.
+ This extension point provides a mechanism for contributing controls for viewing and editing breakpoint attributes.
+The UI controls are added to the "Common" page of the breakpoint properties dialog. If a debug model ID is specified, the
+contribution is shown only when a debugger with corresponding model ID is currently active.
+
+
+
+
+
-
+
+
@@ -34,15 +42,20 @@
-
+
-
+
+
+
+ A breakpoint label is appended to the top section the breakpoint properties common page.
+
+
@@ -50,28 +63,65 @@
- marker type for which attribute labels are applied
+ Breakpoint's marker type for which the given attribute labels are applied.
-
+
-
+
- debug model Id for this extension is valid
-(debugModelId is a property of cbreakpoint)
+ Debug model Id of the active debug context for which this extension is valid. If not specified or if the model ID equals the CDT breakpoint's model (org.eclipse.cdt.debug.core), the option is always shown.
-
+
-
+
+
+
+
+
+
+
+
+
+ A breakpoint editor is appended to the bottom section the breakpoint properties common page.
+
+
+
+
+
+
+
+
+
+ Breakpoint's marker type for which the given attribute labels are applied.
+
+
+
+
+
+
+
+
+
+ Debug model Id of the active debug context for which this extension is valid. If not specified or if the model ID equals the CDT breakpoint's model (org.eclipse.cdt.debug.core), the option is always shown.
+
+
+
+
+
+
+ Each attribute entry displays or modifies a breakpoint attribute with the given ID.
+
+
@@ -88,28 +138,47 @@
user visible label for the breakpoint attribute value
-
+
-
+
- field editor that will be shown to for given attribute.
-If not specified this attribute will not be visible in Common page.
+ Field editor that will be shown to for given attribute. This field editor must be on the classpath of the org.eclipse.cdt.debug.ui plugin. For a custom field editor use the newer fieldEditorFactory attribute. If this parameter is not specified, the org.eclipse.cdt.debug.ui.preferences.ReadOnlyFieldEditor field editor will be used by default.
-
+
-
+
-
+
- Type of the attribute. Value should be one of "boolean", "string", "integer", "float".
+ Type of the attribute. Value should be one of "boolean", "string", "integer", "float".
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -117,8 +186,7 @@ If not specified this attribute will not be visible in Common page.
- Properties of value for parent attribute.
-If Value contains child attributes it means that these property only enabled when value of parent attribute equal to current element value
+ Properties of value for parent attribute. If a value elemnt contains child attribute elements it means that these property only enabled when value of parent attribute equal to current element value.
@@ -137,27 +205,27 @@ If Value contains child attributes it means that these property only enabled whe
User visible label for the breakpoint attribute value
-
+
-
+
-
+
-
+
CDT 5.0
-
+
-
+
<pre>
<extension id="com.xyz.coolMarkerLabels" point="org.eclipse.cdt.debug.ui.breakpointContribution">
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
index 68b8a6beb22..22626082fba 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/breakpoints/CBreakpointPropertyPage.java
@@ -34,6 +34,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.IDebugContextProvider;
@@ -462,11 +463,12 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
protected void createFieldEditors() {
ICBreakpoint breakpoint = getBreakpoint();
createMainLabel(breakpoint);
- createContributedFieldEditors(breakpoint);
+ createContributedFieldEditors(breakpoint, ICBreakpointsUIContribution.BREAKPOINT_LABELS);
createTypeSpecificLabelFieldEditors( breakpoint );
createEnabledField( getFieldEditorParent() );
createConditionEditor( getFieldEditorParent() );
createIgnoreCountEditor( getFieldEditorParent() );
+ createContributedFieldEditors(breakpoint, ICBreakpointsUIContribution.BREAKPOINT_EDITORS);
}
private void createMainLabel(ICBreakpoint breakpoint) {
@@ -760,26 +762,34 @@ public class CBreakpointPropertyPage extends FieldEditorPreferencePage implement
/**
* Creates field editors contributed using breakpointUIContribution extension point
- * @param breakpoint
*/
- private void createContributedFieldEditors(ICBreakpoint breakpoint) {
+ private void createContributedFieldEditors(ICBreakpoint breakpoint, String conMainElement) {
Composite parent = getFieldEditorParent();
+ String[] debugModelIds = CBreakpointUIContributionFactory.DEBUG_MODEL_IDS_DEFAULT;
+ IDebugModelProvider debugModelProvider = (IDebugModelProvider)DebugPlugin.getAdapter(
+ getDebugContext(), IDebugModelProvider.class);
+ if (debugModelProvider != null) {
+ debugModelIds = debugModelProvider.getModelIdentifiers();
+ }
+
try {
ICBreakpointsUIContribution[] cons;
CBreakpointUIContributionFactory factory = CBreakpointUIContributionFactory.getInstance();
IPreferenceStore prefStore = getPreferenceStore();
if (prefStore instanceof CBreakpointPreferenceStore) {
cons = factory.getBreakpointUIContributions(
- breakpoint, ((CBreakpointPreferenceStore) prefStore).getAttributes());
+ debugModelIds, breakpoint, ((CBreakpointPreferenceStore) prefStore).getAttributes());
} else {
cons = factory.getBreakpointUIContributions(breakpoint);
}
for (ICBreakpointsUIContribution con : cons) {
- FieldEditor fieldEditor = con.getFieldEditor(con.getId(), con.getLabel()+":", parent); //$NON-NLS-1$
- if (fieldEditor != null) {
- addField(fieldEditor);
- }
+ if ( conMainElement.equals(con.getMainElement()) ) {
+ FieldEditor fieldEditor = con.getFieldEditor(con.getId(), con.getLabel() + ":", parent); //$NON-NLS-1$
+ if (fieldEditor != null) {
+ addField(fieldEditor);
+ }
+ }
}
} catch (CoreException ce) {
CDebugUIPlugin.log(ce);
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CBreakpointUIContributionFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CBreakpointUIContributionFactory.java
index 9631e55c387..118d1b4b794 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CBreakpointUIContributionFactory.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CBreakpointUIContributionFactory.java
@@ -13,7 +13,9 @@
package org.eclipse.cdt.debug.ui.breakpoints;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.eclipse.cdt.debug.core.CDIDebugModel;
@@ -31,7 +33,6 @@ import org.eclipse.debug.core.model.IBreakpoint;
public class CBreakpointUIContributionFactory {
private static final String EXTENSION_POINT_NAME = "breakpointContribution"; //$NON-NLS-1$
- private static final String MAIN_ELEMENT = "breakpointLabels"; //$NON-NLS-1$
private static CBreakpointUIContributionFactory instance;
protected ArrayList contributions;
@@ -70,22 +71,28 @@ public class CBreakpointUIContributionFactory {
* @throws CoreException if cannot get marker attributes from bearkpoint
* @since 7.2
*/
- public ICBreakpointsUIContribution[] getBreakpointUIContributions(IBreakpoint breakpoint,
- Map attributes)
- throws CoreException
+ public ICBreakpointsUIContribution[] getBreakpointUIContributions(String[] debugModelIDs, IBreakpoint breakpoint,
+ Map attributes) throws CoreException
{
- String debugModelId = breakpoint.getModelIdentifier();
IMarker bmarker = breakpoint.getMarker();
String markerType = CDIDebugModel.calculateMarkerType(breakpoint);
if (bmarker != null) {
markerType = bmarker.getType();
}
- return getBreakpointUIContributions(debugModelId, markerType, attributes);
+ return getBreakpointUIContributions(debugModelIDs, markerType, attributes);
}
+ /**
+ * Default debug model ID list which will cause only the general UI contributions to be returned.
+ * @since 7.2
+ */
+ public final static String[] DEBUG_MODEL_IDS_DEFAULT = new String[] {};
+
/**
* Calculates the breakpoint UI contributions for the given breakpoint.
*
+ * @param debugModelId The debug model ID of the active debug context for
+ * which to calculate contributions.
* @param breakpoint Breakpoint to find UI contributions for.
* @param markerType Marker type of the breakpoint.
* @param attributes Attributes of the breakpoint
@@ -96,25 +103,54 @@ public class CBreakpointUIContributionFactory {
public ICBreakpointsUIContribution[] getBreakpointUIContributions(String debugModelId, String markerType,
Map attributes)
{
- ArrayList list = new ArrayList();
- for (ICBreakpointsUIContribution con : contributions) {
- try {
- if (debugModelId == null || con.getDebugModelId() == null || debugModelId.equals(con.getDebugModelId())) {
- String contributedMarkerType = con.getMarkerType();
- if (isMarkerSubtypeOf(markerType, contributedMarkerType)) {
- if (attributes == null || con.isApplicable(attributes)) {
- list.add(con);
- }
- }
- }
- } catch (Exception e) {
- CDebugUIPlugin.log(e);
- }
-
- }
- return list.toArray(new ICBreakpointsUIContribution[list.size()]);
+ return getBreakpointUIContributions(
+ debugModelId != null ? new String[] { debugModelId } : DEBUG_MODEL_IDS_DEFAULT,
+ markerType,
+ attributes);
+
}
+ /**
+ * Calculates the breakpoint UI contributions for the given breakpoint.
+ *
+ * @param debugModelId The debug model IDs of the active debug context for
+ * which to calculate contributions.
+ * @param breakpoint Breakpoint to find UI contributions for.
+ * @param markerType Marker type of the breakpoint.
+ * @param attributes Attributes of the breakpoint
+ * @return non-null array of ICBreakpointsUIContribution
+ * @throws CoreException
+ * @throws CoreException if cannot get marker attributes from berakpoint
+ *
+ * @since 7.2
+ */
+ public ICBreakpointsUIContribution[] getBreakpointUIContributions(String[] debugModelIds, String markerType,
+ Map attributes)
+ {
+ List debugModelIdsList = Arrays.asList(debugModelIds);
+ ArrayList list = new ArrayList();
+ for (ICBreakpointsUIContribution con : contributions) {
+ try {
+ if (con.getDebugModelId() == null ||
+ con.getDebugModelId().equals(CDIDebugModel.getPluginIdentifier()) ||
+ debugModelIdsList.contains(con.getDebugModelId()))
+ {
+ String contributedMarkerType = con.getMarkerType();
+ if (isMarkerSubtypeOf(markerType, contributedMarkerType)) {
+ if (attributes == null || con.isApplicable(attributes)) {
+ list.add(con);
+ }
+ }
+ }
+ } catch (Exception e) {
+ CDebugUIPlugin.log(e);
+ }
+
+ }
+ return list.toArray(new ICBreakpointsUIContribution[list.size()]);
+ }
+
+
public boolean isMarkerSubtypeOf(String currentType, String type) throws CoreException {
return getWorkspace().getMarkerManager().isSubtype(currentType, type);
}
@@ -132,15 +168,19 @@ public class CBreakpointUIContributionFactory {
IConfigurationElement[] elements = ep.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
IConfigurationElement configurationElement = elements[i];
- if (configurationElement.getName().equals(MAIN_ELEMENT)) {
+ if (configurationElement.getName().equals(ICBreakpointsUIContribution.BREAKPOINT_LABELS) ||
+ configurationElement.getName().equals(ICBreakpointsUIContribution.BREAKPOINT_EDITORS))
+ {
+ String mainElement = configurationElement.getName();
String modelId = configurationElement.getAttribute("debugModelId"); //$NON-NLS-1$
String markerType = getRequired(configurationElement, "markerType"); //$NON-NLS-1$
if (markerType == null)
continue;
IConfigurationElement[] children = configurationElement.getChildren("attribute"); //$NON-NLS-1$
for (IConfigurationElement att : children) {
-
- DefaultCBreakpointUIContribution adapter = new DefaultCBreakpointUIContribution();
+
+ DefaultCBreakpointUIContribution adapter = new DefaultCBreakpointUIContribution(att);
+ adapter.setMainElement(mainElement);
adapter.setMarkerType(markerType);
adapter.setDebugModelId(modelId);
if (processAttribute(att, adapter) == false)
@@ -152,10 +192,13 @@ public class CBreakpointUIContributionFactory {
}
}
- private boolean processAttribute(IConfigurationElement attrElement, DefaultCBreakpointUIContribution adapter) {
+ private boolean processAttribute(IConfigurationElement attrElement,
+ DefaultCBreakpointUIContribution adapter)
+ {
String attrId = getRequired(attrElement, "name"); //$NON-NLS-1$
String attrLabel = getRequired(attrElement, "label"); //$NON-NLS-1$
- String className = attrElement.getAttribute("fieldEditor"); //$NON-NLS-1$
+ String fieldEditorClass = attrElement.getAttribute("fieldEditor"); //$NON-NLS-1$
+ String fieldEditorFactoryClass = attrElement.getAttribute("fieldEditorFactory"); //$NON-NLS-1$
String type = attrElement.getAttribute("type"); //$NON-NLS-1$
String svisible = attrElement.getAttribute("visible"); //$NON-NLS-1$
@@ -174,7 +217,8 @@ public class CBreakpointUIContributionFactory {
}
adapter.setId(attrId);
adapter.setLabel(attrLabel);
- adapter.setControlClass(className);
+ adapter.setControlClass(fieldEditorClass);
+ adapter.setFieldEditorFactory(fieldEditorFactoryClass);
adapter.setType(type);
adapter.setVisible(visible);
addContribution(adapter);
@@ -196,8 +240,9 @@ public class CBreakpointUIContributionFactory {
adapter.addValue(valueId, valueLabel);
IConfigurationElement[] children = valueElement.getChildren("attribute"); //$NON-NLS-1$
for (IConfigurationElement att : children) {
- DefaultCBreakpointUIContribution adapter2 = new DefaultCBreakpointUIContribution();
+ DefaultCBreakpointUIContribution adapter2 = new DefaultCBreakpointUIContribution(att);
// inherit values
+ adapter2.setMainElement(adapter.getMainElement());
adapter2.setMarkerType(adapter.getMarkerType());
adapter2.setDebugModelId(adapter.getDebugModelId());
adapter2.addContionsAll(adapter.getConditions());
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CEventBreakpointsLabelProviderFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CEventBreakpointsLabelProviderFactory.java
index 53c76328c19..953ba4eb1a2 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CEventBreakpointsLabelProviderFactory.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/CEventBreakpointsLabelProviderFactory.java
@@ -96,7 +96,7 @@ public class CEventBreakpointsLabelProviderFactory implements IAdapterFactory {
if (ignoreCount > 0) {
label.append(' ');
label.append(MessageFormat.format(
- DebugCoreMessages.getString("CDebugUtils.3"), new String[] { Integer.toString(ignoreCount) })); //$NON-NLS-1$
+ DebugCoreMessages.getString("CDebugUtils.3"), new Object[] { Integer.toString(ignoreCount) })); //$NON-NLS-1$
}
return label;
}
@@ -106,7 +106,7 @@ public class CEventBreakpointsLabelProviderFactory implements IAdapterFactory {
if (condition != null && condition.length() > 0) {
buffer.append(' ');
buffer.append(MessageFormat
- .format(DebugCoreMessages.getString("CDebugUtils.4"), new String[] { condition })); //$NON-NLS-1$
+ .format(DebugCoreMessages.getString("CDebugUtils.4"), new Object[] { condition })); //$NON-NLS-1$
}
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/DefaultCBreakpointUIContribution.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/DefaultCBreakpointUIContribution.java
index 65c2bc81394..00d5b6107ba 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/DefaultCBreakpointUIContribution.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/DefaultCBreakpointUIContribution.java
@@ -20,19 +20,31 @@ import java.util.Set;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.preferences.ReadOnlyFieldEditor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.widgets.Composite;
class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
+
+ private final IConfigurationElement fConfig;
+ private String mainElement;
private String attLabel;
private String attId;
private String fieldEditorClassName;
+ private String fieldEditorFactoryClass;
+ private IFieldEditorFactory fieldEditorFactory;
private String markerType;
private String modelId;
private String attType;
private Map valueLabels = new LinkedHashMap();
private Map conditions = new HashMap();
+ DefaultCBreakpointUIContribution(IConfigurationElement config) {
+ fConfig = config;
+ }
+
+
@Override
public String getId() {
return attId;
@@ -48,28 +60,43 @@ class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
return modelId;
}
- static private Class[] fieldSignature = new Class[] { String.class, String.class,
+ @Override
+ public String getMainElement() {
+ return mainElement;
+ }
+
+ static private Class>[] fieldSignature = new Class[] { String.class, String.class,
Composite.class };
@Override
public FieldEditor getFieldEditor(String name, String labelText, Composite parent) {
- String className = fieldEditorClassName;
- if (fieldEditorClassName == null) {
- className = ReadOnlyFieldEditor.class.getName();
- }
- try {
- Class cclass = Class.forName(className);
- Constructor constructor = cclass.getConstructor(fieldSignature);
- FieldEditor editor = (FieldEditor) constructor.newInstance(name, labelText, parent);
- if (editor instanceof ICBreakpointsUIContributionUser) {
- ((ICBreakpointsUIContributionUser)editor).setContribution(this);
- }
- return editor;
- } catch (Exception e) {
- // cannot happened, would have happened when loading extension
- CDebugUIPlugin.log(e);
- return null;
- }
+ if (fieldEditorFactory != null) {
+ return fieldEditorFactory.createFieldEditor(name, labelText, parent);
+ } else if (fieldEditorFactoryClass != null) {
+ try {
+ fieldEditorFactory = (IFieldEditorFactory) fConfig.createExecutableExtension("fieldEditorFactory"); //$NON-NLS-1$
+ } catch (CoreException e) {
+ CDebugUIPlugin.log(e);
+ return null;
+ }
+ return fieldEditorFactory.createFieldEditor(name, labelText, parent);
+ } else if (fieldEditorClassName != null) {
+ try {
+ @SuppressWarnings("unchecked")
+ Class cclass = (Class)Class.forName(fieldEditorClassName);
+ Constructor constructor = cclass.getConstructor(fieldSignature);
+ FieldEditor editor = constructor.newInstance(name, labelText, parent);
+ if (editor instanceof ICBreakpointsUIContributionUser) {
+ ((ICBreakpointsUIContributionUser)editor).setContribution(this);
+ }
+ return editor;
+ } catch (Exception e) {
+ CDebugUIPlugin.log(e);
+ return null;
+ }
+ } else {
+ return new ReadOnlyFieldEditor(name, labelText, parent);
+ }
}
@Override
@@ -96,7 +123,7 @@ class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
}
@Override
- public boolean isApplicable(Map properties) {
+ public boolean isApplicable(Map properties) {
for (Object key : properties.keySet()) {
String value = conditions.get(key);
if (value != null) {
@@ -109,6 +136,10 @@ class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
return true;
}
+ public void setMainElement(String mainElement) {
+ this.mainElement = mainElement;
+ }
+
public void setLabel(String attLabel) {
this.attLabel = attLabel;
}
@@ -120,6 +151,10 @@ class DefaultCBreakpointUIContribution implements ICBreakpointsUIContribution {
public void setControlClass(String controlClass) {
this.fieldEditorClassName = controlClass;
}
+
+ public void setFieldEditorFactory(String factoryClass) {
+ fieldEditorFactoryClass = factoryClass;
+ }
public void setMarkerType(String markerId) {
this.markerType = markerId;
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/ICBreakpointsUIContribution.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/ICBreakpointsUIContribution.java
index a0a5aaf2c9a..a21489d4fe8 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/ICBreakpointsUIContribution.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/ICBreakpointsUIContribution.java
@@ -19,13 +19,33 @@ import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.widgets.Composite;
+/**
+ * Interface representing a contributed UI element for breakpoint properties
+ * dialogs.
+ *
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ */
public interface ICBreakpointsUIContribution {
+ /**
+ * Main element name of breakpoint labels extension element.
+ * @since 7.2
+ */
+ public static final String BREAKPOINT_LABELS = "breakpointLabels"; //$NON-NLS-1$
+
+ /**
+ * Main element name of breakpoint editors extension element.
+ * @since 7.2
+ */
+ public static final String BREAKPOINT_EDITORS = "breakpointEditors"; //$NON-NLS-1$
+
/**
* Attribute id
* @return
*/
public String getId();
+
/**
* Extenralizable label for this attribute id
* @return
@@ -41,6 +61,14 @@ public interface ICBreakpointsUIContribution {
*/
public FieldEditor getFieldEditor(String name, String labelText, Composite parent);
+ /**
+ * Returns the element name under which this attribute was added. The value should either be
+ * "breakpointLabels" or "breakpointEditors".
+ * @return Main element name.
+ * @since 7.2
+ */
+ public String getMainElement();
+
/**
* Get raw field editor class name
* @return class name
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/IFieldEditorFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/IFieldEditorFactory.java
new file mode 100644
index 00000000000..0ccb6f985d3
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/IFieldEditorFactory.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.debug.ui.breakpoints;
+
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Factory for creating field editors contributed through the
+ * org.eclipse.cdt.debug.ui.breakpointContribution
extension point.
+ *
+ * Field editors do not have a non-arg constructor, therefore custom editors
+ * cannot be created directly by the extension point directly. This factory
+ * allows clients to instantiate a custom field editor which is not on the class
+ * path of the CDT debug UI plugin.
+ *
+ * @since 7.2
+ */
+public interface IFieldEditorFactory {
+
+ /**
+ * Creates a field editor with given parameters.
+ *
+ * @param name Field editor's property name.
+ * @param labelText Field editors label.
+ * @param parent Field editors parent control.
+ * @return Newly created field editor.
+ */
+ public FieldEditor createFieldEditor(String name, String labelText, Composite parent);
+}
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/META-INF/MANIFEST.MF b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/META-INF/MANIFEST.MF
index 62e756489dc..266cd29f9b8 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/META-INF/MANIFEST.MF
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.cdt.examples.dsf.pda,
org.eclipse.cdt.dsf,
- org.eclipse.cdt.dsf.ui
+ org.eclipse.cdt.dsf.ui,
+ org.eclipse.cdt.debug.ui;bundle-version="7.2.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.examples.dsf.pda.ui,
org.eclipse.cdt.examples.dsf.pda.ui.breakpoints,
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
index 16608bd2233..4a7413cccf7 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
@@ -110,5 +110,18 @@
class="org.eclipse.cdt.examples.dsf.pda.ui.viewmodel.VariablePersistableFactory"
id="org.eclipse.cdt.examples.dsf.pda.ui.variablePersitableFactory">
+
+
+
+
+
+
-->
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/breakpoints/PDAWatchpointFunctionFieldEditorFactory.java b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/breakpoints/PDAWatchpointFunctionFieldEditorFactory.java
new file mode 100644
index 00000000000..0c01b97b734
--- /dev/null
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/breakpoints/PDAWatchpointFunctionFieldEditorFactory.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.examples.dsf.pda.ui.breakpoints;
+
+import org.eclipse.cdt.debug.ui.breakpoints.IFieldEditorFactory;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ *
+ */
+public class PDAWatchpointFunctionFieldEditorFactory implements IFieldEditorFactory {
+
+ public FieldEditor createFieldEditor(String name, String labelText, Composite parent) {
+ return new StringFieldEditor(name, labelText, parent);
+ }
+}
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDABreakpointAttributeTranslator.java b/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDABreakpointAttributeTranslator.java
index 1a082761534..3b3a18a0bfe 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDABreakpointAttributeTranslator.java
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDABreakpointAttributeTranslator.java
@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
+import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator;
import org.eclipse.cdt.dsf.debug.service.BreakpointsMediator2;
@@ -59,6 +60,11 @@ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTra
PDAWatchpoint.MODIFICATION
};
+ private static final String[] fgCDTWatchpointAttributes = {
+ IBreakpoint.ENABLED,
+ PDAWatchpoint.FUNCTION_NAME,
+ };
+
// PDA breakpoints translator doesn't keep any state and it doesn't
// need to initialize or clean up.
public void initialize(BreakpointsMediator2 mediator) {
@@ -71,8 +77,10 @@ public class PDABreakpointAttributeTranslator implements IBreakpointAttributeTra
private List
- *
+ *
* @since 5.0
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public final class ASTRewrite {
/**
* Defines the positions of the comment.
- *
+ *
* @since 5.3
*/
public enum CommentPosition {
@@ -67,7 +67,7 @@ public final class ASTRewrite {
*/
freestanding
}
-
+
/**
* Creates a rewriter for a translation unit.
*/
@@ -80,7 +80,7 @@ public final class ASTRewrite {
private final ASTModificationStore fModificationStore;
private final ASTModification fParentMod;
private final NodeCommentMap fCommentMap;
-
+
private enum Operation {
insertBefore,
replace,
@@ -99,8 +99,8 @@ public final class ASTRewrite {
* Creates and returns a node for a source string that is to be inserted into
* the output document.
* The string will be inserted without being reformatted beyond correcting
- * the indentation level.
- *
+ * the indentation level.
+ *
* @param code the string to be inserted; lines should not have extra indentation
* @return a synthetic node representing the literal code.
* @throws IllegalArgumentException if the code is null.
@@ -115,7 +115,7 @@ public final class ASTRewrite {
*
* @param node the node being removed
* @param editGroup the edit group in which to collect the corresponding
- * text edits, or null
+ * text edits, or null
* @throws IllegalArgumentException if the node is null, the node is not
* part of this rewriter's AST.
*/
@@ -129,13 +129,13 @@ public final class ASTRewrite {
/**
* Replaces the given node in this rewriter. The ast is not modified, the rewriter
* just records the replacement.
- * The replacement node can be part of a translation-unit or it is a synthetic
+ * The replacement node can be part of a translation-unit or it is a synthetic
* (newly created) node.
*
* @param node the node being replaced
* @param replacement the node replacing the given one
* @param editGroup the edit group in which to collect the corresponding text edits,
- * or null
+ * or null
* @return a rewriter for further rewriting the replacement node.
* @throws IllegalArgumentException if the node or the replacement is null, or if the node is
* not part of this rewriter's AST
@@ -155,14 +155,14 @@ public final class ASTRewrite {
/**
* Inserts the given node in this rewriter. The ast is not modified, the rewriter
* just records the insertion.
- * The new node can be part of a translation-unit or it is a synthetic
+ * The new node can be part of a translation-unit or it is a synthetic
* (newly created) node.
* @param parent the parent the new node is added to.
* @param insertionPoint the node before which the insertion shall be done, or null
* for inserting after the last child.
- * @param newNode the node being inserted
+ * @param newNode the node being inserted
* @param editGroup the edit group in which to collect the corresponding
- * text edits, or null
+ * text edits, or null
* @return a rewriter for further rewriting the inserted node.
* @throws IllegalArgumentException if the parent or the newNode is null, or if the parent is
* not part of this rewriter's AST, or the insertionPoint is not a child of the parent.
@@ -191,17 +191,17 @@ public final class ASTRewrite {
fModificationStore.storeModification(fParentMod, mod);
return new ASTRewrite(newNode, fModificationStore, mod, fCommentMap);
}
-
+
/**
* Converts all modifications recorded by this rewriter into the change object required by
* the refactoring framework.
*
- * Calling this methods does not discard the modifications on record. Subsequence modifications
+ * Calling this methods does not discard the modifications on record. Subsequence modifications
* are added to the ones already on record. If this method is called again later,
* the resulting text edit object will accurately reflect the net cumulative affect of all those
* changes.
*
- *
+ *
* @return Change object describing the changes to the document corresponding to the changes
* recorded by this rewriter
* @since 5.0
@@ -210,7 +210,8 @@ public final class ASTRewrite {
if (!(fRoot instanceof IASTTranslationUnit)) {
throw new IllegalArgumentException("This API can only be used for the root rewrite object."); //$NON-NLS-1$
}
- return ASTRewriteAnalyzer.rewriteAST((IASTTranslationUnit) fRoot, fModificationStore, fCommentMap);
+ return ASTRewriteAnalyzer.rewriteAST((IASTTranslationUnit) fRoot, fModificationStore,
+ fCommentMap);
}
private void checkBelongsToAST(IASTNode node) {
@@ -222,7 +223,7 @@ public final class ASTRewrite {
}
throw new IllegalArgumentException();
}
-
+
private void checkSupportedNode(IASTNode node, Operation op) {
if (node instanceof IASTComment) {
if (op != Operation.remove) {
@@ -234,12 +235,12 @@ public final class ASTRewrite {
}
if (node instanceof IASTProblem) {
throw new IllegalArgumentException("Rewriting problem nodes is not supported"); //$NON-NLS-1$
- }
+ }
}
/**
* Assigns the comment to the node.
- *
+ *
* @param node the node.
* @param comment the comment to be attached to the node at the given position.
* @param pos the position of the comment.
@@ -261,7 +262,7 @@ public final class ASTRewrite {
/**
* Returns comments for the given node.
- *
+ *
* @param node the node
* @param pos the position of the comments
* @return All comments assigned to the node at this position
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
index 2ad28acedcb..44c789f50ba 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTWhileStatement.java
@@ -27,8 +27,8 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
public class CPPASTWhileStatement extends ASTNode
implements ICPPASTWhileStatement, IASTAmbiguityParent {
private IASTExpression condition;
- private IASTStatement body;
private IASTDeclaration condition2;
+ private IASTStatement body;
private IScope scope;
public CPPASTWhileStatement() {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index 106d7934251..886841c7edf 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
- *******************************************************************************/
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -20,7 +20,8 @@ import org.eclipse.ltk.core.refactoring.TextFileChange;
public class ASTRewriteAnalyzer {
private static ICTextFileChangeFactory sFileChangeFactory;
- public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore, NodeCommentMap commentMap) {
+ public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore,
+ NodeCommentMap commentMap) {
ChangeGenerator rewriter = new ChangeGenerator(modificationStore, commentMap);
rewriter.generateChange(root);
return rewriter.getChange();
@@ -29,7 +30,7 @@ public class ASTRewriteAnalyzer {
public static void setCTextFileChangeFactory(ICTextFileChangeFactory factory) {
sFileChangeFactory= factory;
}
-
+
public static TextFileChange createCTextFileChange(IFile file) {
if (sFileChangeFactory == null) {
return new TextFileChange(file.getName(), file);
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java
index f0d99b53f28..c3582ae8c3f 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractlocalvariable/ExtractLocalVariableRefactoringTest.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/
@@ -333,7 +333,6 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
}
//A.cpp
- //
//template
//class Foo {
//};
@@ -345,7 +344,6 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
// return 0;
//}
//====================
- //
//template
//class Foo {
//};
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
index 4a1618d5268..2aba31b03dd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
@@ -643,8 +643,8 @@ public class ExtractFunctionRefactoring extends CRefactoring {
insertion = new InsertionInfo(parent, functionToExtractFrom);
}
if (insertion.getPrologue() != null) {
- rewrite.insertBefore(insertion.getParentNode(),
- insertion.getInsertBeforeNode(), insertion.getPrologue(), group);
+ rewrite.insertBefore(insertion.getParentNode(), insertion.getInsertBeforeNode(),
+ insertion.getPrologue(), group);
}
subRewrite = rewrite.insertBefore(insertion.getParentNode(),
insertion.getInsertBeforeNode(), nodeToInsert, group);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFromImplementationToHeaderOrClassStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFromImplementationToHeaderOrClassStrategy.java
index a1ea8336546..b7ab8fa087b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFromImplementationToHeaderOrClassStrategy.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleFromImplementationToHeaderOrClassStrategy.java
@@ -120,9 +120,9 @@ public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleR
ICPPASTCompositeTypeSpecifier.class);
IASTNode parentnode = null;
if (parent != null) {
- parentnode = parent;
+ parentnode = parent;
} else {
- parentnode =context.getDeclarationAST();
+ parentnode = context.getDeclarationAST();
}
return parentnode;
}
From ef82e2a7b2d5a3cd3de95508fcfe055384beca58 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 11:44:34 -0700
Subject: [PATCH 10/22] Cosmetics.
---
.../replace/PointerInParameterTest.java | 6 +++---
.../replace/ReplaceForLoopBodyTest.java | 14 ++++----------
.../replace/ReplaceInsertStatementTest.java | 4 +---
.../extractfunction/ExtractFunctionInputPage.java | 2 +-
4 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java
index 86936d0effb..c13d597cbf1 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/PointerInParameterTest.java
@@ -13,21 +13,21 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
-import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification.ModificationKind;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
public class PointerInParameterTest extends ChangeGeneratorTest {
public PointerInParameterTest() {
- super("Replace Pointer for Parameter"); //$NON-NLS-1$
+ super("PointerInParameterTest"); //$NON-NLS-1$
}
@Override
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceForLoopBodyTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceForLoopBodyTest.java
index cd03e41d3ea..04dd81f7b6e 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceForLoopBodyTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceForLoopBodyTest.java
@@ -7,30 +7,25 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace;
import junit.framework.Test;
-import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
-
-
-
-
public class ReplaceForLoopBodyTest extends ChangeGeneratorTest {
-
- private boolean forReplaced = false;
+ private boolean forReplaced;
public ReplaceForLoopBodyTest(){
- super("Replace For-Loop"); //$NON-NLS-1$
+ super("ReplaceForLoopBodyTest"); //$NON-NLS-1$
}
@Override
@@ -45,7 +40,6 @@ public class ReplaceForLoopBodyTest extends ChangeGeneratorTest {
return new ReplaceForLoopBodyTest();
}
-
@Override
protected ASTVisitor createModificator(
final ASTModificationStore modStore) {
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceInsertStatementTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceInsertStatementTest.java
index ec9997d57c1..54edf670e7b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceInsertStatementTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceInsertStatementTest.java
@@ -65,8 +65,7 @@ public class ReplaceInsertStatementTest extends ChangeGeneratorTest {
IASTLiteralExpression value = new CPPASTLiteralExpression(
IASTLiteralExpression.lk_integer_constant, "42".toCharArray());
IASTExpressionStatement insertStmt = new CPPASTExpressionStatement(
- new CPPASTBinaryExpression(
- IASTBinaryExpression.op_assign, id, value));
+ new CPPASTBinaryExpression(IASTBinaryExpression.op_assign, id, value));
IASTIdExpression incId = new CPPASTIdExpression(
new CPPASTName("i".toCharArray()));
@@ -88,5 +87,4 @@ public class ReplaceInsertStatementTest extends ChangeGeneratorTest {
}
};
}
-
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInputPage.java
index 78ac71edbe9..b1a58bdf269 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInputPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionInputPage.java
@@ -251,7 +251,7 @@ public class ExtractFunctionInputPage extends UserInputWizardPage {
return;
if (methodName.isEmpty()) {
- methodName = StubUtility.suggestMethodName("someMethodName", null, //$NON-NLS-1$
+ methodName = StubUtility.suggestMethodName("extracted", null, //$NON-NLS-1$
refactoring.getTranslationUnit());
}
From b424f35ce4e5df293f6a7139d7f93960916f1c9c Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 17:17:01 -0700
Subject: [PATCH 11/22] Cosmetics.
---
.../ChangeGeneratorTestSuite.java | 4 +-
.../insertbefore/InsertBeforeTestSuite.java | 2 +-
.../replace/ReplaceTestSuite.java | 2 +-
.../cdt/internal/core/pdom/PDOMManager.java | 13 +-
.../internal/ui/launching/CArgumentsTab.java | 145 +++++++-----------
.../launch/ui/CLaunchConfigurationTab.java | 19 +--
6 files changed, 73 insertions(+), 112 deletions(-)
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java
index 68acede3815..b473b7b3e44 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTestSuite.java
@@ -22,10 +22,10 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.Replace
/**
* @author Thomas Corbat
*/
-public class ChangeGeneratorTestSuite{
+public class ChangeGeneratorTestSuite {
public static Test suite() throws Exception {
- TestSuite suite = new TestSuite("ChangeGeneratorTests");
+ TestSuite suite = new TestSuite("ChangeGeneratorTestSuite");
suite.addTest(ReplaceTestSuite.suite());
suite.addTest(RemoveTestSuite.suite());
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java
index bd847e623ad..4fcc0039c70 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/insertbefore/InsertBeforeTestSuite.java
@@ -20,7 +20,7 @@ import junit.framework.TestSuite;
public class InsertBeforeTestSuite {
public static Test suite() throws Exception {
- TestSuite suite = new TestSuite("ChangeGenerator InsertBefore Tests");
+ TestSuite suite = new TestSuite("InsertBeforeTestSuite");
suite.addTest(FirstParameterTest.suite());
suite.addTest(PointerParameterTest.suite());
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java
index e0c52e5d88c..ebabb020021 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/replace/ReplaceTestSuite.java
@@ -20,7 +20,7 @@ import junit.framework.TestSuite;
public class ReplaceTestSuite {
public static Test suite() throws Exception {
- TestSuite suite = new TestSuite("ChangeGeneratorReplaceTests");
+ TestSuite suite = new TestSuite("ReplaceTestSuite");
suite.addTest(NameTest.suite());
suite.addTest(MoveTest.suite());
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index 09a72dba2c4..d79b5dd70f6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -85,6 +85,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -494,6 +495,8 @@ public class PDOMManager implements IWritableIndexManager, IListener {
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
Properties props= IndexerPreferences.getProperties(prj);
+ // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
+ synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(prj.getName())) {
return;
@@ -517,7 +520,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
enqueue(new PDOMRebuildTask(indexer));
}
- }
+ }}
if (oldIndexer != null) {
stopIndexer(oldIndexer);
@@ -550,6 +553,8 @@ public class PDOMManager implements IWritableIndexManager, IListener {
assert !Thread.holdsLock(fProjectToPDOM);
try {
+ // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
+ synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(name)) {
if (fTraceIndexerSetup)
@@ -599,12 +604,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
return;
}
- }
+ }}
// rebuild is required, try import first.
TeamPDOMImportOperation operation= new TeamPDOMImportOperation(project);
operation.run(pm);
+ // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
+ synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(name)) {
if (fTraceIndexerSetup)
@@ -633,7 +640,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
enqueue(task);
}
- }
+ }}
} catch (CoreException e) {
// Ignore if project is no longer open
if (prj.isOpen()) {
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CArgumentsTab.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CArgumentsTab.java
index 84fded9fdb8..a9ef92021ed 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CArgumentsTab.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CArgumentsTab.java
@@ -38,7 +38,6 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-
/**
* A launch configuration tab that displays and edits program arguments,
* and working directory launch configuration attributes.
@@ -47,7 +46,6 @@ import org.eclipse.swt.widgets.Text;
*
*/
public class CArgumentsTab extends CLaunchConfigurationTab {
-
/**
* Tab identifier used for ordering of tabs added using the
* org.eclipse.debug.ui.launchConfigurationTabs
@@ -65,20 +63,17 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
// Working directory
protected WorkingDirectoryBlock fWorkingDirectoryBlock = new WorkingDirectoryBlock();
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
- */
@Override
public void createControl(Composite parent) {
- Font font = parent.getFont();
- Composite comp = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout(1, true);
- comp.setLayout(layout);
- comp.setFont(font);
-
- GridData gd = new GridData(GridData.FILL_BOTH);
- comp.setLayoutData(gd);
- setControl(comp);
+ Font font = parent.getFont();
+ Composite comp = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ comp.setLayout(layout);
+ comp.setFont(font);
+
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ comp.setLayoutData(gd);
+ setControl(comp);
GdbUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(), ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_ARGUMNETS_TAB);
@@ -87,52 +82,46 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
fWorkingDirectoryBlock.createControl(comp);
}
- protected void createArgumentComponent(Composite comp, int horizontalSpan) {
- Font font = comp.getFont();
- Group group = new Group(comp, SWT.NONE);
- group.setFont(font);
- group.setLayout(new GridLayout());
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.horizontalSpan = horizontalSpan;
- group.setLayoutData(gd);
-
- group.setText(LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments")); //$NON-NLS-1$
- fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
- fPrgmArgumentsText.getAccessible().addAccessibleListener(
- new AccessibleAdapter() {
- @Override
- public void getName(AccessibleEvent e) {
- e.result = LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments"); //$NON-NLS-1$
- }
- }
- );
- gd = new GridData(GridData.FILL_BOTH);
- gd.heightHint = 40;
- gd.widthHint = 100;
- fPrgmArgumentsText.setLayoutData(gd);
- fPrgmArgumentsText.setFont(font);
- fPrgmArgumentsText.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent evt) {
- updateLaunchConfigurationDialog();
- }
- });
- fArgumentVariablesButton= createPushButton(group, LaunchMessages.getString("CArgumentsTab.Variables"), null); //$NON-NLS-1$
- gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
- fArgumentVariablesButton.setLayoutData(gd);
- fArgumentVariablesButton.addSelectionListener(new SelectionAdapter() {
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- handleVariablesButtonSelected(fPrgmArgumentsText);
- }
-
- });
- addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons
- }
+ protected void createArgumentComponent(Composite comp, int horizontalSpan) {
+ Font font = comp.getFont();
+ Group group = new Group(comp, SWT.NONE);
+ group.setFont(font);
+ group.setLayout(new GridLayout());
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.horizontalSpan = horizontalSpan;
+ group.setLayoutData(gd);
+
+ group.setText(LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments")); //$NON-NLS-1$
+ fPrgmArgumentsText = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
+ fPrgmArgumentsText.getAccessible().addAccessibleListener(
+ new AccessibleAdapter() {
+ @Override
+ public void getName(AccessibleEvent e) {
+ e.result = LaunchMessages.getString("CArgumentsTab.C/C++_Program_Arguments"); //$NON-NLS-1$
+ }
+ });
+ gd = new GridData(GridData.FILL_BOTH);
+ gd.heightHint = 40;
+ gd.widthHint = 100;
+ fPrgmArgumentsText.setLayoutData(gd);
+ fPrgmArgumentsText.setFont(font);
+ fPrgmArgumentsText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent evt) {
+ updateLaunchConfigurationDialog();
+ }
+ });
+ fArgumentVariablesButton= createPushButton(group, LaunchMessages.getString("CArgumentsTab.Variables"), null); //$NON-NLS-1$
+ gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
+ fArgumentVariablesButton.setLayoutData(gd);
+ fArgumentVariablesButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ handleVariablesButtonSelected(fPrgmArgumentsText);
+ }
+ });
+ addControlAccessibleListener(fArgumentVariablesButton, fArgumentVariablesButton.getText()); // need to strip the mnemonic from buttons
+ }
/**
* A variable entry button has been pressed for the given text
@@ -142,7 +131,6 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
protected void handleVariablesButtonSelected(Text textField) {
String variable = getVariable();
if (variable != null) {
- // We should use insert() but not append() to be consistent with the Platform behavior (e.g. Common tab)
textField.insert(variable);
}
}
@@ -158,7 +146,7 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
}
public void addControlAccessibleListener(Control control, String controlName) {
- //strip mnemonic (&)
+ // Strip mnemonic (&)
String[] strs = controlName.split("&"); //$NON-NLS-1$
StringBuffer stripped = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
@@ -169,36 +157,28 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
private class ControlAccessibleListener extends AccessibleAdapter {
private String controlName;
+
ControlAccessibleListener(String name) {
controlName = name;
}
+
@Override
public void getName(AccessibleEvent e) {
e.result = controlName;
}
-
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
- */
@Override
public boolean isValid(ILaunchConfiguration config) {
return fWorkingDirectoryBlock.isValid(config);
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
- */
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy config) {
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String) null);
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
- */
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
@@ -211,9 +191,6 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
}
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
- */
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
configuration.setAttribute(
@@ -242,26 +219,17 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
return TAB_ID;
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
- */
@Override
public String getName() {
return LaunchMessages.getString("CArgumentsTab.Arguments"); //$NON-NLS-1$
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setLaunchConfigurationDialog(org.eclipse.debug.ui.ILaunchConfigurationDialog)
- */
@Override
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
super.setLaunchConfigurationDialog(dialog);
fWorkingDirectoryBlock.setLaunchConfigurationDialog(dialog);
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getErrorMessage()
- */
@Override
public String getErrorMessage() {
String m = super.getErrorMessage();
@@ -271,9 +239,6 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
return m;
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getMessage()
- */
@Override
public String getMessage() {
String m = super.getMessage();
@@ -283,17 +248,11 @@ public class CArgumentsTab extends CLaunchConfigurationTab {
return m;
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
- */
@Override
public Image getImage() {
return LaunchImages.get(LaunchImages.IMG_VIEW_ARGUMENTS_TAB);
}
- /* (non-Javadoc)
- * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
- */
@Override
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
index 27280d70d51..5bce11d045f 100644
--- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
+++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
@@ -8,7 +8,6 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Ken Ryall (Nokia) - bug 178731
- * Anton Gorenkov
*******************************************************************************/
package org.eclipse.cdt.launch.ui;
@@ -45,7 +44,6 @@ import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
public abstract class CLaunchConfigurationTab extends AbstractLaunchConfigurationTab {
-
/**
* Returns the current C element context from which to initialize default
* settings, or null
if none. Note, if possible we will
@@ -85,9 +83,9 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
}
}
if (obj instanceof IResource) {
- ICElement ce = CoreModel.getDefault().create((IResource)obj);
+ ICElement ce = CoreModel.getDefault().create((IResource) obj);
if (ce == null) {
- IProject pro = ((IResource)obj).getProject();
+ IProject pro = ((IResource) obj).getProject();
ce = CoreModel.getDefault().create(pro);
}
obj = ce;
@@ -96,7 +94,7 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
if (platform != null && !platform.equals("*")) { //$NON-NLS-1$
ICDescriptor descriptor;
try {
- descriptor = CCorePlugin.getDefault().getCProjectDescription( ((ICElement)obj).getCProject().getProject(),
+ descriptor = CCorePlugin.getDefault().getCProjectDescription(((ICElement) obj).getCProject().getProject(),
false);
if (descriptor != null) {
String projectPlatform = descriptor.getPlatform();
@@ -109,9 +107,9 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
}
if (obj != null) {
if (programName == null || programName.equals("")) { //$NON-NLS-1$
- return (ICElement)obj;
+ return (ICElement) obj;
}
- ICElement ce = (ICElement)obj;
+ ICElement ce = (ICElement) obj;
IProject project;
project = (IProject)ce.getCProject().getResource();
IPath programFile = project.getFile(programName).getLocation();
@@ -119,11 +117,10 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
if (ce != null && ce.exists()) {
return ce;
}
- return (ICElement)obj;
+ return (ICElement) obj;
}
}
- if (page != null)
- {
+ if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
IEditorInput input = part.getEditorInput();
@@ -160,7 +157,6 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
-
}
protected String getPlatform(ILaunchConfiguration config) {
@@ -210,5 +206,4 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
dialog.open();
return dialog.getVariableExpression();
}
-
}
From 3e38bde42ce3d1b8c019fff9f8d25b69f8730b0a Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 17:18:45 -0700
Subject: [PATCH 12/22] Fixed an API tooling error.
---
launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF | 2 +-
.../src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF
index f8298e26ce6..d3de935303c 100644
--- a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF
+++ b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true
-Bundle-Version: 7.0.0.qualifier
+Bundle-Version: 7.1.0.qualifier
Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
index 5bce11d045f..c9c6bfec18b 100644
--- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
+++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CLaunchConfigurationTab.java
@@ -171,7 +171,7 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
/**
* Creates a button that allows user to insert build variables.
*
- * @since 7.0
+ * @since 7.1
*/
protected Button createVariablesButton(Composite parent, String label, final Text textField) {
Button variablesButton = createPushButton(parent, label, null);
@@ -192,7 +192,6 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
private void handleVariablesButtonSelected(Text textField) {
String variable = getVariable();
if (variable != null) {
- // We should use insert() but not append() to be consistent with the Platform behavior (e.g. Common tab)
textField.insert(variable);
}
}
From 1d231890fbf07054888ad6903005439501c427b0 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 17:20:42 -0700
Subject: [PATCH 13/22] Bug 255093 - In C++ refactoring, selection should be
updated like Java refactorings do
---
.../changegenerator/ChangeGenerator.java | 220 +++++++++++++-----
.../rewrite/changegenerator/TextEditUtil.java | 219 +++++++++++++++++
2 files changed, 384 insertions(+), 55 deletions(-)
create mode 100644 core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/TextEditUtil.java
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
index 8bf7c9c7b2a..63621e08d97 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
@@ -72,6 +72,8 @@ import org.eclipse.jface.text.TextUtilities;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
@@ -312,6 +314,37 @@ public class ChangeGenerator extends ASTVisitor {
return super.leave(statement);
}
+ private void addChildEdit(TextEdit edit) {
+ rootEdit.addChild(edit);
+ processedOffset = edit.getExclusiveEnd();
+ }
+
+ private TextEdit clippedEdit(TextEdit edit, IRegion region) {
+ if ((edit.getOffset() < region.getOffset() && edit.getExclusiveEnd() <= region.getOffset()) ||
+ edit.getOffset() >= endOffset(region)) {
+ return null;
+ }
+ int offset = Math.max(edit.getOffset(), region.getOffset());
+ int length = Math.min(endOffset(edit), endOffset(region)) - offset;
+ if (offset == edit.getOffset() && length == edit.getLength()) {
+ // InsertEdit always satisfies the above condition.
+ return edit;
+ }
+ if (edit instanceof DeleteEdit) {
+ return new DeleteEdit(offset, length);
+ } if (edit instanceof ReplaceEdit) {
+ String replacement = ((ReplaceEdit) edit).getText();
+ int start = Math.max(offset - edit.getOffset(), 0);
+ int end = Math.min(endOffset(region) - offset, replacement.length());
+ if (end <= start) {
+ return new DeleteEdit(offset, length);
+ }
+ return new ReplaceEdit(offset, length, replacement.substring(start, end));
+ } else {
+ throw new IllegalArgumentException("Unexpected edit type: " + edit.getClass().getSimpleName()); //$NON-NLS-1$
+ }
+ }
+
/**
* Applies the C++ code formatter to the code affected by refactoring.
*
@@ -321,47 +354,40 @@ public class ChangeGenerator extends ASTVisitor {
private void formatChangedCode(String code, ITranslationUnit tu) {
IDocument document = new Document(code);
try {
- // Apply refactoring changes to a temporary document.
TextEdit edit = rootEdit.copy();
+ // Apply refactoring changes to a temporary document.
edit.apply(document, TextEdit.UPDATE_REGIONS);
// Expand regions affected by the changes to cover complete lines. We calculate two
// sets of regions, reflecting the state of the document before and after
// the refactoring changes.
- TextEdit[] edits = edit.getChildren();
- TextEdit[] originalEdits = rootEdit.getChildren();
- IRegion[] regionsAfter = new IRegion[edits.length];
- IRegion[] regionsBefore = new IRegion[edits.length];
+ TextEdit[] appliedEdits = edit.getChildren();
+ TextEdit[] edits = rootEdit.removeChildren();
+ IRegion[] regions = new IRegion[appliedEdits.length];
int numRegions = 0;
int prevEnd = -1;
- for (int i = 0; i < edits.length; i++) {
- edit = edits[i];
+ for (int i = 0; i < appliedEdits.length; i++) {
+ edit = appliedEdits[i];
int offset = edit.getOffset();
int end = offset + edit.getLength();
int newOffset = document.getLineInformationOfOffset(offset).getOffset();
- edit = originalEdits[i];
+ edit = edits[i];
int originalEnd = edit.getExclusiveEnd();
// Expand to the end of the line unless the end of the edit region is at
// the beginning of line both, before and after the change.
int newEnd = (originalEnd == 0 || code.charAt(originalEnd - 1) == '\n') && end == newOffset ?
end : endOffset(document.getLineInformationOfOffset(end));
- int offsetBefore = edit.getOffset();
- int newOffsetBefore = newOffset + offsetBefore - offset;
- int newEndBefore = newEnd + offsetBefore + edit.getLength() - end;
if (newOffset <= prevEnd) {
numRegions--;
- newOffset = regionsAfter[numRegions].getOffset();
- newOffsetBefore = regionsBefore[numRegions].getOffset();
+ newOffset = regions[numRegions].getOffset();
}
prevEnd = newEnd;
- regionsAfter[numRegions] = new Region(newOffset, newEnd - newOffset);
- regionsBefore[numRegions] = new Region(newOffsetBefore, newEndBefore - newOffsetBefore);
+ regions[numRegions] = new Region(newOffset, newEnd - newOffset);
numRegions++;
}
- if (numRegions < regionsAfter.length) {
- regionsAfter = Arrays.copyOf(regionsAfter, numRegions);
- regionsBefore = Arrays.copyOf(regionsBefore, numRegions);
+ if (numRegions < regions.length) {
+ regions = Arrays.copyOf(regions, numRegions);
}
// Calculate formatting changes for the regions after the refactoring changes.
@@ -374,23 +400,72 @@ public class ChangeGenerator extends ASTVisitor {
CodeFormatter formatter = ToolFactory.createCodeFormatter(options);
code = document.get();
TextEdit[] formatEdits = formatter.format(CodeFormatter.K_TRANSLATION_UNIT, code,
- regionsAfter, TextUtilities.getDefaultLineDelimiter(document));
+ regions, TextUtilities.getDefaultLineDelimiter(document));
- // For each of the regions we apply formatting changes and create a ReplaceEdit using
- // the region before the refactoring changes and the text after the formatting changes.
- MultiTextEdit resultEdit = new MultiTextEdit();
- for (int i = 0; i < regionsAfter.length; i++) {
- IRegion region = regionsAfter[i];
- int offset = region.getOffset();
- edit = formatEdits[i];
- edit.moveTree(-offset);
- document = new Document(code.substring(offset, offset + region.getLength()));
- edit.apply(document, TextEdit.NONE);
- region = regionsBefore[i];
- edit = new ReplaceEdit(region.getOffset(), region.getLength(), document.get());
- resultEdit.addChild(edit);
+ TextEdit combinedFormatEdit = new MultiTextEdit();
+ for (TextEdit formatEdit : formatEdits) {
+ combinedFormatEdit = TextEditUtil.merge(combinedFormatEdit, formatEdit);
}
- rootEdit = resultEdit;
+ formatEdits = TextEditUtil.flatten(combinedFormatEdit).removeChildren();
+
+ MultiTextEdit result = new MultiTextEdit();
+ int delta = 0;
+ TextEdit edit1 = null;
+ TextEdit edit2 = null;
+ int i = 0;
+ int j = 0;
+ while (true) {
+ if (edit1 == null && i < edits.length)
+ edit1 = edits[i++];
+ if (edit2 == null && j < formatEdits.length)
+ edit2 = formatEdits[j++];
+ if (edit1 == null) {
+ if (edit2 == null)
+ break;
+ edit2.moveTree(-delta);
+ result.addChild(edit2);
+ edit2 = null;
+ } else {
+ int d = TextEditUtil.delta(edit1);
+ if (edit2 == null) {
+ delta += d;
+ result.addChild(edit1);
+ edit1 = null;
+ } else {
+ if (edit2.getExclusiveEnd() - delta <= edit1.getOffset()) {
+ edit2.moveTree(-delta);
+ result.addChild(edit2);
+ edit2 = null;
+ } else {
+ TextEdit piece = clippedEdit(edit2, new Region(-1, edit1.getOffset() + delta));
+ if (piece != null) {
+ piece.moveTree(-delta);
+ result.addChild(piece);
+ }
+ Region region = new Region(edit1.getOffset() + delta, edit1.getLength() + d);
+ int end = endOffset(region);
+ MultiTextEdit format = new MultiTextEdit();
+ while ((piece = clippedEdit(edit2, region)) != null) {
+ format.addChild(piece);
+ if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
+ break;
+ }
+ edit2 = formatEdits[j++];
+ }
+ if (format.hasChildren()) {
+ format.moveTree(-delta);
+ edit1 = applyEdit(format, edit1);
+ }
+ delta += d;
+ result.addChild(edit1);
+ edit1 = null;
+
+ edit2 = clippedEdit(edit2, new Region(end, Integer.MAX_VALUE - end));
+ }
+ }
+ }
+ }
+ rootEdit = result;
} catch (MalformedTreeException e) {
CCorePlugin.log(e);
} catch (BadLocationException e) {
@@ -398,10 +473,39 @@ public class ChangeGenerator extends ASTVisitor {
}
}
+ /**
+ * Applies source edit to the target one and returns the combined edit.
+ */
+ private TextEdit applyEdit(TextEdit source, TextEdit target)
+ throws MalformedTreeException, BadLocationException {
+ source.moveTree(-target.getOffset());
+ String text;
+ if (target instanceof InsertEdit) {
+ text = ((InsertEdit) target).getText();
+ } else if (target instanceof ReplaceEdit) {
+ text = ((ReplaceEdit) target).getText();
+ } else {
+ text = ""; //$NON-NLS-1$
+ }
+
+ IDocument document = new Document(text);
+ source.apply(document, TextEdit.NONE);
+ text = document.get();
+ if (target.getLength() == 0) {
+ return new InsertEdit(target.getOffset(), text);
+ } else {
+ return new ReplaceEdit(target.getOffset(), target.getLength(), text);
+ }
+ }
+
private int endOffset(IRegion region) {
return region.getOffset() + region.getLength();
}
+ private int endOffset(TextEdit edit) {
+ return edit.getOffset() + edit.getLength();
+ }
+
private int endOffset(IASTFileLocation nodeLocation) {
return nodeLocation.getNodeOffset() + nodeLocation.getNodeLength();
}
@@ -451,21 +555,23 @@ public class ChangeGenerator extends ASTVisitor {
insertPos = skipPrecedingBlankLines(tuCode, insertPos);
length -= insertPos;
}
- String code = writer.toString();
- ReplaceEdit edit = new ReplaceEdit(insertPos, length, code);
addToRootEdit(anchorNode);
- rootEdit.addChild(edit);
- processedOffset = edit.getOffset();
+ String code = writer.toString();
+ if (!code.isEmpty())
+ addChildEdit(new InsertEdit(insertPos, code));
+ if (length != 0)
+ addChildEdit(new DeleteEdit(insertPos, length));
}
private void handleReplace(IASTNode node) {
List modifications = getModifications(node, ModificationKind.REPLACE);
String source = node.getTranslationUnit().getRawSignature();
- TextEdit edit;
ChangeGeneratorWriterVisitor writer =
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
IASTFileLocation fileLocation = node.getFileLocation();
+ addToRootEdit(node);
if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
+ // There is no replacement. We are deleting a piece of existing code.
int offset = getOffsetIncludingComments(node);
int endOffset = getEndOffsetIncludingComments(node);
offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
@@ -492,25 +598,27 @@ public class ChangeGenerator extends ASTVisitor {
writer.newLine();
}
String code = writer.toString();
- edit = new ReplaceEdit(offset, endOffset - offset, code);
+ if (endOffset > offset)
+ addChildEdit(new DeleteEdit(offset, endOffset - offset));
+ if (!code.isEmpty())
+ addChildEdit(new InsertEdit(endOffset, code));
} else {
node.accept(writer);
String code = writer.toString();
int offset = fileLocation.getNodeOffset();
int endOffset = offset + fileLocation.getNodeLength();
- if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
- // Include trailing comments in the area to be replaced.
- endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
- }
String lineSeparator = writer.getScribe().getLineSeparator();
if (code.endsWith(lineSeparator)) {
code = code.substring(0, code.length() - lineSeparator.length());
}
- edit = new ReplaceEdit(offset, endOffset - offset, code);
+ addChildEdit(new ReplaceEdit(offset, endOffset - offset, code));
+ if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
+ // Include trailing comments in the area to be replaced.
+ int commentEnd = getEndOffsetIncludingTrailingComments(node);
+ if (commentEnd > endOffset)
+ addChildEdit(new DeleteEdit(endOffset, commentEnd - endOffset));
+ }
}
- addToRootEdit(node);
- rootEdit.addChild(edit);
- processedOffset = edit.getExclusiveEnd();
}
private void handleAppends(IASTNode node) {
@@ -537,13 +645,12 @@ public class ChangeGenerator extends ASTVisitor {
if (node instanceof ICPPASTNamespaceDefinition) {
writer.newLine();
}
- String code = writer.toString();
addToRootEdit(node);
- ReplaceEdit edit = new ReplaceEdit(anchor.getOffset(), anchor.getLength(),
- code + anchor.getText());
- rootEdit.addChild(edit);
- IASTFileLocation fileLocation = node.getFileLocation();
- processedOffset = endOffset(fileLocation);
+ String code = writer.toString();
+ if (!code.isEmpty())
+ addChildEdit(new InsertEdit(anchor.getOffset(), code));
+ addChildEdit(new ReplaceEdit(anchor.getOffset(), anchor.getLength(), anchor.getText()));
+ processedOffset = endOffset(node);
}
private void handleAppends(IASTTranslationUnit node) {
@@ -565,6 +672,7 @@ public class ChangeGenerator extends ASTVisitor {
String source = node.getRawSignature();
int endOffset = skipTrailingBlankLines(source, offset);
+ addToRootEdit(node);
ChangeGeneratorWriterVisitor writer =
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
IASTNode newNode = null;
@@ -593,8 +701,10 @@ public class ChangeGenerator extends ASTVisitor {
}
String code = writer.toString();
- addToRootEdit(node);
- rootEdit.addChild(new ReplaceEdit(offset, endOffset - offset, code));
+ if (!code.isEmpty())
+ addChildEdit(new InsertEdit(offset, code));
+ if (endOffset > offset)
+ addChildEdit(new DeleteEdit(offset, endOffset - offset));
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/TextEditUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/TextEditUtil.java
new file mode 100644
index 00000000000..3b5b2b6f5b1
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/TextEditUtil.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Sergey Prigogin (Google)
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
+
+import org.eclipse.text.edits.CopyTargetEdit;
+import org.eclipse.text.edits.DeleteEdit;
+import org.eclipse.text.edits.InsertEdit;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.MoveSourceEdit;
+import org.eclipse.text.edits.MoveTargetEdit;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+
+public class TextEditUtil {
+ // Do not instantiate. All methods are static.
+ private TextEditUtil() {
+ }
+
+ /**
+ * Degenerates the given edit tree into a list.
+ * All nodes of the result are leafs.
+ * The given edit is modified and can no longer be used.
+ *
+ * @param edit the edit tree to flatten
+ * @return a MultiTextEdit containing the list of edits
+ */
+ public static MultiTextEdit flatten(TextEdit edit) {
+ MultiTextEdit result= new MultiTextEdit();
+ flatten(edit, result);
+ return result;
+ }
+
+ private static void flatten(TextEdit edit, MultiTextEdit result) {
+ if (edit.hasChildren()) {
+ TextEdit[] children= edit.getChildren();
+ for (int i= 0; i < children.length; i++) {
+ TextEdit child= children[i];
+ child.getParent().removeChild(0);
+ flatten(child, result);
+ }
+ } else if (!(edit instanceof MultiTextEdit)) {
+ result.addChild(edit);
+ }
+ }
+
+ /**
+ * Create an edit which contains edit1
and edit2
+ * The given edits are modified and they can no longer be used.
+ *
+ * @param edit1 the edit to merge with edit2
+ * @param edit2 the edit to merge with edit1
+ * @return the merged tree
+ * @throws MalformedTreeException if the two edits ovelap
+ */
+ public static TextEdit merge(TextEdit edit1, TextEdit edit2) {
+ if (edit1 instanceof MultiTextEdit && !edit1.hasChildren()) {
+ return edit2;
+ }
+
+ if (edit2 instanceof MultiTextEdit && !edit2.hasChildren()) {
+ return edit1;
+ }
+
+ MultiTextEdit result= new MultiTextEdit();
+ merge(edit1, edit2, result);
+ return result;
+ }
+
+ private static void merge(TextEdit edit1, TextEdit edit2, MultiTextEdit result) {
+ if (edit1 instanceof MultiTextEdit && edit2 instanceof MultiTextEdit) {
+ MultiTextEdit multiTextEdit1= (MultiTextEdit) edit1;
+ if (!multiTextEdit1.hasChildren()) {
+ result.addChild(edit2);
+ return;
+ }
+
+ MultiTextEdit multiTextEdit2= (MultiTextEdit) edit2;
+ if (!multiTextEdit2.hasChildren()) {
+ result.addChild(edit1);
+ return;
+ }
+
+ TextEdit[] children1= multiTextEdit1.getChildren();
+ TextEdit[] children2= multiTextEdit2.getChildren();
+
+ int i1= 0;
+ int i2= 0;
+ while (i1 < children1.length && i2 < children2.length) {
+ while (i1 < children1.length && children1[i1].getExclusiveEnd() < children2[i2].getOffset()) {
+ edit1.removeChild(0);
+ result.addChild(children1[i1]);
+ i1++;
+ }
+ if (i1 >= children1.length)
+ break;
+
+ while (i2 < children2.length && children2[i2].getExclusiveEnd() < children1[i1].getOffset()) {
+ edit2.removeChild(0);
+ result.addChild(children2[i2]);
+ i2++;
+ }
+ if (i2 >= children2.length)
+ break;
+
+ if (children1[i1].getExclusiveEnd() < children2[i2].getOffset())
+ continue;
+
+ edit1.removeChild(0);
+ edit2.removeChild(0);
+ merge(children1[i1], children2[i2], result);
+
+ i1++;
+ i2++;
+ }
+
+ while (i1 < children1.length) {
+ edit1.removeChild(0);
+ result.addChild(children1[i1]);
+ i1++;
+ }
+
+ while (i2 < children2.length) {
+ edit2.removeChild(0);
+ result.addChild(children2[i2]);
+ i2++;
+ }
+ } else if (edit1 instanceof MultiTextEdit) {
+ TextEdit[] children= edit1.getChildren();
+
+ int i= 0;
+ while (children[i].getExclusiveEnd() < edit2.getOffset()) {
+ edit1.removeChild(0);
+ result.addChild(children[i]);
+ i++;
+ if (i >= children.length) {
+ result.addChild(edit2);
+ return;
+ }
+ }
+ edit1.removeChild(0);
+ merge(children[i], edit2, result);
+ i++;
+ while (i < children.length) {
+ edit1.removeChild(0);
+ result.addChild(children[i]);
+ i++;
+ }
+ } else if (edit2 instanceof MultiTextEdit) {
+ TextEdit[] children= edit2.getChildren();
+
+ int i= 0;
+ while (children[i].getExclusiveEnd() < edit1.getOffset()) {
+ edit2.removeChild(0);
+ result.addChild(children[i]);
+ i++;
+ if (i >= children.length) {
+ result.addChild(edit1);
+ return;
+ }
+ }
+ edit2.removeChild(0);
+ merge(edit1, children[i], result);
+ i++;
+ while (i < children.length) {
+ edit2.removeChild(0);
+ result.addChild(children[i]);
+ i++;
+ }
+ } else {
+ if (edit1.getExclusiveEnd() < edit2.getOffset()) {
+ result.addChild(edit1);
+ result.addChild(edit2);
+ } else {
+ result.addChild(edit2);
+ result.addChild(edit1);
+ }
+ }
+ }
+
+ /**
+ * Returns the difference in the document length caused by the edit. {@code InsertEdit}s have
+ * positive delta, {@code DeleteEdit}s have negative one.
+ * @param edit the edit to determine delta for.
+ * @return the delta
+ */
+ public static int delta(TextEdit edit) {
+ int delta = 0;
+ for (TextEdit child : edit.getChildren()) {
+ delta += delta(child);
+ }
+ delta += ownDelta(edit);
+ return delta;
+ }
+
+ private static int ownDelta(TextEdit edit) {
+ if (edit instanceof DeleteEdit || edit instanceof MoveSourceEdit) {
+ return -edit.getLength();
+ } else if (edit instanceof InsertEdit) {
+ return ((InsertEdit) edit).getText().length();
+ } else if (edit instanceof ReplaceEdit) {
+ return ((ReplaceEdit) edit).getText().length() - edit.getLength();
+ } else if (edit instanceof CopyTargetEdit) {
+ return ((CopyTargetEdit) edit).getSourceEdit().getLength();
+ } else if (edit instanceof MoveTargetEdit) {
+ return ((MoveTargetEdit) edit).getSourceEdit().getLength();
+ }
+ return 0;
+ }
+}
From 3ea797a02e5f30752281f278da5c20808854ca1c Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 17:28:06 -0700
Subject: [PATCH 14/22] Cosmetics.
---
.../ui/launching/CLaunchConfigurationTab.java | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
index 30da39b4357..6b183448612 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
@@ -53,8 +53,8 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
IWorkbenchPage page = GdbUIPlugin.getActivePage();
Object obj = null;
try {
- projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
- programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String)null);
+ projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
+ programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, (String) null);
if (programName != null) {
programName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName);
}
@@ -115,15 +115,13 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
return (ICElement)obj;
}
}
- if (page != null)
- {
+ if (page != null) {
IEditorPart part = page.getActiveEditor();
if (part != null) {
IEditorInput input = part.getEditorInput();
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput)input).getFile();
- if (file != null)
- {
+ if (file != null) {
ICElement ce = CoreModel.getDefault().create(file);
if (ce == null) {
IProject pro = file.getProject();
@@ -153,7 +151,6 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
-
}
protected String getPlatform(ILaunchConfiguration config) {
From 1a4b2a06b5e6b02fcc07c3f26f01edb6cbb8b68f Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 17:33:36 -0700
Subject: [PATCH 15/22] Cosmetics.
---
.../gdb/internal/ui/launching/CLaunchConfigurationTab.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
index 6b183448612..5f310e7e58d 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CLaunchConfigurationTab.java
@@ -38,7 +38,6 @@ import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
public abstract class CLaunchConfigurationTab extends AbstractLaunchConfigurationTab {
-
/**
* Returns the current C element context from which to initialize default
* settings, or null
if none. Note, if possible we will
@@ -60,6 +59,7 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
}
} catch (CoreException e) {
}
+
if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
@@ -144,11 +144,10 @@ public abstract class CLaunchConfigurationTab extends AbstractLaunchConfiguratio
if (cProject != null && cProject.exists()) {
name = cProject.getElementName();
config.setMappedResources(new IResource[] {cProject.getProject()});
-
+
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(cProject.getProject());
String buildConfigID = projDes.getActiveConfiguration().getId();
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, buildConfigID);
-
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
}
From b4481a57738de0d1829402c02dbaf7eec6167d6a Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Thu, 5 Apr 2012 10:08:30 -0700
Subject: [PATCH 16/22] Incremented version in pom to match the one in
MANIFEST.MF
---
launch/org.eclipse.cdt.launch/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/launch/org.eclipse.cdt.launch/pom.xml b/launch/org.eclipse.cdt.launch/pom.xml
index 513efe9ff97..4869e59dc88 100644
--- a/launch/org.eclipse.cdt.launch/pom.xml
+++ b/launch/org.eclipse.cdt.launch/pom.xml
@@ -11,7 +11,7 @@
../../pom.xml
- 7.0.0-SNAPSHOT
+ 7.1.0-SNAPSHOT
org.eclipse.cdt.launch
eclipse-plugin
From 9c2b66cf03f5423013365c0db8890a801b45a876 Mon Sep 17 00:00:00 2001
From: Markus Schorn
Date: Wed, 4 Apr 2012 17:18:30 +0200
Subject: [PATCH 17/22] Bug 375601: Remove workaround for bug 359485.
---
.../eclipse/cdt/internal/core/pdom/PDOMManager.java | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
index d79b5dd70f6..09a72dba2c4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java
@@ -85,7 +85,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -495,8 +494,6 @@ public class PDOMManager implements IWritableIndexManager, IListener {
String newid= IndexerPreferences.get(prj, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
Properties props= IndexerPreferences.getProperties(prj);
- // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
- synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(prj.getName())) {
return;
@@ -520,7 +517,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
enqueue(new PDOMRebuildTask(indexer));
}
- }}
+ }
if (oldIndexer != null) {
stopIndexer(oldIndexer);
@@ -553,8 +550,6 @@ public class PDOMManager implements IWritableIndexManager, IListener {
assert !Thread.holdsLock(fProjectToPDOM);
try {
- // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
- synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(name)) {
if (fTraceIndexerSetup)
@@ -604,14 +599,12 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
return;
}
- }}
+ }
// rebuild is required, try import first.
TeamPDOMImportOperation operation= new TeamPDOMImportOperation(project);
operation.run(pm);
- // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=359485
- synchronized (new ProjectScope(prj).getNode(CCorePlugin.PLUGIN_ID)) {
synchronized (fUpdatePolicies) {
if (fClosingProjects.contains(name)) {
if (fTraceIndexerSetup)
@@ -640,7 +633,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
}
enqueue(task);
}
- }}
+ }
} catch (CoreException e) {
// Ignore if project is no longer open
if (prj.isOpen()) {
From 2ab852ece0dc8a845643ae3e2330e70de037b359 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Fri, 6 Apr 2012 11:01:32 -0700
Subject: [PATCH 18/22] Minor code cleanup.
---
.../changegenerator/ChangeGenerator.java | 63 +++++++++----------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
index 63621e08d97..61c61b34c29 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
@@ -425,43 +425,42 @@ public class ChangeGenerator extends ASTVisitor {
edit2.moveTree(-delta);
result.addChild(edit2);
edit2 = null;
+ } else if (edit2 == null) {
+ delta += TextEditUtil.delta(edit1);
+ result.addChild(edit1);
+ edit1 = null;
} else {
- int d = TextEditUtil.delta(edit1);
- if (edit2 == null) {
+ if (edit2.getExclusiveEnd() - delta <= edit1.getOffset()) {
+ edit2.moveTree(-delta);
+ result.addChild(edit2);
+ edit2 = null;
+ } else {
+ TextEdit piece = clippedEdit(edit2, new Region(-1, edit1.getOffset() + delta));
+ if (piece != null) {
+ piece.moveTree(-delta);
+ result.addChild(piece);
+ }
+ int d = TextEditUtil.delta(edit1);
+ Region region = new Region(edit1.getOffset() + delta, edit1.getLength() + d);
+ int end = endOffset(region);
+ MultiTextEdit format = new MultiTextEdit();
+ while ((piece = clippedEdit(edit2, region)) != null) {
+ format.addChild(piece);
+ // The warning "The variable edit2 may be null at this location" is bogus.
+ if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
+ break;
+ }
+ edit2 = formatEdits[j++];
+ }
+ if (format.hasChildren()) {
+ format.moveTree(-delta);
+ edit1 = applyEdit(format, edit1);
+ }
delta += d;
result.addChild(edit1);
edit1 = null;
- } else {
- if (edit2.getExclusiveEnd() - delta <= edit1.getOffset()) {
- edit2.moveTree(-delta);
- result.addChild(edit2);
- edit2 = null;
- } else {
- TextEdit piece = clippedEdit(edit2, new Region(-1, edit1.getOffset() + delta));
- if (piece != null) {
- piece.moveTree(-delta);
- result.addChild(piece);
- }
- Region region = new Region(edit1.getOffset() + delta, edit1.getLength() + d);
- int end = endOffset(region);
- MultiTextEdit format = new MultiTextEdit();
- while ((piece = clippedEdit(edit2, region)) != null) {
- format.addChild(piece);
- if (edit2.getExclusiveEnd() >= end || j >= formatEdits.length) {
- break;
- }
- edit2 = formatEdits[j++];
- }
- if (format.hasChildren()) {
- format.moveTree(-delta);
- edit1 = applyEdit(format, edit1);
- }
- delta += d;
- result.addChild(edit1);
- edit1 = null;
- edit2 = clippedEdit(edit2, new Region(end, Integer.MAX_VALUE - end));
- }
+ edit2 = clippedEdit(edit2, new Region(end, Integer.MAX_VALUE - end));
}
}
}
From 07561ca8838caa59a6fc4bca25e37f8e1094f346 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Sun, 8 Apr 2012 22:25:36 -0700
Subject: [PATCH 19/22] Cosmetics.
---
.../parser/AbstractGNUSourceCodeParser.java | 17 ++++----
.../core/dom/parser/c/GNUCSourceParser.java | 39 ++++++++-----------
.../dom/parser/cpp/GNUCPPSourceParser.java | 2 +-
3 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 44318861942..8b4d2131073 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -563,10 +563,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
/**
- * Parse an identifier.
+ * Parses an identifier.
*
- * @throws BacktrackException
- * request a backtrack
+ * @throws BacktrackException request a backtrack
*/
protected abstract IASTName identifier() throws EndOfFileException, BacktrackException;
@@ -1242,7 +1241,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
IASTCastExpression result = buildCastExpression(IASTCastExpression.op_cast,
typeId, rhs, startingOffset, calculateEndOffset(rhs));
- if (!unaryFailed && couldBeFunctionCall && rhs instanceof IASTCastExpression == false) {
+ if (!unaryFailed && couldBeFunctionCall && !(rhs instanceof IASTCastExpression)) {
IToken markEnd= mark();
backup(mark);
try {
@@ -2164,27 +2163,25 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return cs;
}
-
protected int figureEndOffset(IASTDeclSpecifier declSpec, IASTDeclarator[] declarators) {
if (declarators.length == 0)
return calculateEndOffset(declSpec);
return calculateEndOffset(declarators[declarators.length - 1]);
}
-
protected int figureEndOffset(IASTDeclSpecifier declSpecifier, IASTDeclarator declarator) {
if (declarator == null || ((ASTNode) declarator).getLength() == 0)
return calculateEndOffset(declSpecifier);
return calculateEndOffset(declarator);
}
-
protected void throwBacktrack(IToken token) throws BacktrackException {
throwBacktrack(token.getOffset(), token.getLength());
}
protected IASTExpression parseTypeidInParenthesisOrUnaryExpression(boolean exprIsLimitedToParenthesis,
- int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat) throws BacktrackException, EndOfFileException {
+ int offset, int typeExprKind, int unaryExprKind, CastExprCtx ctx, ITemplateIdStrategy strat)
+ throws BacktrackException, EndOfFileException {
IASTTypeId typeid;
IASTExpression expr= null;
IToken typeidLA= null;
@@ -2315,7 +2312,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
/**
- * Accept a sequence of __attribute__ or __declspec
+ * Accepts a sequence of __attribute__ or __declspec.
*
* @param allowAttrib if true accept any number of __attribute__
* @param allowDeclspec if true accept any number of __declspec
@@ -2416,7 +2413,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
* @throws EndOfFileException
*/
protected void handleOtherDeclSpecModifier() throws BacktrackException, EndOfFileException {
- // default action: consume keyword plus optional parenthesised "something"
+ // default action: consume keyword plus optional parenthesized "something"
consume();
IToken token = LA(1);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index 2819243d5d6..d104fb63984 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * John Camelon (IBM Rational Software) - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Ed Swartz (Nokia)
- * Mike Kucera (IBM) - bug #206952
+ * John Camelon (IBM Rational Software) - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
+ * Mike Kucera (IBM) - bug #206952
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -415,7 +415,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
final IASTDeclarator outerDtor= declarators[0];
final IASTDeclarator fdtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
- if (fdtor instanceof IASTFunctionDeclarator == false)
+ if (!(fdtor instanceof IASTFunctionDeclarator))
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
IASTFunctionDefinition funcDefinition = nodeFactory.newFunctionDefinition(declSpec, (IASTFunctionDeclarator) fdtor, null);
@@ -465,8 +465,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
private IASTExpression expression(final ExprKind kind) throws EndOfFileException, BacktrackException {
- final boolean allowComma= kind==ExprKind.eExpression;
- boolean allowAssignment= kind !=ExprKind.eConstant;
+ final boolean allowComma= kind == ExprKind.eExpression;
+ boolean allowAssignment= kind != ExprKind.eConstant;
int lt1;
int conditionCount= 0;
BinaryOperator lastOperator= null;
@@ -479,7 +479,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
// ? :
// Precedence: 25 is lower than precedence of logical or; 0 is lower than precedence of expression
lastOperator= new BinaryOperator(lastOperator, lastExpression, lt1, 25, 0);
- if (LT(2) == IToken.tCOLON) {
+ if (LT(2) == IToken.tCOLON) {
// Gnu extension: The expression after '?' can be omitted.
consume(); // Consume operator
lastExpression= null; // Next cast expression is just null
@@ -1491,7 +1491,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
int startOffset= last.getOffset();
// check for K&R C parameters (0 means it's not K&R C)
- if (fPreventKnrCheck==0 && supportKnRC) {
+ if (fPreventKnrCheck == 0 && supportKnRC) {
fPreventKnrCheck++;
try {
final int numKnRCParms = countKnRCParms();
@@ -1597,7 +1597,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
private IASTSimpleDeclaration checkKnrParameterDeclaration(IASTDeclaration decl, final IASTName[] parmNames) {
- if (decl instanceof IASTSimpleDeclaration == false)
+ if (!(decl instanceof IASTSimpleDeclaration))
return null;
IASTSimpleDeclaration declaration= ((IASTSimpleDeclaration) decl);
@@ -1839,7 +1839,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
return parseDeclarationOrExpressionStatement();
}
-
}
@Override
@@ -1863,7 +1862,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
previousWasIdentifier = false;
} else if (LT(1) == IToken.tIDENTIFIER) {
consume();
- if (previousWasIdentifier == true) {
+ if (previousWasIdentifier) {
backup(mark);
return 0; // i.e. KnR C won't have int f(typedef x)
// char
@@ -2011,9 +2010,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
if (if_statement != null) {
if_statement.setElseClause(new_if_statement);
- ((ASTNode) if_statement)
- .setLength(calculateEndOffset(new_if_statement)
- - ((ASTNode) if_statement).getOffset());
+ ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement)
+ - ((ASTNode) if_statement).getOffset());
}
if (result == null && if_statement != null)
result = if_statement;
@@ -2027,9 +2025,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
new_if_statement.setElseClause(elseStatement);
if (if_statement != null) {
if_statement.setElseClause(new_if_statement);
- ((ASTNode) if_statement)
- .setLength(calculateEndOffset(new_if_statement)
- - ((ASTNode) if_statement).getOffset());
+ ((ASTNode) if_statement).setLength(calculateEndOffset(new_if_statement)
+ - ((ASTNode) if_statement).getOffset());
} else {
if (result == null)
result = new_if_statement;
@@ -2037,12 +2034,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
} else {
if( thenClause != null )
- ((ASTNode) new_if_statement)
- .setLength(calculateEndOffset(thenClause) - start);
+ ((ASTNode) new_if_statement).setLength(calculateEndOffset(thenClause) - start);
if (if_statement != null) {
if_statement.setElseClause(new_if_statement);
- ((ASTNode) new_if_statement)
- .setLength(calculateEndOffset(new_if_statement) - start);
+ ((ASTNode) new_if_statement).setLength(calculateEndOffset(new_if_statement) - start);
}
if (result == null && if_statement != null)
result = if_statement;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index f0a3aa88b97..9459ab9e636 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -2454,7 +2454,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
IASTDeclarator outerDtor) throws EndOfFileException, BacktrackException {
final IASTDeclarator dtor= ASTQueries.findTypeRelevantDeclarator(outerDtor);
- if (dtor instanceof ICPPASTFunctionDeclarator == false)
+ if (!(dtor instanceof ICPPASTFunctionDeclarator))
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
From 1d9c709b88ae983e6f9a2370c301b146289a4086 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Wed, 4 Apr 2012 20:07:54 -0700
Subject: [PATCH 20/22] Cosmetics.
---
.../org/eclipse/cdt/core/dom/ast/IASTDeclaration.java | 2 +-
.../org/eclipse/cdt/core/dom/ast/IASTDeclarator.java | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java
index 69d1f60d13f..8e3ea11db58 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclaration.java
@@ -17,7 +17,7 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTDeclaration extends IASTNode {
- public static final IASTDeclaration[] EMPTY_DECLARATION_ARRAY = new IASTDeclaration[0];
+ public static final IASTDeclaration[] EMPTY_DECLARATION_ARRAY = {};
/**
* @since 5.1
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
index f1d6994bd64..55a24fda2cd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTDeclarator.java
@@ -67,7 +67,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
public void addPointerOperator(IASTPointerOperator operator);
/**
- * If the declarator is nested in parentheses, this returns the declarator
+ * If the declarator is nested in parentheses, returns the declarator
* as found in those parentheses.
*
* @return the nested declarator or null
@@ -77,7 +77,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
public void setNestedDeclarator(IASTDeclarator nested);
/**
- * This returns the name of the declarator. If this is an abstract
+ * Returns the name of the declarator. If this is an abstract
* declarator, this will return an empty name.
*
* @return the name of the declarator
@@ -85,7 +85,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
public IASTName getName();
/**
- * Set the name of he declarator.
+ * Sets the name of he declarator.
*
* @param name
* IASTName
@@ -93,7 +93,7 @@ public interface IASTDeclarator extends IASTNode, IASTNameOwner {
public void setName(IASTName name);
/**
- * This is the optional initializer for this declarator.
+ * Returns the optional initializer for this declarator.
*
* @return the initializer expression or null
*/
From 36442384d4c85bc34b77432175c735d52fda7d05 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Sat, 7 Apr 2012 23:32:14 -0700
Subject: [PATCH 21/22] Cosmetics.
---
.../cdt/core/dom/ast/IASTExpressionList.java | 3 +-
.../dom/ast/IASTInitializerExpression.java | 3 +-
.../org/eclipse/cdt/core/dom/ast/IValue.java | 10 ++--
.../org/eclipse/cdt/core/parser/IScanner.java | 1 -
.../core/dom/parser/ASTEqualsInitializer.java | 5 +-
.../parser/AbstractGNUSourceCodeParser.java | 3 --
.../internal/core/dom/parser/NodeFactory.java | 1 -
.../dom/parser/c/CASTAmbiguousDeclarator.java | 10 ++--
.../parser/cpp/CPPASTAmbiguousDeclarator.java | 11 ++---
.../core/dom/parser/cpp/CPPASTProblem.java | 30 ++++++------
.../SemanticHighlightingReconciler.java | 49 +++++--------------
.../cdt/internal/ui/editor/SemanticToken.java | 6 +--
12 files changed, 46 insertions(+), 86 deletions(-)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java
index f61b4791069..55a874a4a7b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTExpressionList.java
@@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTExpressionList extends IASTExpression {
-
/**
* NESTED_EXPRESSION
describes the relationship between
* IASTExpressionList
and the nested
@@ -29,7 +28,7 @@ public interface IASTExpressionList extends IASTExpression {
/**
* Get nested expressions.
*
- * @return IASTExpression []
nested expressions
+ * @return IASTExpression[]
nested expressions
*/
public IASTExpression[] getExpressions();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java
index 7de70794e85..6abbcb8b1eb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTInitializerExpression.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Doug Schaefer (IBM) - Initial API and implementation
+ * Doug Schaefer (IBM) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -19,7 +19,6 @@ package org.eclipse.cdt.core.dom.ast;
*/
@Deprecated
public interface IASTInitializerExpression extends IASTEqualsInitializer {
-
/**
* INITIALIZER_EXPRESSION
represents the relationship between
* an IASTInitializerExpression
. and its
IASTExpression.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java
index 41660e88706..2f8a2f46b99 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IValue.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
+ * Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
@@ -24,8 +24,8 @@ public interface IValue {
Long numericalValue();
/**
- * Returns an internal representation of the expression that builds up the
- * value. It is suitable for instantiating dependent values but may not be
+ * Returns an internal representation of the expression that builds up
+ * the value. It is suitable for instantiating dependent values but may not be
* used for the purpose of displaying values.
*/
char[] getInternalExpression();
@@ -37,8 +37,8 @@ public interface IValue {
IBinding[] getUnknownBindings();
/**
- * Returns a signature containing both the internal representation and the
- * unknown bindings. The representation is sufficient to distinguish values
+ * Returns a signature containing both the internal representation and
+ * the unknown bindings. The representation is sufficient to distinguish values
* for the purpose of instantiation, it may not be used to display the value.
*/
char[] getSignature();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index e37c2baf261..e23d3047bda 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -30,7 +30,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IScanner {
-
/**
* Returns a map from {@link String} to {@link IMacroBinding} containing
* all the definitions that are defined at the current point in the
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java
index 55a4b27c635..8045137a4e2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTEqualsInitializer.java
@@ -20,9 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
/**
* Initializer with equals sign (copy initialization)
*/
-public abstract class ASTEqualsInitializer extends ASTNode implements IASTEqualsInitializer,
- IASTAmbiguityParent {
-
+public abstract class ASTEqualsInitializer extends ASTNode
+ implements IASTEqualsInitializer, IASTAmbiguityParent {
private IASTInitializerClause fArgument;
public ASTEqualsInitializer() {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 8b4d2131073..186a8ad1baf 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -181,7 +181,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected boolean functionCallCanBeLValue= false;
protected boolean skipTrivialExpressionsInAggregateInitializers= false;
-
/**
* Marks the beginning of the current declaration. It is important to clear the mark whenever we
@@ -2122,7 +2121,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
}
-
protected IASTStatement parseCompoundStatement() throws EndOfFileException, BacktrackException {
IASTCompoundStatement compound = compoundStatement();
return compound;
@@ -2501,7 +2499,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
}
protected boolean canBeTypeSpecifier() throws EndOfFileException {
-
final int lt1 = LT(1);
switch (lt1) {
// simple type specifiers:
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java
index 04ba0b9aa95..61a70afb099 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/NodeFactory.java
@@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.INodeFactory;
* Abstract base class for node factories.
*/
public abstract class NodeFactory implements INodeFactory {
-
@Override
public final void setOffsets(IASTNode node, int offset, int endOffset) {
((ASTNode) node).setOffsetAndLength(offset, endOffset-offset);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
index 4279aec37cf..7052c5240b2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguousDeclarator.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - Initial API and implementation
+ * Markus Schorn - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -29,13 +29,11 @@ import org.eclipse.core.runtime.Assert;
* @since 5.0.1
*/
public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator {
-
private IASTDeclarator[] dtors = new IASTDeclarator[2];
- private int dtorPos=-1;
-
+ private int dtorPos= -1;
public CASTAmbiguousDeclarator(IASTDeclarator... decls) {
- for(IASTDeclarator d : decls) {
+ for (IASTDeclarator d : decls) {
if (d != null) {
addDeclarator(d);
}
@@ -63,7 +61,7 @@ public class CASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmb
@Override
public IASTDeclarator[] getDeclarators() {
- dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos );
+ dtors = ArrayUtil.trimAt(IASTDeclarator.class, dtors, dtorPos);
return dtors;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
index d7d03003e05..4ab8074fd29 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguousDeclarator.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - Initial API and implementation
+ * Markus Schorn - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -29,15 +29,14 @@ import org.eclipse.core.runtime.Assert;
*
* Example: void f(int (D)); // is D a type?
*/
-public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode implements IASTAmbiguousDeclarator, ICPPASTDeclarator {
-
+public class CPPASTAmbiguousDeclarator extends ASTAmbiguousNode
+ implements IASTAmbiguousDeclarator, ICPPASTDeclarator {
private IASTDeclarator[] dtors = new IASTDeclarator[2];
- private int dtorPos=-1;
+ private int dtorPos= -1;
private IASTInitializer fInitializer;
-
public CPPASTAmbiguousDeclarator(IASTDeclarator... decls) {
- for(IASTDeclarator d : decls) {
+ for (IASTDeclarator d : decls) {
if (d != null) {
addDeclarator(d);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java
index 7852ed3aec5..988787d934e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
- * Markus Schorn (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -16,7 +16,7 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
/**
- * cpp-specific implementation allows actions to visit the problem.
+ * C++-specific implementation allows actions to visit the problem.
*/
public class CPPASTProblem extends ASTProblem {
@@ -41,19 +41,19 @@ public class CPPASTProblem extends ASTProblem {
}
@Override
- public boolean accept( ASTVisitor action ){
- if( action.shouldVisitProblems ){
- switch( action.visit( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
+ public boolean accept(ASTVisitor action) {
+ if (action.shouldVisitProblems) {
+ switch (action.visit(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
}
}
- if( action.shouldVisitProblems ){
- switch( action.leave( this ) ){
- case ASTVisitor.PROCESS_ABORT : return false;
- case ASTVisitor.PROCESS_SKIP : return true;
- default : break;
+ if (action.shouldVisitProblems) {
+ switch (action.leave(this)) {
+ case ASTVisitor.PROCESS_ABORT: return false;
+ case ASTVisitor.PROCESS_SKIP: return true;
+ default: break;
}
}
return true;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java
index 1e8b3eb3133..a35e261f5f3 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java
@@ -51,7 +51,6 @@ import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.Highlighte
import org.eclipse.cdt.internal.ui.editor.SemanticHighlightingManager.HighlightingStyle;
import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
-
/**
* Semantic highlighting reconciler - Background thread implementation.
* Cloned from JDT.
@@ -59,12 +58,10 @@ import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
* @since 4.0
*/
public class SemanticHighlightingReconciler implements ICReconcilingListener {
-
/**
* Collects positions from the AST.
*/
private class PositionCollector extends ASTVisitor {
-
/** The semantic token */
private SemanticToken fToken= new SemanticToken();
private int fMinLocation;
@@ -82,12 +79,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
shouldVisitImplicitNameAlternates = visitImplicitNames;
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)
- */
@Override
public int visit(IASTTranslationUnit tu) {
-
// visit macro definitions
IASTPreprocessorMacroDefinition[] macroDefs= tu.getMacroDefinitions();
for (IASTPreprocessorMacroDefinition macroDef : macroDefs) {
@@ -115,9 +108,6 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
return super.visit(tu);
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
- */
@Override
public int visit(IASTDeclaration declaration) {
if (!declaration.isPartOfTranslationUnitFile()) {
@@ -126,9 +116,6 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
return PROCESS_CONTINUE;
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#leave(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
- */
@Override
public int leave(IASTDeclaration declaration) {
// if (!shouldVisitCatchHandlers && declaration instanceof IASTFunctionDefinition) {
@@ -154,9 +141,6 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
return PROCESS_CONTINUE;
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
- */
@Override
public int visit(IASTDeclarator declarator) {
// if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
@@ -165,9 +149,6 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
return PROCESS_CONTINUE;
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTStatement)
- */
@Override
public int visit(IASTStatement statement) {
// if (!shouldVisitCatchHandlers && statement instanceof ICPPASTCatchHandler) {
@@ -176,9 +157,6 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
return PROCESS_CONTINUE;
}
- /*
- * @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTName)
- */
@Override
public int visit(IASTName name) {
if (visitNode(name)) {
@@ -226,7 +204,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
}
} else {
- // fallback in case no image location available
+ // Fallback in case no image location available
IASTNodeLocation[] nodeLocations= name.getNodeLocations();
if (nodeLocations.length == 1 && !(nodeLocations[0] instanceof IASTMacroExpansionLocation)) {
addNodeLocation(nodeLocations[0], highlightingStyle);
@@ -319,20 +297,14 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
/** Highlightings - cache for background thread, only valid during {@link #reconciled(IASTTranslationUnit, boolean, IProgressMonitor)} */
private HighlightingStyle[] fJobHighlightings;
- /*
- * @see org.eclipse.cdt.internal.ui.text.java.ICReconcilingListener#aboutToBeReconciled()
- */
@Override
public void aboutToBeReconciled() {
// Do nothing
}
- /*
- * @see org.eclipse.cdt.internal.ui.text.ICReconcilingListener#reconciled(IASTTranslationUnit, boolean, IProgressMonitor)
- */
@Override
public void reconciled(IASTTranslationUnit ast, boolean force, IProgressMonitor progressMonitor) {
- // ensure at most one thread can be reconciling at any time
+ // Ensure at most one thread can be reconciling at any time
synchronized (fReconcileLock) {
if (fIsReconciling)
return;
@@ -397,8 +369,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
/**
* Reconcile positions based on the AST.
*
- * @param ast the AST
- * @param visitor the AST visitor
+ * @param ast the AST
+ * @param visitor the AST visitor
*/
private void reconcilePositions(IASTTranslationUnit ast, PositionCollector visitor) {
ast.accept(visitor);
@@ -410,12 +382,13 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
newPositions.add(current);
}
fRemovedPositions= newPositions;
- // positions need to be sorted by ascending offset
+ // Positions need to be sorted by ascending offset
Collections.sort(fAddedPositions, new Comparator() {
@Override
public int compare(final Position p1, final Position p2) {
return p1.getOffset() - p2.getOffset();
- }});
+ }
+ });
}
/**
@@ -450,7 +423,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
/**
- * Stop reconciling positions.
+ * Stops reconciling positions.
*/
protected void stopReconcilingPositions() {
fRemovedPositions.clear();
@@ -459,7 +432,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
/**
- * Install this reconciler on the given editor, presenter and highlightings.
+ * Installs this reconciler on the given editor, presenter and highlightings.
* @param editor the editor
* @param sourceViewer the source viewer
* @param presenter the semantic highlighting presenter
@@ -479,7 +452,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
/**
- * Uninstall this reconciler from the editor
+ * Uninstalsl this reconciler from the editor
*/
public void uninstall() {
if (fPresenter != null)
@@ -496,7 +469,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
}
/**
- * Schedule a background job for retrieving the AST and reconciling the Semantic Highlighting model.
+ * Schedules a background job for retrieving the AST and reconciling the Semantic Highlighting model.
*/
private void scheduleJob() {
final ICElement element= fEditor.getInputCElement();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticToken.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticToken.java
index 1bac7aed700..ffe4541d158 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticToken.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticToken.java
@@ -9,7 +9,6 @@
* IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.editor;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -24,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
* @since 4.0
*/
public final class SemanticToken {
-
/** AST node */
private IASTNode fNode;
@@ -35,7 +33,7 @@ public final class SemanticToken {
/** AST root */
private IASTTranslationUnit fRoot;
- private boolean fIsRootResolved= false;
+ private boolean fIsRootResolved;
/**
* @return Returns the binding, can be null
.
@@ -44,7 +42,7 @@ public final class SemanticToken {
if (!fIsBindingResolved) {
fIsBindingResolved= true;
if (fNode instanceof IASTName)
- fBinding= ((IASTName)fNode).resolveBinding();
+ fBinding= ((IASTName) fNode).resolveBinding();
}
return fBinding;
From 64f529b3ecd2759678615d162d6214e6205e22d9 Mon Sep 17 00:00:00 2001
From: Sergey Prigogin
Date: Sun, 8 Apr 2012 20:51:32 -0700
Subject: [PATCH 22/22] Replaced StringBuffer with StringBuilder.
---
.../core/parser/tests/ast2/AST2CSpecTest.java | 186 +--
.../core/parser/tests/ast2/AST2KnRTests.java | 739 +++++-----
.../cdt/core/parser/tests/ast2/GCCTests.java | 1276 ++++++++---------
3 files changed, 1099 insertions(+), 1102 deletions(-)
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
index 5351512e021..974728e23da 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java
@@ -32,7 +32,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test4s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#ifdef __STDC_IEC_559__ /* FE_UPWARD defined */\n"); //$NON-NLS-1$
buffer.append("fesetround(FE_UPWARD);\n"); //$NON-NLS-1$
buffer.append("#endif\n"); //$NON-NLS-1$
@@ -46,7 +46,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_1_3s2() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("char i;\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
@@ -61,7 +61,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char c1, c2;\n"); //$NON-NLS-1$
buffer.append("c1 = c1 + c2;\n"); //$NON-NLS-1$
@@ -79,7 +79,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("float f1, f2;\n"); //$NON-NLS-1$
buffer.append("double d;\n"); //$NON-NLS-1$
@@ -99,7 +99,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("double d1, d2;\n"); //$NON-NLS-1$
buffer.append("float f;\n"); //$NON-NLS-1$
@@ -121,7 +121,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("double x, y, z;\n"); //$NON-NLS-1$
buffer.append("x = (x * y) * z; // not equivalent tox *= y * z;\n"); //$NON-NLS-1$
@@ -145,7 +145,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int a, b;\n"); //$NON-NLS-1$
buffer.append("a = a + 32760 + b + 5;\n"); //$NON-NLS-1$
@@ -169,7 +169,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test5_1_2_3s15() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("//#include \n"); //$NON-NLS-1$
buffer.append("int f() {");
buffer.append("int sum;\n"); //$NON-NLS-1$
@@ -186,7 +186,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_2_5s28() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct tag (* a[5])(float);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
}
@@ -199,7 +199,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_2_7s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(int (*)(), double (*)[3]);\n"); //$NON-NLS-1$
buffer.append("int f(int (*)(char *), double (*)[]);\n"); //$NON-NLS-1$
buffer.append("int f(int (*)(char *), double (*)[3]);\n"); //$NON-NLS-1$
@@ -214,7 +214,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_4_4_4s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("char x='\\023';\n"); //$NON-NLS-1$
buffer.append("char y='\\0';\n"); //$NON-NLS-1$
buffer.append("char z='\\x13';\n"); //$NON-NLS-1$
@@ -234,7 +234,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_2s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f1() {}\n"); //$NON-NLS-1$
buffer.append("int f2() {}\n"); //$NON-NLS-1$
buffer.append("int f3() {}\n"); //$NON-NLS-1$
@@ -263,7 +263,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { int i; const int ci; };\n"); //$NON-NLS-1$
buffer.append("struct s s;\n"); //$NON-NLS-1$
buffer.append("const struct s cs;\n"); //$NON-NLS-1$
@@ -305,7 +305,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s8a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("union {\n"); //$NON-NLS-1$
buffer.append("struct {\n"); //$NON-NLS-1$
buffer.append("int alltypes;\n"); //$NON-NLS-1$
@@ -351,7 +351,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_3s8b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct t1 { int m; };\n"); //$NON-NLS-1$
buffer.append("struct t2 { int m; };\n"); //$NON-NLS-1$
buffer.append("int f(struct t1 * p1, struct t2 * p2)\n"); //$NON-NLS-1$
@@ -377,7 +377,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int *p = (int []){2, 4};\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 0);
}
@@ -392,7 +392,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(void)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int *p;\n"); //$NON-NLS-1$
@@ -412,7 +412,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(){\n"); //$NON-NLS-1$
buffer.append("drawline((struct point){.x=1, .y=1},\n"); //$NON-NLS-1$
buffer.append("(struct point){.x=3, .y=4});\n"); //$NON-NLS-1$
@@ -430,7 +430,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("(const float []){1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6};\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
@@ -447,7 +447,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("\"/tmp/fileXXXXXX\";\n"); //$NON-NLS-1$
buffer.append("(char []){\"/tmp/fileXXXXXX\"};\n"); //$NON-NLS-1$
@@ -464,7 +464,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("(const char []){\"abc\"} == \"abc\";\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
@@ -481,7 +481,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s15() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("struct int_list { int car; struct int_list *cdr; };\n"); //$NON-NLS-1$
buffer.append("struct int_list endless_zeros = {0, &endless_zeros};\n"); //$NON-NLS-1$
@@ -505,7 +505,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_2_5s16() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { int i; };\n"); //$NON-NLS-1$
buffer.append("int f (void)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -526,7 +526,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_3_4s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern void *alloc(size_t);\n"); //$NON-NLS-1$
buffer.append("double *dp = alloc(sizeof *dp);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
@@ -541,7 +541,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_3_4s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int array[5];\n"); //$NON-NLS-1$
buffer.append("int x = sizeof array / sizeof array[0];\n"); //$NON-NLS-1$
@@ -562,7 +562,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_6s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int n = 4, m = 3;\n"); //$NON-NLS-1$
buffer.append("int a[n][m];\n"); //$NON-NLS-1$
@@ -587,7 +587,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_15s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const void *c_vp;\n"); //$NON-NLS-1$
buffer.append("void *vp;\n"); //$NON-NLS-1$
@@ -610,7 +610,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_16_1s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char c;\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
@@ -633,7 +633,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_5_16_1s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const char **cpp;\n"); //$NON-NLS-1$
buffer.append("char *p;\n"); //$NON-NLS-1$
@@ -657,7 +657,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s17() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
// offsetoff is a macro defined in stddef.h, using GNU definition
buffer.append("#define offsetof(TYPE, MEMBER) ((size_t) (&((TYPE *)0)->MEMBER))\n");
@@ -682,7 +682,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s18a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("struct s *s1;\n"); //$NON-NLS-1$
buffer.append("struct s *s2;\n"); //$NON-NLS-1$
@@ -699,7 +699,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_1s18b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct { int n; double d[8]; } *s1;\n"); //$NON-NLS-1$
buffer.append("struct { int n; double d[5]; } *s2;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -718,7 +718,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_2s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("enum hue { chartreuse, burgundy, claret=20, winedark };\n"); //$NON-NLS-1$
buffer.append("enum hue col, *cp;\n"); //$NON-NLS-1$
@@ -740,7 +740,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct tnode {\n"); //$NON-NLS-1$
buffer.append("int count;\n"); //$NON-NLS-1$
buffer.append("struct tnode *left, *right;\n"); //$NON-NLS-1$
@@ -760,7 +760,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef struct tnode TNODE;\n"); //$NON-NLS-1$
buffer.append("struct tnode {\n"); //$NON-NLS-1$
buffer.append("int count;\n"); //$NON-NLS-1$
@@ -778,7 +778,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_2_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s2;\n"); //$NON-NLS-1$
buffer.append("struct s1 { struct s2 *s2p; }; // D1\n"); //$NON-NLS-1$
buffer.append("struct s2 { struct s1 *s1p; }; // D2\n"); //$NON-NLS-1$
@@ -791,7 +791,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern const volatile int real_time_clock;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -815,7 +815,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("const struct s { int mem; } cs = { 1 };\n"); //$NON-NLS-1$
buffer.append("struct s ncs; // the object ncs is modifiable\n"); //$NON-NLS-1$
@@ -841,7 +841,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int * restrict a;\n"); //$NON-NLS-1$
buffer.append("int * restrict b;\n"); //$NON-NLS-1$
buffer.append("extern int c[];\n"); //$NON-NLS-1$
@@ -858,7 +858,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(int n, int * restrict p, int * restrict q)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("while (n-- > 0)\n"); //$NON-NLS-1$
@@ -883,7 +883,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void f(int n, int * restrict p, int * restrict q)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("while (n-- > 0)\n"); //$NON-NLS-1$
@@ -909,7 +909,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void h(int n, int * restrict p, int * restrict q, int * restrict r)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int i;\n"); //$NON-NLS-1$
@@ -936,7 +936,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s11() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int * restrict p1;\n"); //$NON-NLS-1$
@@ -965,7 +965,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_3_1s12() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef struct { int n; float * restrict v; } vector;\n"); //$NON-NLS-1$
buffer.append("vector new_vector(int n)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -995,7 +995,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_4s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("inline double fahr(double t)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("return (9.0 * t) / 5.0 + 32.0;\n"); //$NON-NLS-1$
@@ -1021,7 +1021,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("const int *ptr_to_constant;\n"); //$NON-NLS-1$
buffer.append("int *const constant_ptr1;\n"); //$NON-NLS-1$
buffer.append("typedef int *int_ptr;\n"); //$NON-NLS-1$
@@ -1035,7 +1035,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("float fa[11], *afp[17];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1047,7 +1047,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int *x;\n"); //$NON-NLS-1$
buffer.append("extern int y[];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -1070,7 +1070,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int n;\n"); //$NON-NLS-1$
buffer.append("extern int m;\n"); //$NON-NLS-1$
buffer.append("void fcompat(void)\n"); //$NON-NLS-1$
@@ -1110,7 +1110,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_2s10() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int n;\n"); //$NON-NLS-1$
buffer.append("int A[n]; // invalid: file scope VLA\n"); //$NON-NLS-1$
buffer.append("extern int (*p2)[n]; // invalid: file scope VM\n"); //$NON-NLS-1$
@@ -1139,7 +1139,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s16() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(void), *fip(), (*pfi)();\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1150,7 +1150,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s18() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int (*apfi[3])(int *x, int *y);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1161,7 +1161,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s19() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int (*fpfi(int (*)(long), int))(int, ...);\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1187,7 +1187,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s20() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void addscalar(int n, int m,\n"); //$NON-NLS-1$
buffer.append("double a[n][n*m+300], double x);\n"); //$NON-NLS-1$
buffer.append("int main()\n"); //$NON-NLS-1$
@@ -1222,7 +1222,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_5_3s21() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("double maximum1(int n, int m, double a[n][m]);\n"); //$NON-NLS-1$
buffer.append("double maximum2(int n, int m, double a[*][*]);\n"); //$NON-NLS-1$
buffer.append("double maximum3(int n, int m, double a[ ][*]);\n"); //$NON-NLS-1$
@@ -1245,7 +1245,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef int MILES, KLICKSP();\n"); //$NON-NLS-1$
buffer.append("typedef struct { double hi, lo; } range;\n"); //$NON-NLS-1$
buffer.append("MILES distance;\n"); //$NON-NLS-1$
@@ -1262,7 +1262,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef struct s1 { int x; } t1, *tp1;\n"); //$NON-NLS-1$
buffer.append("typedef struct s2 { int x; } t2, *tp2;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -1277,7 +1277,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef void fv(int), (*pfv)(int);\n"); //$NON-NLS-1$
buffer.append("void (*signal(int, void (*)(int)))(int);\n"); //$NON-NLS-1$
buffer.append("fv *signal(int, fv *);\n"); //$NON-NLS-1$
@@ -1299,7 +1299,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void copyt(int n)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("typedef int B[n]; // B is n ints, n evaluated now\n"); //$NON-NLS-1$
@@ -1319,7 +1319,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s24() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int i = 3.5;\n"); //$NON-NLS-1$
buffer.append("complex c = 5 + 3 * I;\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), false, 0);
@@ -1331,7 +1331,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s25() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int x[] = { 1, 3, 5 };\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1346,7 +1346,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s26a() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int y[4][3] = {\n"); //$NON-NLS-1$
buffer.append("{ 1, 3, 5 },\n"); //$NON-NLS-1$
buffer.append("{ 2, 4, 6 },\n"); //$NON-NLS-1$
@@ -1363,7 +1363,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s26b() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int y[4][3] = {\n"); //$NON-NLS-1$
buffer.append("1, 3, 5, 2, 4, 6, 3, 5, 7\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
@@ -1378,7 +1378,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s27() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int z[4][3] = {\n"); //$NON-NLS-1$
buffer.append("{ 1 }, { 2 }, { 3 }, { 4 }\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
@@ -1391,7 +1391,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s28() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct { int a[3], b; } w[] = { { 1 }, 2 };\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1423,7 +1423,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s29() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("short q1[4][3][2] = {\n"); //$NON-NLS-1$
buffer.append("{ 1 },\n"); //$NON-NLS-1$
buffer.append("{ 2, 3 },\n"); //$NON-NLS-1$
@@ -1457,7 +1457,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s31() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef int A[]; // OK - declared with block scope\n"); //$NON-NLS-1$
buffer.append("A a1 = { 1, 2 }, b1 = { 3, 4, 5 };\n"); //$NON-NLS-1$
buffer.append("int a2[] = { 1, 2 }, b2[] = { 3, 4, 5 };\n"); //$NON-NLS-1$
@@ -1475,7 +1475,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s32() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int foo() {\n"); //$NON-NLS-1$
buffer.append("char s1[] = \"abc\", t1[3] = \"abc\";\n"); //$NON-NLS-1$
buffer.append("char s2[] = { 'a', 'b', 'c', '\0' },\n"); //$NON-NLS-1$
@@ -1495,7 +1495,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s33() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("enum { member_one, member_two };\n"); //$NON-NLS-1$
buffer.append("const char *nm[] = {\n"); //$NON-NLS-1$
buffer.append("[member_two] = \"member two\",\n"); //$NON-NLS-1$
@@ -1510,7 +1510,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s34() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("div_t answer = { .quot = 2, .rem = -1 };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 1); // div_t (correctly) cannot be resolved
}
@@ -1522,7 +1522,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s35() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct { int a[3], b; } w[] =\n"); //$NON-NLS-1$
buffer.append("{ [0].a = {1}, [1].a[0] = 2 };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 0);
@@ -1537,7 +1537,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s36() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int MAX=15;\n"); //$NON-NLS-1$
buffer.append("int a[MAX] = {\n"); //$NON-NLS-1$
buffer.append("1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0\n"); //$NON-NLS-1$
@@ -1551,7 +1551,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_8s38() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("union { int any_member; } u = { .any_member = 42 };\n"); //$NON-NLS-1$
parse(buffer.toString(), ParserLanguage.C, true, 0);
}
@@ -1565,7 +1565,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int p(int);\n"); //$NON-NLS-1$
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("(void)p(0);\n"); //$NON-NLS-1$
@@ -1583,7 +1583,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("char *s;\n"); //$NON-NLS-1$
buffer.append("while (*s++ != '\0')\n"); //$NON-NLS-1$
@@ -1608,7 +1608,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_3s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("int i=1;\n"); //$NON-NLS-1$
buffer.append("while (i) {\n"); //$NON-NLS-1$
@@ -1640,7 +1640,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_4s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f(int a) {}\n"); //$NON-NLS-1$
buffer.append("int g(int expr) {\n"); //$NON-NLS-1$
buffer.append("switch (expr)\n"); //$NON-NLS-1$
@@ -1674,7 +1674,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_1s3() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("goto first_time;\n"); //$NON-NLS-1$
buffer.append("for (;;) {\n"); //$NON-NLS-1$
@@ -1710,7 +1710,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("goto lab3; // invalid: going INTO scope of VLA.\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
@@ -1751,7 +1751,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_8_6_4s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("struct s { double i; } f(void);\n"); //$NON-NLS-1$
buffer.append("union {\n"); //$NON-NLS-1$
buffer.append("struct {\n"); //$NON-NLS-1$
@@ -1782,7 +1782,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_1s13() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("extern int max(int a, int b)\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("return a > b ? a : b;\n"); //$NON-NLS-1$
@@ -1800,7 +1800,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_1s14() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("void g(int (*funcp)(void))\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("(*funcp)();\n"); //$NON-NLS-1$
@@ -1829,7 +1829,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_9_2s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int i1 = 1; // definition, external linkage\n"); //$NON-NLS-1$
buffer.append("static int i2 = 2; // definition, internal linkage\n"); //$NON-NLS-1$
buffer.append("extern int i3 = 3; // definition, external linkage\n"); //$NON-NLS-1$
@@ -1861,7 +1861,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_1s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("int g() {}\n"); //$NON-NLS-1$
buffer.append("int f() {\n"); //$NON-NLS-1$
buffer.append("#if 'z' - 'a' == 25\n"); //$NON-NLS-1$
@@ -1884,7 +1884,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_3s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define hash_hash # ## #\n"); //$NON-NLS-1$
buffer.append("#define mkstr(a) # a\n"); //$NON-NLS-1$
buffer.append("#define in_between(a) mkstr(a)\n"); //$NON-NLS-1$
@@ -1901,7 +1901,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s3() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define TABSIZE 100\n"); //$NON-NLS-1$
buffer.append("int table[TABSIZE];\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
@@ -1913,7 +1913,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s4() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define max(a, b) ((a) > (b) ? (a) : (b))\n"); //$NON-NLS-1$
parseCandCPP(buffer.toString(), true, 0);
}
@@ -1941,7 +1941,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s5() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define x 3\n"); //$NON-NLS-1$
buffer.append("#define f(a) f(x * (a))\n"); //$NON-NLS-1$
buffer.append("#undef x\n"); //$NON-NLS-1$
@@ -1985,7 +1985,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define str(s) # s \n"); //$NON-NLS-1$
buffer.append("#define xstr(s) str(s) \n"); //$NON-NLS-1$
buffer.append("#define debug(s, t) printf(\"x\" # s \"= %d, x\" # t \"= %s\", \\\n"); //$NON-NLS-1$
@@ -2017,7 +2017,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s7() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$
buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$
buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$
@@ -2036,7 +2036,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s8() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define OBJ_LIKE1 (1-1)\n"); //$NON-NLS-1$
buffer.append("#define OBJ_LIKE2 \\n"); //$NON-NLS-1$
buffer.append(" (1-1) \\n"); //$NON-NLS-1$
@@ -2062,7 +2062,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_10_3_5s9() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("#define debug(...) fprintf(stderr, __VA_ARGS__)\n"); //$NON-NLS-1$
buffer.append("#define showlist(...) puts(#__VA_ARGS__)\n"); //$NON-NLS-1$
buffer.append("#define report(test, ...) ((test)?puts(#test):\\\n"); //$NON-NLS-1$
@@ -2095,7 +2095,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest {
--End Example]
*/
public void test6_7_7s6() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef signed int t;\n"); //$NON-NLS-1$
buffer.append("typedef int plain;\n"); //$NON-NLS-1$
buffer.append("struct tag {\n"); //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
index 6044bae340e..452ca0e7ec2 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2KnRTests.java
@@ -69,161 +69,161 @@ public class AST2KnRTests extends AST2BaseTest {
}
public void testSimpleKRCTest1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(char x);\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(char x);\n"); //$NON-NLS-1$
+ buffer.append("int f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- IParameter x1 = (IParameter)((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName().resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x1 = (IParameter) ((IASTStandardFunctionDeclarator) f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName().resolveBinding();
- assertNotNull( x1 );
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x1, x2 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x1);
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x1, x2);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x1);
- assertEquals( decls.length, 2 );
- assertEquals( decls[0], ((IASTStandardFunctionDeclarator)f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName() );
- assertEquals( decls[1], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
+ assertEquals(decls.length, 2);
+ assertEquals(decls[0], ((IASTStandardFunctionDeclarator) f1.getDeclarators()[0]).getParameters()[0].getDeclarator().getName());
+ assertEquals(decls[1], ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testSimpleKRCTest2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f();\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f();\n"); //$NON-NLS-1$
+ buffer.append("int f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x2);
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName() );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f2.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testSimpleKRCTest3() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int const *f();\n" ); //$NON-NLS-1$
- buffer.append( "int const *f(x) char x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int const *f();\n"); //$NON-NLS-1$
+ buffer.append("int const *f(x) char x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration f1 = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTFunctionDefinition f2 = (IASTFunctionDefinition)tu.getDeclarations()[1];
+ IASTSimpleDeclaration f1 = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTFunctionDefinition f2 = (IASTFunctionDefinition) tu.getDeclarations()[1];
- assertTrue( f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
+ assertTrue(f1.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
- IParameter x4 = (IParameter)((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
- IParameter x3 = (IParameter)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
- IParameter x2 = (IParameter)((ICASTKnRFunctionDeclarator)f2.getDeclarator()).getParameterNames()[0].resolveBinding();
+ IParameter x4 = (IParameter) ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f2.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding();
+ IParameter x3 = (IParameter) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName().resolveBinding();
+ IParameter x2 = (IParameter) ((ICASTKnRFunctionDeclarator) f2.getDeclarator()).getParameterNames()[0].resolveBinding();
- assertNotNull( x2 );
- assertNotNull( x3 );
- assertNotNull( x4 );
- assertEquals( x2, x3 );
- assertEquals( x3, x4 );
+ assertNotNull(x2);
+ assertNotNull(x3);
+ assertNotNull(x4);
+ assertEquals(x2, x3);
+ assertEquals(x3, x4);
}
public void testKRC_1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int isroot (x, y) /* comment */ \n" ); //$NON-NLS-1$
- buffer.append( "int x;\n" ); //$NON-NLS-1$
- buffer.append( "int y;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int isroot (x, y) /* comment */ \n"); //$NON-NLS-1$
+ buffer.append("int x;\n"); //$NON-NLS-1$
+ buffer.append("int y;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition isroot_def = (IASTFunctionDefinition) tu.getDeclarations()[0];
- IASTName ret_x = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+ IASTName ret_x = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
IASTDeclarator isroot_decltor = isroot_def.getDeclarator();
- assertTrue( isroot_decltor instanceof ICASTKnRFunctionDeclarator );
- IASTDeclarator x1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
- IASTDeclarator y1 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
+ assertTrue(isroot_decltor instanceof ICASTKnRFunctionDeclarator);
+ IASTDeclarator x1 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
+ IASTDeclarator y1 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
- IParameter x_parm = (IParameter)x1.getName().resolveBinding();
- IParameter y_parm = (IParameter)y1.getName().resolveBinding();
- assertNotNull( x_parm );
- assertNotNull( y_parm );
+ IParameter x_parm = (IParameter) x1.getName().resolveBinding();
+ IParameter y_parm = (IParameter) y1.getName().resolveBinding();
+ assertNotNull(x_parm);
+ assertNotNull(y_parm);
- IASTDeclarator x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
- IASTDeclarator y2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
+ IASTDeclarator x2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[0]).getDeclarators()[0];
+ IASTDeclarator y2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_decltor).getParameterDeclarations()[1]).getDeclarators()[0];
- IParameter x_parm2 = (IParameter)x2.getName().resolveBinding();
- IParameter y_parm2 = (IParameter)y2.getName().resolveBinding();
+ IParameter x_parm2 = (IParameter) x2.getName().resolveBinding();
+ IParameter y_parm2 = (IParameter) y2.getName().resolveBinding();
- assertNotNull( x_parm2 );
- assertNotNull( y_parm2 );
- assertNotNull( ret_x.resolveBinding() );
+ assertNotNull(x_parm2);
+ assertNotNull(y_parm2);
+ assertNotNull(ret_x.resolveBinding());
- assertEquals( x_parm, x_parm2 );
- assertEquals( y_parm, y_parm2 );
- assertEquals( ret_x.resolveBinding(), x_parm );
+ assertEquals(x_parm, x_parm2);
+ assertEquals(y_parm, y_parm2);
+ assertEquals(ret_x.resolveBinding(), x_parm);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(ret_x.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x1.getName() );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x1.getName());
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("y").toCharArray())); //$NON-NLS-1$
}
public void testKRCWithTypes() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef char c;\n" ); //$NON-NLS-1$
- buffer.append( "int isroot (c);\n" ); //$NON-NLS-1$
- buffer.append( "int isroot (x) \n" ); //$NON-NLS-1$
- buffer.append( "c x;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef char c;\n"); //$NON-NLS-1$
+ buffer.append("int isroot (c);\n"); //$NON-NLS-1$
+ buffer.append("int isroot (x) \n"); //$NON-NLS-1$
+ buffer.append("c x;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration c_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTFunctionDefinition isroot_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
+ IASTSimpleDeclaration c_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration isroot_decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTFunctionDefinition isroot_def = (IASTFunctionDefinition) tu.getDeclarations()[2];
- //IASTName x0 = ((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
- IASTName x1 = ((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterNames()[0];
- IASTName x2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+ //IASTName x0 = ((IASTStandardFunctionDeclarator) isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclarator().getName();
+ IASTName x1 = ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterNames()[0];
+ IASTName x2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName x3 = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) isroot_def.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
- IParameter x1_var = (IParameter)x1.resolveBinding();
- IParameter x2_var = (IParameter)x2.resolveBinding();
- IParameter x3_var = (IParameter)x3.resolveBinding();
+ IParameter x1_var = (IParameter) x1.resolveBinding();
+ IParameter x2_var = (IParameter) x2.resolveBinding();
+ IParameter x3_var = (IParameter) x3.resolveBinding();
assertNotNull(x1_var);
assertNotNull(x2_var);
@@ -232,12 +232,12 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(x2_var, x3_var);
IASTName c1 = c_decl.getDeclarators()[0].getName();
- IASTName c2 = ((IASTNamedTypeSpecifier)((IASTStandardFunctionDeclarator)isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
- IASTName c3 = ((IASTNamedTypeSpecifier)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
+ IASTName c2 = ((IASTNamedTypeSpecifier) ((IASTStandardFunctionDeclarator) isroot_decl.getDeclarators()[0]).getParameters()[0].getDeclSpecifier()).getName();
+ IASTName c3 = ((IASTNamedTypeSpecifier) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) isroot_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
- ITypedef c1_t = (ITypedef)c1.resolveBinding();
- ITypedef c2_t = (ITypedef)c2.resolveBinding();
- ITypedef c3_t = (ITypedef)c3.resolveBinding();
+ ITypedef c1_t = (ITypedef) c1.resolveBinding();
+ ITypedef c2_t = (ITypedef) c2.resolveBinding();
+ ITypedef c3_t = (ITypedef) c3.resolveBinding();
assertNotNull(c1_t);
assertNotNull(c2_t);
@@ -245,101 +245,101 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(c1_t, c2_t);
assertEquals(c2_t, c3_t);
assertTrue(c1_t.getType() instanceof IBasicType);
- assertEquals(((IBasicType)c1_t.getType()).getType(), IBasicType.t_char);
+ assertEquals(((IBasicType) c1_t.getType()).getType(), IBasicType.t_char);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x3.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("c").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("isroot").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) isroot_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testKRCProblem1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
IASTDeclaration[] decls= tu.getDeclarations();
assertTrue(CVisitor.getProblems(tu).length > 0);
}
public void testKRCProblem2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int i=0;\n" ); //$NON-NLS-1$
- buffer.append( "int f(x) i++;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int i=0;\n"); //$NON-NLS-1$
+ buffer.append("int f(x) i++;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
IASTSimpleDeclaration sd= getDeclaration(tu, 0);
assertTrue(CVisitor.getProblems(tu).length > 0);
}
public void testKRCProblem3() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char y;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char y;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 0 );
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 0);
}
public void testKRCProblem4() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x,y,z) char x,y,z; int a;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x,y,z) char x,y,z; int a;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTSimpleDeclaration);
assertTrue(f_kr.getParameterDeclarations()[1] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// bindings should still be ok
IASTName x1 = f_kr.getParameterNames()[0];
IASTName y1 = f_kr.getParameterNames()[1];
IASTName z1 = f_kr.getParameterNames()[2];
- IASTName x2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName y2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[1].getName();
- IASTName z2 = ((IASTSimpleDeclaration)f_kr.getParameterDeclarations()[0]).getDeclarators()[2].getName();
- IASTName x3 = ((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
+ IASTName x2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName y2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[1].getName();
+ IASTName z2 = ((IASTSimpleDeclaration) f_kr.getParameterDeclarations()[0]).getDeclarators()[2].getName();
+ IASTName x3 = ((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName();
- IParameter x1_parm = (IParameter)x1.resolveBinding();
- IParameter x2_parm = (IParameter)x2.resolveBinding();
- IParameter x3_parm = (IParameter)x3.resolveBinding();
- IParameter y1_parm = (IParameter)y1.resolveBinding();
- IParameter y2_parm = (IParameter)y2.resolveBinding();
- IParameter z1_parm = (IParameter)z1.resolveBinding();
- IParameter z2_parm = (IParameter)z2.resolveBinding();
+ IParameter x1_parm = (IParameter) x1.resolveBinding();
+ IParameter x2_parm = (IParameter) x2.resolveBinding();
+ IParameter x3_parm = (IParameter) x3.resolveBinding();
+ IParameter y1_parm = (IParameter) y1.resolveBinding();
+ IParameter y2_parm = (IParameter) y2.resolveBinding();
+ IParameter z1_parm = (IParameter) z1.resolveBinding();
+ IParameter z2_parm = (IParameter) z2.resolveBinding();
assertEquals(x1_parm, x2_parm);
assertEquals(x2_parm, x3_parm);
@@ -347,267 +347,265 @@ public class AST2KnRTests extends AST2BaseTest {
assertEquals(z1_parm, z2_parm);
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
-
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
}
public void testKRCProblem5() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(x) char x,a;\n" ); //$NON-NLS-1$
- buffer.append( "{ return x == 0; }\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true, false );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(x) char x,a;\n"); //$NON-NLS-1$
+ buffer.append("{ return x == 0; }\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, false);
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
assertTrue(f.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator)f.getDeclarator();
+ ICASTKnRFunctionDeclarator f_kr = (ICASTKnRFunctionDeclarator) f.getDeclarator();
assertEquals(f_kr.getName().toString(), "f"); //$NON-NLS-1$
assertEquals(f_kr.getParameterNames()[0].toString(), "x"); //$NON-NLS-1$
assertTrue(f_kr.getParameterDeclarations()[0] instanceof IASTProblemDeclaration);
assertTrue(f.getBody() instanceof IASTCompoundStatement);
- assertTrue(((IASTCompoundStatement)f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
- assertTrue(((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
- assertEquals(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
- assertTrue(((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
- assertEquals(((IASTLiteralExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTCompoundStatement) f.getBody()).getStatements()[0] instanceof IASTReturnStatement);
+ assertTrue(((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue() instanceof IASTBinaryExpression);
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1() instanceof IASTIdExpression);
+ assertEquals(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().toString(), "x"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2() instanceof IASTLiteralExpression);
+ assertEquals(((IASTLiteralExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand2()).toString(), "0"); //$NON-NLS-1$
// test tu.getDeclarationsInAST(IBinding)
- IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression)((IASTBinaryExpression)((IASTReturnStatement)((IASTCompoundStatement)f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
- assertEquals( decls.length, 0 );
+ IASTName[] decls = tu.getDeclarationsInAST(((IASTIdExpression) ((IASTBinaryExpression) ((IASTReturnStatement) ((IASTCompoundStatement) f.getBody()).getStatements()[0]).getReturnValue()).getOperand1()).getName().resolveBinding());
+ assertEquals(decls.length, 0);
}
public void testKRC_monop_cards1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "#ifdef __STDC__\n" ); //$NON-NLS-1$
- buffer.append( "#define __P(x) x\n" ); //$NON-NLS-1$
- buffer.append( "#else\n" ); //$NON-NLS-1$
- buffer.append( "#define __P(x) ()\n" ); //$NON-NLS-1$
- buffer.append( "#endif\n" ); //$NON-NLS-1$
- buffer.append( "struct A_struct {\n" ); //$NON-NLS-1$
- buffer.append( "int a;\n" ); //$NON-NLS-1$
- buffer.append( "long *c;\n" ); //$NON-NLS-1$
- buffer.append( "};\n" ); //$NON-NLS-1$
- buffer.append( "typedef struct A_struct A;\n" ); //$NON-NLS-1$
- buffer.append( "static void f __P((A *));\n" ); //$NON-NLS-1$
- buffer.append( "static void\n" ); //$NON-NLS-1$
- buffer.append( "f(x)\n" ); //$NON-NLS-1$
- buffer.append( "A *x; {\n" ); //$NON-NLS-1$
- buffer.append( "x->a = 0;\n" ); //$NON-NLS-1$
- buffer.append( "x->c[1]=x->c[2];\n" ); //$NON-NLS-1$
- buffer.append( "}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("#ifdef __STDC__\n"); //$NON-NLS-1$
+ buffer.append("#define __P(x) x\n"); //$NON-NLS-1$
+ buffer.append("#else\n"); //$NON-NLS-1$
+ buffer.append("#define __P(x) ()\n"); //$NON-NLS-1$
+ buffer.append("#endif\n"); //$NON-NLS-1$
+ buffer.append("struct A_struct {\n"); //$NON-NLS-1$
+ buffer.append("int a;\n"); //$NON-NLS-1$
+ buffer.append("long *c;\n"); //$NON-NLS-1$
+ buffer.append("};\n"); //$NON-NLS-1$
+ buffer.append("typedef struct A_struct A;\n"); //$NON-NLS-1$
+ buffer.append("static void f __P((A *));\n"); //$NON-NLS-1$
+ buffer.append("static void\n"); //$NON-NLS-1$
+ buffer.append("f(x)\n"); //$NON-NLS-1$
+ buffer.append("A *x; {\n"); //$NON-NLS-1$
+ buffer.append("x->a = 0;\n"); //$NON-NLS-1$
+ buffer.append("x->c[1]=x->c[2];\n"); //$NON-NLS-1$
+ buffer.append("}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration A_struct = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration A = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration)tu.getDeclarations()[2];
- IASTFunctionDefinition f_def = (IASTFunctionDefinition)tu.getDeclarations()[3];
+ IASTSimpleDeclaration A_struct = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration A = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTSimpleDeclaration f_decl = (IASTSimpleDeclaration) tu.getDeclarations()[2];
+ IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[3];
// check A_struct
- assertTrue( A_struct.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier );
- assertEquals( A_struct.getDeclarators().length, 0 );
+ assertTrue(A_struct.getDeclSpecifier() instanceof IASTCompositeTypeSpecifier);
+ assertEquals(A_struct.getDeclarators().length, 0);
IASTName A_struct_name1 = ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName();
- assertEquals( A_struct_name1.toString(), "A_struct" ); //$NON-NLS-1$
+ assertEquals(A_struct_name1.toString(), "A_struct"); //$NON-NLS-1$
ICompositeType A_struct_type1 = (ICompositeType)A_struct_name1.resolveBinding();
- assertEquals( ((ICInternalBinding)A_struct_type1).getPhysicalNode(), ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName() );
+ assertEquals(((ICInternalBinding)A_struct_type1).getPhysicalNode(), ((IASTCompositeTypeSpecifier)A_struct.getDeclSpecifier()).getName());
IField[] fields = A_struct_type1.getFields();
IField a1 = fields[0];
IField c1 = fields[1];
- assertEquals( a1.getName().toString(), "a" ); //$NON-NLS-1$
- assertEquals( c1.getName().toString(), "c" ); //$NON-NLS-1$
- IBasicType a1_t = (IBasicType)a1.getType();
- IPointerType c1_t = (IPointerType)c1.getType();
- assertEquals( a1_t.getType(), IBasicType.t_int );
- assertTrue( c1_t.getType() instanceof IBasicType );
- assertTrue( ((IBasicType)c1_t.getType()).isLong() );
+ assertEquals(a1.getName().toString(), "a"); //$NON-NLS-1$
+ assertEquals(c1.getName().toString(), "c"); //$NON-NLS-1$
+ IBasicType a1_t = (IBasicType) a1.getType();
+ IPointerType c1_t = (IPointerType) c1.getType();
+ assertEquals(a1_t.getType(), IBasicType.t_int);
+ assertTrue(c1_t.getType() instanceof IBasicType);
+ assertTrue(((IBasicType) c1_t.getType()).isLong());
// check A
IASTName A_name1 = A.getDeclarators()[0].getName();
- assertEquals( A_name1.toString(), "A" ); //$NON-NLS-1$
+ assertEquals(A_name1.toString(), "A"); //$NON-NLS-1$
ITypedef A_var1 = (ITypedef)A_name1.resolveBinding();
- assertTrue( A.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier );
+ assertTrue(A.getDeclSpecifier() instanceof IASTElaboratedTypeSpecifier);
IASTName A_struct_name_2 = ((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getName();
- assertEquals( A_struct_name_2.toString(), "A_struct" ); //$NON-NLS-1$
- assertEquals( ((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getStorageClass(), IASTDeclSpecifier.sc_typedef );
+ assertEquals(A_struct_name_2.toString(), "A_struct"); //$NON-NLS-1$
+ assertEquals(((IASTElaboratedTypeSpecifier)A.getDeclSpecifier()).getStorageClass(), IASTDeclSpecifier.sc_typedef);
ICompositeType A_struct_type2 = (ICompositeType)A_struct_name_2.resolveBinding();
- assertEquals( A_struct_type2, A_struct_type1 );
+ assertEquals(A_struct_type2, A_struct_type1);
// check f_decl
- assertTrue( f_decl.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator );
- IASTStandardFunctionDeclarator f_decltor1 = ((IASTStandardFunctionDeclarator)f_decl.getDeclarators()[0]);
+ assertTrue(f_decl.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator);
+ IASTStandardFunctionDeclarator f_decltor1 = ((IASTStandardFunctionDeclarator) f_decl.getDeclarators()[0]);
IASTName f_name1 = f_decltor1.getName();
- IFunction f_fun1 = (IFunction)f_name1.resolveBinding();
- assertEquals( f_name1.toString(), "f" ); //$NON-NLS-1$
- assertEquals( f_decltor1.getParameters().length, 1 );
+ IFunction f_fun1 = (IFunction) f_name1.resolveBinding();
+ assertEquals(f_name1.toString(), "f"); //$NON-NLS-1$
+ assertEquals(f_decltor1.getParameters().length, 1);
//IASTName x0 = f_decltor1.getParameters()[0].getDeclarator().getName();
- IASTName A_name2 = ((ICASTTypedefNameSpecifier)f_decltor1.getParameters()[0].getDeclSpecifier()).getName();
- assertEquals( A_name2.toString(), "A" ); //$NON-NLS-1$
+ IASTName A_name2 = ((ICASTTypedefNameSpecifier) f_decltor1.getParameters()[0].getDeclSpecifier()).getName();
+ assertEquals(A_name2.toString(), "A"); //$NON-NLS-1$
ITypedef A_var2 = (ITypedef)A_name2.resolveBinding();
- assertEquals( A_var1, A_var2 );
+ assertEquals(A_var1, A_var2);
// check f_def
- assertTrue( f_def.getDeclarator() instanceof ICASTKnRFunctionDeclarator );
+ assertTrue(f_def.getDeclarator() instanceof ICASTKnRFunctionDeclarator);
- ICASTKnRFunctionDeclarator f_decltor2 = (ICASTKnRFunctionDeclarator)f_def.getDeclarator();
- assertEquals( f_decltor2.getName().toString(), "f" ); //$NON-NLS-1$
- IFunction f_fun2 = (IFunction)f_decltor2.getName().resolveBinding();
- assertEquals( f_fun1, f_fun2 );
- ICBasicType f_ret_t = (ICBasicType)f_fun2.getType().getReturnType();
- assertEquals( f_ret_t.getType(), IBasicType.t_void );
+ ICASTKnRFunctionDeclarator f_decltor2 = (ICASTKnRFunctionDeclarator) f_def.getDeclarator();
+ assertEquals(f_decltor2.getName().toString(), "f"); //$NON-NLS-1$
+ IFunction f_fun2 = (IFunction) f_decltor2.getName().resolveBinding();
+ assertEquals(f_fun1, f_fun2);
+ ICBasicType f_ret_t = (ICBasicType) f_fun2.getType().getReturnType();
+ assertEquals(f_ret_t.getType(), IBasicType.t_void);
IASTName x1 = f_decltor2.getParameterNames()[0];
- assertEquals( x1.toString(), "x" ); //$NON-NLS-1$
- IASTSimpleDeclaration x_parm = (IASTSimpleDeclaration)f_decltor2.getParameterDeclarations()[0];
+ assertEquals(x1.toString(), "x"); //$NON-NLS-1$
+ IASTSimpleDeclaration x_parm = (IASTSimpleDeclaration) f_decltor2.getParameterDeclarations()[0];
IASTName x2 = x_parm.getDeclarators()[0].getName();
- assertEquals( x2.toString(), "x" ); //$NON-NLS-1$
- assertEquals( x_parm.getDeclarators()[0].getPointerOperators().length, 1 );
- IASTName A3 = ((IASTNamedTypeSpecifier)x_parm.getDeclSpecifier()).getName();
+ assertEquals(x2.toString(), "x"); //$NON-NLS-1$
+ assertEquals(x_parm.getDeclarators()[0].getPointerOperators().length, 1);
+ IASTName A3 = ((IASTNamedTypeSpecifier) x_parm.getDeclSpecifier()).getName();
ITypedef A_var3 = (ITypedef)A3.resolveBinding();
- assertEquals( A_var2, A_var3 );
- assertEquals( A3.toString(), "A" ); //$NON-NLS-1$;
- assertEquals( x1.resolveBinding(), x2.resolveBinding() );
+ assertEquals(A_var2, A_var3);
+ assertEquals(A3.toString(), "A"); //$NON-NLS-1$;
+ assertEquals(x1.resolveBinding(), x2.resolveBinding());
// check f_def body
- assertTrue( f_def.getBody() instanceof IASTCompoundStatement );
- IASTCompoundStatement f_def_body = (IASTCompoundStatement)f_def.getBody();
- IASTExpressionStatement stmt1 = (IASTExpressionStatement)f_def_body.getStatements()[0];
- IASTExpressionStatement stmt2 = (IASTExpressionStatement)f_def_body.getStatements()[1];
- IASTName a2 = ((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldName();
- assertEquals( ((IASTName)((ICInternalBinding)a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding() );
- IASTName x3 = ((IASTIdExpression)((IASTFieldReference)((IASTBinaryExpression)stmt1.getExpression()).getOperand1()).getFieldOwner()).getName();
- assertEquals( x2.resolveBinding(), x3.resolveBinding() );
- assertEquals( ((IASTBinaryExpression)stmt1.getExpression()).getOperand2().toString(), "0" ); //$NON-NLS-1$
- assertTrue( ((IASTBinaryExpression)stmt2.getExpression()).getOperand1() instanceof IASTArraySubscriptExpression );
- assertTrue( ((IASTBinaryExpression)stmt2.getExpression()).getOperand2() instanceof IASTArraySubscriptExpression );
- IASTName c2 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldName();
- IASTName x4 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
- IASTName c3 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName();
- IASTName x5 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTBinaryExpression)stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
- assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding() );
- assertEquals( ((IASTName)((ICInternalBinding)c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding() );
- assertEquals( x3.resolveBinding(), x4.resolveBinding() );
- assertEquals( x4.resolveBinding(), x5.resolveBinding() );
+ assertTrue(f_def.getBody() instanceof IASTCompoundStatement);
+ IASTCompoundStatement f_def_body = (IASTCompoundStatement) f_def.getBody();
+ IASTExpressionStatement stmt1 = (IASTExpressionStatement) f_def_body.getStatements()[0];
+ IASTExpressionStatement stmt2 = (IASTExpressionStatement) f_def_body.getStatements()[1];
+ IASTName a2 = ((IASTFieldReference) ((IASTBinaryExpression) stmt1.getExpression()).getOperand1()).getFieldName();
+ assertEquals(((IASTName) ((ICInternalBinding) a1).getPhysicalNode()).resolveBinding(), a2.resolveBinding());
+ IASTName x3 = ((IASTIdExpression) ((IASTFieldReference) ((IASTBinaryExpression) stmt1.getExpression()).getOperand1()).getFieldOwner()).getName();
+ assertEquals(x2.resolveBinding(), x3.resolveBinding());
+ assertEquals(((IASTBinaryExpression) stmt1.getExpression()).getOperand2().toString(), "0"); //$NON-NLS-1$
+ assertTrue(((IASTBinaryExpression) stmt2.getExpression()).getOperand1() instanceof IASTArraySubscriptExpression);
+ assertTrue(((IASTBinaryExpression) stmt2.getExpression()).getOperand2() instanceof IASTArraySubscriptExpression);
+ IASTName c2 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldName();
+ IASTName x4 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
+ IASTName c3 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand2()).getArrayExpression()).getFieldName();
+ IASTName x5 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTBinaryExpression) stmt2.getExpression()).getOperand1()).getArrayExpression()).getFieldOwner()).getName();
+ assertEquals(((IASTName) ((ICInternalBinding) c1).getPhysicalNode()).resolveBinding(), c2.resolveBinding());
+ assertEquals(((IASTName) ((ICInternalBinding) c1).getPhysicalNode()).resolveBinding(), c3.resolveBinding());
+ assertEquals(x3.resolveBinding(), x4.resolveBinding());
+ assertEquals(x4.resolveBinding(), x5.resolveBinding());
// test CFunction.getParameters size
IParameter[] f1_parms = f_fun1.getParameters();
- assertEquals( f1_parms.length, 1 );
+ assertEquals(f1_parms.length, 1);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(x2.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], x2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], x2);
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray()) ); //$NON-NLS-1$
- assertNotNull( ((CScope)((IASTCompoundStatement)f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray()) ); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_TAG, new String("A_struct").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("A").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) tu.getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("f").toCharArray())); //$NON-NLS-1$
+ assertNotNull(((CScope) ((IASTCompoundStatement) f_def.getBody()).getScope()).getBinding(CScope.NAMESPACE_TYPE_OTHER, new String("x").toCharArray())); //$NON-NLS-1$
}
public void testKRC_monop_cards2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int\n" ); //$NON-NLS-1$
- buffer.append( "getinp(prompt, list)\n" ); //$NON-NLS-1$
- buffer.append( " const char *prompt, *const list[];\n" ); //$NON-NLS-1$
- buffer.append( "{\n *list[1] = 'a';\n}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int\n"); //$NON-NLS-1$
+ buffer.append("getinp(prompt, list)\n"); //$NON-NLS-1$
+ buffer.append(" const char *prompt, *const list[];\n"); //$NON-NLS-1$
+ buffer.append("{\n *list[1] = 'a';\n}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTFunctionDefinition getinp = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTFunctionDefinition getinp = (IASTFunctionDefinition) tu.getDeclarations()[0];
- IASTName prompt1 = ((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterNames()[0];
- IASTName list1 = ((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterNames()[1];
- IASTName prompt2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName list2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[1].getName();
- IASTName list3 = ((IASTIdExpression)((IASTArraySubscriptExpression)((IASTUnaryExpression)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)getinp.getBody()).getStatements()[0]).getExpression()).getOperand1()).getOperand()).getArrayExpression()).getName();
+ IASTName prompt1 = ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterNames()[0];
+ IASTName list1 = ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterNames()[1];
+ IASTName prompt2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName list2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[1].getName();
+ IASTName list3 = ((IASTIdExpression) ((IASTArraySubscriptExpression) ((IASTUnaryExpression) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) getinp.getBody()).getStatements()[0]).getExpression()).getOperand1()).getOperand()).getArrayExpression()).getName();
- assertEquals( prompt1.resolveBinding(), prompt2.resolveBinding() );
- assertEquals( list1.resolveBinding(), list2.resolveBinding() );
- assertEquals( list2.resolveBinding(), list3.resolveBinding() );
+ assertEquals(prompt1.resolveBinding(), prompt2.resolveBinding());
+ assertEquals(list1.resolveBinding(), list2.resolveBinding());
+ assertEquals(list2.resolveBinding(), list3.resolveBinding());
- IASTSimpleDeclaration parm_decl = (IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)getinp.getDeclarator()).getParameterDeclarations()[0];
- assertTrue( ((IASTSimpleDeclSpecifier)parm_decl.getDeclSpecifier()).isConst() );
- assertEquals( ((IASTSimpleDeclSpecifier)parm_decl.getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_char );
+ IASTSimpleDeclaration parm_decl = (IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) getinp.getDeclarator()).getParameterDeclarations()[0];
+ assertTrue(((IASTSimpleDeclSpecifier) parm_decl.getDeclSpecifier()).isConst());
+ assertEquals(((IASTSimpleDeclSpecifier) parm_decl.getDeclSpecifier()).getType(), IASTSimpleDeclSpecifier.t_char);
IASTDeclarator prompt = parm_decl.getDeclarators()[0];
- IASTArrayDeclarator list = (IASTArrayDeclarator)parm_decl.getDeclarators()[1];
- assertEquals( prompt.getName().toString(), "prompt" ); //$NON-NLS-1$
- assertEquals( prompt.getPointerOperators().length, 1 );
- assertEquals( list.getName().toString(), "list" ); //$NON-NLS-1$
- assertEquals( list.getArrayModifiers().length, 1 );
- assertNull( list.getArrayModifiers()[0].getConstantExpression() );
- assertEquals( list.getPointerOperators().length, 1 );
+ IASTArrayDeclarator list = (IASTArrayDeclarator) parm_decl.getDeclarators()[1];
+ assertEquals(prompt.getName().toString(), "prompt"); //$NON-NLS-1$
+ assertEquals(prompt.getPointerOperators().length, 1);
+ assertEquals(list.getName().toString(), "list"); //$NON-NLS-1$
+ assertEquals(list.getArrayModifiers().length, 1);
+ assertNull(list.getArrayModifiers()[0].getConstantExpression());
+ assertEquals(list.getPointerOperators().length, 1);
// test tu.getDeclarationsInAST(IBinding)
IASTName[] decls = tu.getDeclarationsInAST(list3.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], list2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], list2);
decls = tu.getDeclarationsInAST(prompt1.resolveBinding());
- assertEquals( decls.length, 1 );
- assertEquals( decls[0], prompt2 );
+ assertEquals(decls.length, 1);
+ assertEquals(decls[0], prompt2);
}
public void testKRC_getParametersOrder() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f(a, b) int b,a;{}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
-
- IASTFunctionDefinition f = (IASTFunctionDefinition)tu.getDeclarations()[0];
- ICASTKnRFunctionDeclarator f_decltor = (ICASTKnRFunctionDeclarator)f.getDeclarator();
- IFunction f_fun = (IFunction)f_decltor.getName().resolveBinding();
- IParameter [] f_parms = f_fun.getParameters();
- assertEquals( f_parms.length, 2 );
- assertEquals( ((CParameter)f_parms[0]).getName(), "a" ); //$NON-NLS-1$
- assertEquals( ((CParameter)f_parms[1]).getName(), "b" ); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(a, b) int b,a;{}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
+ IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0];
+ ICASTKnRFunctionDeclarator f_decltor = (ICASTKnRFunctionDeclarator) f.getDeclarator();
+ IFunction f_fun = (IFunction) f_decltor.getName().resolveBinding();
+ IParameter[] f_parms = f_fun.getParameters();
+ assertEquals(f_parms.length, 2);
+ assertEquals(((CParameter) f_parms[0]).getName(), "a"); //$NON-NLS-1$
+ assertEquals(((CParameter) f_parms[1]).getName(), "b"); //$NON-NLS-1$
}
public void testKRC_Ethereal_1() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct symbol {\n" ); //$NON-NLS-1$
- buffer.append( "int lambda;\n};\n" ); //$NON-NLS-1$
- buffer.append( "struct lemon {\n" ); //$NON-NLS-1$
- buffer.append( "struct symbol **symbols;\n" ); //$NON-NLS-1$
- buffer.append( "int errorcnt;\n};\n" ); //$NON-NLS-1$
- buffer.append( "void f(lemp)\n" ); //$NON-NLS-1$
- buffer.append( "struct lemon *lemp;\n{\n" ); //$NON-NLS-1$
- buffer.append( "lemp->symbols[1]->lambda = 1;\n" ); //$NON-NLS-1$
- buffer.append( "lemp->errorcnt++;}\n" ); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C, true );
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct symbol {\n"); //$NON-NLS-1$
+ buffer.append("int lambda;\n};\n"); //$NON-NLS-1$
+ buffer.append("struct lemon {\n"); //$NON-NLS-1$
+ buffer.append("struct symbol **symbols;\n"); //$NON-NLS-1$
+ buffer.append("int errorcnt;\n};\n"); //$NON-NLS-1$
+ buffer.append("void f(lemp)\n"); //$NON-NLS-1$
+ buffer.append("struct lemon *lemp;\n{\n"); //$NON-NLS-1$
+ buffer.append("lemp->symbols[1]->lambda = 1;\n"); //$NON-NLS-1$
+ buffer.append("lemp->errorcnt++;}\n"); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
- IASTSimpleDeclaration symbol_decl = (IASTSimpleDeclaration)tu.getDeclarations()[0];
- IASTSimpleDeclaration lemon_decl = (IASTSimpleDeclaration)tu.getDeclarations()[1];
- IASTFunctionDefinition f_def = (IASTFunctionDefinition)tu.getDeclarations()[2];
+ IASTSimpleDeclaration symbol_decl = (IASTSimpleDeclaration) tu.getDeclarations()[0];
+ IASTSimpleDeclaration lemon_decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
+ IASTFunctionDefinition f_def = (IASTFunctionDefinition) tu.getDeclarations()[2];
- IASTName symbol_name1 = ((IASTCompositeTypeSpecifier)symbol_decl.getDeclSpecifier()).getName();
- IASTName lambda_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)symbol_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
- IASTName lemon_name1 = ((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getName();
- IASTName symbol_name2 = ((IASTElaboratedTypeSpecifier)((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclSpecifier()).getName();
- IASTName symbols_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
- IASTName errorcnt_name1 = ((IASTSimpleDeclaration)((IASTCompositeTypeSpecifier)lemon_decl.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
- IASTName lemp_name1 = ((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterNames()[0];
- IASTName lemon_name2 = ((IASTElaboratedTypeSpecifier)((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
- IASTName lemp_name2 = ((IASTSimpleDeclaration)((ICASTKnRFunctionDeclarator)f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
- IASTName lemp_name3 = ((IASTIdExpression)((IASTFieldReference)((IASTArraySubscriptExpression)((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldOwner()).getName();
- IASTName symbols_name2 = ((IASTFieldReference)((IASTArraySubscriptExpression)((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldName();
- IASTName lambda_name2 = ((IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldName();
+ IASTName symbol_name1 = ((IASTCompositeTypeSpecifier) symbol_decl.getDeclSpecifier()).getName();
+ IASTName lambda_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) symbol_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
+ IASTName lemon_name1 = ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getName();
+ IASTName symbol_name2 = ((IASTElaboratedTypeSpecifier) ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclSpecifier()).getName();
+ IASTName symbols_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[0]).getDeclarators()[0].getName();
+ IASTName errorcnt_name1 = ((IASTSimpleDeclaration) ((IASTCompositeTypeSpecifier) lemon_decl.getDeclSpecifier()).getMembers()[1]).getDeclarators()[0].getName();
+ IASTName lemp_name1 = ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterNames()[0];
+ IASTName lemon_name2 = ((IASTElaboratedTypeSpecifier) ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclSpecifier()).getName();
+ IASTName lemp_name2 = ((IASTSimpleDeclaration) ((ICASTKnRFunctionDeclarator) f_def.getDeclarator()).getParameterDeclarations()[0]).getDeclarators()[0].getName();
+ IASTName lemp_name3 = ((IASTIdExpression) ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldOwner()).getName();
+ IASTName symbols_name2 = ((IASTFieldReference) ((IASTArraySubscriptExpression) ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldOwner()).getArrayExpression()).getFieldName();
+ IASTName lambda_name2 = ((IASTFieldReference) ((IASTBinaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[0]).getExpression()).getOperand1()).getFieldName();
- IASTName lemp_name4 = ((IASTIdExpression)((IASTFieldReference)((IASTUnaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldOwner()).getName();
- IASTName errorcnt_name2 = ((IASTFieldReference)((IASTUnaryExpression)((IASTExpressionStatement)((IASTCompoundStatement)f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldName();
+ IASTName lemp_name4 = ((IASTIdExpression) ((IASTFieldReference) ((IASTUnaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldOwner()).getName();
+ IASTName errorcnt_name2 = ((IASTFieldReference) ((IASTUnaryExpression) ((IASTExpressionStatement) ((IASTCompoundStatement) f_def.getBody()).getStatements()[1]).getExpression()).getOperand()).getFieldName();
- assertEquals( symbol_name1.resolveBinding(), symbol_name2.resolveBinding() );
- assertEquals( lambda_name1.resolveBinding(), lambda_name2.resolveBinding() );
- assertEquals( lemon_name1.resolveBinding(), lemon_name2.resolveBinding() );
- assertEquals( symbols_name1.resolveBinding(), symbols_name2.resolveBinding() );
- assertEquals( errorcnt_name1.resolveBinding(), errorcnt_name2.resolveBinding() );
- assertEquals( lemp_name1.resolveBinding(), lemp_name2.resolveBinding() );
- assertEquals( lemp_name2.resolveBinding(), lemp_name3.resolveBinding() );
- assertEquals( lemp_name3.resolveBinding(), lemp_name4.resolveBinding() );
+ assertEquals(symbol_name1.resolveBinding(), symbol_name2.resolveBinding());
+ assertEquals(lambda_name1.resolveBinding(), lambda_name2.resolveBinding());
+ assertEquals(lemon_name1.resolveBinding(), lemon_name2.resolveBinding());
+ assertEquals(symbols_name1.resolveBinding(), symbols_name2.resolveBinding());
+ assertEquals(errorcnt_name1.resolveBinding(), errorcnt_name2.resolveBinding());
+ assertEquals(lemp_name1.resolveBinding(), lemp_name2.resolveBinding());
+ assertEquals(lemp_name2.resolveBinding(), lemp_name3.resolveBinding());
+ assertEquals(lemp_name3.resolveBinding(), lemp_name4.resolveBinding());
}
public void testBug97447() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("void f( a ) int a; {} \n"); //$NON-NLS-1$
- buffer.append("void f( int ); \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("void f(a) int a; {} \n"); //$NON-NLS-1$
+ buffer.append("void f(int); \n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true);
CNameCollector col = new CNameCollector();
@@ -619,38 +617,38 @@ public class AST2KnRTests extends AST2BaseTest {
}
public void testBug100104() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef int ush;\n"); //$NON-NLS-1$
buffer.append("int f()\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("int a=1;\n"); //$NON-NLS-1$
- buffer.append("((ush)(a)*(ush)(a) * a);\n"); //$NON-NLS-1$
+ buffer.append("((ush) (a)*(ush) (a) * a);\n"); //$NON-NLS-1$
buffer.append("{\n"); //$NON-NLS-1$
buffer.append("};\n"); //$NON-NLS-1$
buffer.append("}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
- assertTrue( tu.getDeclarations()[0] instanceof IASTSimpleDeclaration );
- assertTrue( tu.getDeclarations()[1] instanceof IASTFunctionDefinition );
- IASTStatement[] stmts = ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements();
- assertTrue( stmts[0] instanceof IASTDeclarationStatement );
- assertTrue( stmts[1] instanceof IASTExpressionStatement );
- assertTrue( stmts[2] instanceof IASTCompoundStatement );
- assertTrue( stmts[3] instanceof IASTNullStatement );
+ assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
+ assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
+ IASTStatement[] stmts = ((IASTCompoundStatement) ((IASTFunctionDefinition) tu.getDeclarations()[1]).getBody()).getStatements();
+ assertTrue(stmts[0] instanceof IASTDeclarationStatement);
+ assertTrue(stmts[1] instanceof IASTExpressionStatement);
+ assertTrue(stmts[2] instanceof IASTCompoundStatement);
+ assertTrue(stmts[3] instanceof IASTNullStatement);
}
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=203050
public void testBug203050() throws Exception {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("typedef long time_t;\n" + //$NON-NLS-1$
"\n" + //$NON-NLS-1$
- "void (foo)(timep)\n" + //$NON-NLS-1$
+ "void (foo) (timep)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
" struct tm tmp;\n" + //$NON-NLS-1$
" bar(timep, &tmp);\n" + //$NON-NLS-1$
"}\n" + //$NON-NLS-1$
- "int (bar)(timep, tmp)\n" + //$NON-NLS-1$
+ "int (bar) (timep, tmp)\n" + //$NON-NLS-1$
" const time_t * const timep;\n" + //$NON-NLS-1$
" struct tm * tmp;\n" + //$NON-NLS-1$
"{\n" + //$NON-NLS-1$
@@ -658,23 +656,22 @@ public class AST2KnRTests extends AST2BaseTest {
"}\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
- assertTrue( tu.getDeclarations()[0] instanceof IASTSimpleDeclaration );
- assertTrue( tu.getDeclarations()[1] instanceof IASTFunctionDefinition );
- assertTrue( tu.getDeclarations()[2] instanceof IASTFunctionDefinition );
- IASTStatement[] stmts = ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements();
- assertTrue( stmts[0] instanceof IASTDeclarationStatement );
- assertTrue( stmts[1] instanceof IASTExpressionStatement );
- IASTExpression expr= ((IASTExpressionStatement)stmts[1]).getExpression();
+ assertTrue(tu.getDeclarations()[0] instanceof IASTSimpleDeclaration);
+ assertTrue(tu.getDeclarations()[1] instanceof IASTFunctionDefinition);
+ assertTrue(tu.getDeclarations()[2] instanceof IASTFunctionDefinition);
+ IASTStatement[] stmts = ((IASTCompoundStatement) ((IASTFunctionDefinition) tu.getDeclarations()[1]).getBody()).getStatements();
+ assertTrue(stmts[0] instanceof IASTDeclarationStatement);
+ assertTrue(stmts[1] instanceof IASTExpressionStatement);
+ IASTExpression expr= ((IASTExpressionStatement) stmts[1]).getExpression();
assertTrue(expr instanceof IASTFunctionCallExpression);
- IASTIdExpression fnameExpr= (IASTIdExpression)((IASTFunctionCallExpression)expr).getFunctionNameExpression();
+ IASTIdExpression fnameExpr= (IASTIdExpression) ((IASTFunctionCallExpression) expr).getFunctionNameExpression();
fnameExpr.getName().resolveBinding();
- IASTName fname= ((IASTFunctionDefinition)tu.getDeclarations()[2]).getDeclarator().getName();
+ IASTName fname= ((IASTFunctionDefinition) tu.getDeclarations()[2]).getDeclarator().getName();
try {
fname.resolveBinding();
} catch (StackOverflowError e) {
fail(e.getMessage());
}
}
-
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
index 46ee3cb7b64..a8ef3b40f40 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/GCCTests.java
@@ -39,795 +39,795 @@ public class GCCTests extends AST2BaseTest {
}
public void testGCC20000113() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct x { \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x1:1; \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x2:2; \n" ); //$NON-NLS-1$
- buffer.append( " unsigned x3:3; \n" ); //$NON-NLS-1$
- buffer.append( "}; \n" ); //$NON-NLS-1$
- buffer.append( "foobar( int x, int y, int z ){ \n" ); //$NON-NLS-1$
- buffer.append( " struct x a = {x, y, z}; \n" ); //$NON-NLS-1$
- buffer.append( " struct x b = {x, y, z}; \n" ); //$NON-NLS-1$
- buffer.append( " struct x *c = &b; \n" ); //$NON-NLS-1$
- buffer.append( " c->x3 += ( a.x2 - a.x1) * c->x2; \n" ); //$NON-NLS-1$
- buffer.append( " if( a.x1 != 1 || c->x3 != 5 ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct x { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x1:1; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x2:2; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned x3:3; \n"); //$NON-NLS-1$
+ buffer.append("}; \n"); //$NON-NLS-1$
+ buffer.append("foobar(int x, int y, int z) { \n"); //$NON-NLS-1$
+ buffer.append(" struct x a = {x, y, z}; \n"); //$NON-NLS-1$
+ buffer.append(" struct x b = {x, y, z}; \n"); //$NON-NLS-1$
+ buffer.append(" struct x *c = &b; \n"); //$NON-NLS-1$
+ buffer.append(" c->x3 += (a.x2 - a.x1) * c->x2; \n"); //$NON-NLS-1$
+ buffer.append(" if (a.x1 != 1 || c->x3 != 5) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 33 );
- ICompositeType x = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField x1 = (IField) collector.getName( 1 ).resolveBinding();
- IField x2 = (IField) collector.getName( 2 ).resolveBinding();
- IField x3 = (IField) collector.getName( 3 ).resolveBinding();
- IVariable vx = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable vy = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable vz = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 14 ).resolveBinding();
- IVariable c = (IVariable) collector.getName( 19 ).resolveBinding();
+ assertEquals(collector.size(), 33);
+ ICompositeType x = (ICompositeType) collector.getName(0).resolveBinding();
+ IField x1 = (IField) collector.getName(1).resolveBinding();
+ IField x2 = (IField) collector.getName(2).resolveBinding();
+ IField x3 = (IField) collector.getName(3).resolveBinding();
+ IVariable vx = (IVariable) collector.getName(5).resolveBinding();
+ IVariable vy = (IVariable) collector.getName(6).resolveBinding();
+ IVariable vz = (IVariable) collector.getName(7).resolveBinding();
+ IVariable a = (IVariable) collector.getName(9).resolveBinding();
+ IVariable b = (IVariable) collector.getName(14).resolveBinding();
+ IVariable c = (IVariable) collector.getName(19).resolveBinding();
- assertInstances( collector, x, 4 );
- assertInstances( collector, x1, 3);
- assertInstances( collector, x2, 3);
- assertInstances( collector, x3, 3);
- assertInstances( collector, vx, 3);
- assertInstances( collector, vy, 3);
- assertInstances( collector, vz, 3);
- assertInstances( collector, a, 4);
- assertInstances( collector, b, 2);
- assertInstances( collector, c, 4);
+ assertInstances(collector, x, 4);
+ assertInstances(collector, x1, 3);
+ assertInstances(collector, x2, 3);
+ assertInstances(collector, x3, 3);
+ assertInstances(collector, vx, 3);
+ assertInstances(collector, vy, 3);
+ assertInstances(collector, vz, 3);
+ assertInstances(collector, a, 4);
+ assertInstances(collector, b, 2);
+ assertInstances(collector, c, 4);
}
public void testGCC20000205() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "static int f( int a ) { \n"); //$NON-NLS-1$
- buffer.append( " if( a == 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( " do \n"); //$NON-NLS-1$
- buffer.append( " if( a & 128 ) \n"); //$NON-NLS-1$
- buffer.append( " return 1; \n"); //$NON-NLS-1$
- buffer.append( " while( f(0) ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("static int f(int a) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a == 0) \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append(" do \n"); //$NON-NLS-1$
+ buffer.append(" if (a & 128) \n"); //$NON-NLS-1$
+ buffer.append(" return 1; \n"); //$NON-NLS-1$
+ buffer.append(" while (f(0)); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 5 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 5);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IVariable a = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, f, 2 );
- assertInstances( collector, a, 3 );
+ assertInstances(collector, f, 2);
+ assertInstances(collector, a, 3);
}
public void testGCC20000217() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "unsigned short int showbug( unsigned short int * a, \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int * b ) { \n"); //$NON-NLS-1$
- buffer.append( " *a += *b - 8; \n"); //$NON-NLS-1$
- buffer.append( " return (*a >= 8 ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main(){ \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int x = 0; \n"); //$NON-NLS-1$
- buffer.append( " unsigned short int y = 10; \n"); //$NON-NLS-1$
- buffer.append( " if( showbug( &x, &y ) != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned short int showbug(unsigned short int * a, \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int * b) { \n"); //$NON-NLS-1$
+ buffer.append(" *a += *b - 8; \n"); //$NON-NLS-1$
+ buffer.append(" return (*a >= 8); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int x = 0; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned short int y = 10; \n"); //$NON-NLS-1$
+ buffer.append(" if (showbug(&x, &y) != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 12 );
+ assertEquals(collector.size(), 12);
- IFunction showBug = (IFunction) collector.getName( 0 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable y = (IVariable) collector.getName( 8 ).resolveBinding();
+ IFunction showBug = (IFunction) collector.getName(0).resolveBinding();
+ IVariable a = (IVariable) collector.getName(1).resolveBinding();
+ IVariable b = (IVariable) collector.getName(2).resolveBinding();
+ IVariable x = (IVariable) collector.getName(7).resolveBinding();
+ IVariable y = (IVariable) collector.getName(8).resolveBinding();
- assertInstances( collector, showBug, 2 );
- assertInstances( collector, a, 3 );
- assertInstances( collector, b, 2 );
- assertInstances( collector, x, 2 );
- assertInstances( collector, y, 2 );
+ assertInstances(collector, showBug, 2);
+ assertInstances(collector, a, 3);
+ assertInstances(collector, b, 2);
+ assertInstances(collector, x, 2);
+ assertInstances(collector, y, 2);
}
public void testGCC20000224() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int loop_1 = 100; \n"); //$NON-NLS-1$
- buffer.append( "int loop_2 = 7; \n"); //$NON-NLS-1$
- buffer.append( "int flag = 0; \n"); //$NON-NLS-1$
- buffer.append( "int test( void ) { \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " int counter = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( loop_1 > counter ) { \n"); //$NON-NLS-1$
- buffer.append( " if( flag & 1 ) { \n"); //$NON-NLS-1$
- buffer.append( " for( i = 0; i < loop_2; i++ ) { \n"); //$NON-NLS-1$
- buffer.append( " counter++; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " flag++; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " return 1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int loop_1 = 100; \n"); //$NON-NLS-1$
+ buffer.append("int loop_2 = 7; \n"); //$NON-NLS-1$
+ buffer.append("int flag = 0; \n"); //$NON-NLS-1$
+ buffer.append("int test(void) { \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" int counter = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (loop_1 > counter) { \n"); //$NON-NLS-1$
+ buffer.append(" if (flag & 1) { \n"); //$NON-NLS-1$
+ buffer.append(" for (i = 0; i < loop_2; i++) { \n"); //$NON-NLS-1$
+ buffer.append(" counter++; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" flag++; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" return 1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 16 );
- IVariable loop1 = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable loop2 = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable flag = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable counter = (IVariable) collector.getName( 6 ).resolveBinding();
+ assertEquals(collector.size(), 16);
+ IVariable loop1 = (IVariable) collector.getName(0).resolveBinding();
+ IVariable loop2 = (IVariable) collector.getName(1).resolveBinding();
+ IVariable flag = (IVariable) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(5).resolveBinding();
+ IVariable counter = (IVariable) collector.getName(6).resolveBinding();
- assertInstances( collector, loop1, 2 );
- assertInstances( collector, loop2, 2 );
- assertInstances( collector, flag, 3 );
- assertInstances( collector, i, 4 );
- assertInstances( collector, counter, 3 );
+ assertInstances(collector, loop1, 2);
+ assertInstances(collector, loop2, 2);
+ assertInstances(collector, flag, 3);
+ assertInstances(collector, i, 4);
+ assertInstances(collector, counter, 3);
}
public void testGCC20000225() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int nResult, b = 0, i = -1; \n"); //$NON-NLS-1$
- buffer.append( " do { \n"); //$NON-NLS-1$
- buffer.append( " if( b != 0 ) { \n"); //$NON-NLS-1$
- buffer.append( " nResult = 1; \n"); //$NON-NLS-1$
- buffer.append( " } else { \n"); //$NON-NLS-1$
- buffer.append( " nResult = 0; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " i++; \n"); //$NON-NLS-1$
- buffer.append( " b = ( i + 2 ) * 4; \n"); //$NON-NLS-1$
- buffer.append( " } while ( i < 0 ); \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int nResult, b = 0, i = -1; \n"); //$NON-NLS-1$
+ buffer.append(" do { \n"); //$NON-NLS-1$
+ buffer.append(" if (b != 0) { \n"); //$NON-NLS-1$
+ buffer.append(" nResult = 1; \n"); //$NON-NLS-1$
+ buffer.append(" } else { \n"); //$NON-NLS-1$
+ buffer.append(" nResult = 0; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" i++; \n"); //$NON-NLS-1$
+ buffer.append(" b = (i + 2) * 4; \n"); //$NON-NLS-1$
+ buffer.append(" } while (i < 0); \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IVariable nResult = (IVariable) collector.getName( 1 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 3 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IVariable nResult = (IVariable) collector.getName(1).resolveBinding();
+ IVariable b = (IVariable) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(3).resolveBinding();
- assertInstances( collector, nResult, 3 );
- assertInstances( collector, b, 3 );
- assertInstances( collector, i, 4 );
+ assertInstances(collector, nResult, 3);
+ assertInstances(collector, b, 3);
+ assertInstances(collector, i, 4);
}
public void testGCC20000227() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "static const unsigned char f[] = \"\\0\\377\"; \n"); //$NON-NLS-1$
- buffer.append( "static const unsigned char g[] = \"\\0y\"; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " if( sizeof f != 3 || sizeof g != 3 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( f[0] != g[0] ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( f[1] != g[1] || f[2] != g[2] ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("static const unsigned char f[] = \"\\0\\377\"; \n"); //$NON-NLS-1$
+ buffer.append("static const unsigned char g[] = \"\\0y\"; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (sizeof f != 3 || sizeof g != 3) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (f[0] != g[0]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (f[1] != g[1] || f[2] != g[2]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IVariable f = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable g = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IVariable f = (IVariable) collector.getName(0).resolveBinding();
+ IVariable g = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, f, 5 );
- assertInstances( collector, g, 5 );
+ assertInstances(collector, f, 5);
+ assertInstances(collector, g, 5);
}
public void testGCC20000313() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "unsigned int buggy( unsigned int *param ) { \n"); //$NON-NLS-1$
- buffer.append( " unsigned int accu, zero = 0, borrow; \n"); //$NON-NLS-1$
- buffer.append( " accu = - *param; \n"); //$NON-NLS-1$
- buffer.append( " borrow = - ( accu > zero ); \n"); //$NON-NLS-1$
- buffer.append( " return borrow; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main(void){ \n"); //$NON-NLS-1$
- buffer.append( " unsigned int param = 1; \n"); //$NON-NLS-1$
- buffer.append( " unsigned int borrow = buggy (¶m); \n"); //$NON-NLS-1$
- buffer.append( " if( param != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " if( borrow +1 != 0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned int buggy(unsigned int *param) { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int accu, zero = 0, borrow; \n"); //$NON-NLS-1$
+ buffer.append(" accu = - *param; \n"); //$NON-NLS-1$
+ buffer.append(" borrow = - (accu > zero); \n"); //$NON-NLS-1$
+ buffer.append(" return borrow; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main(void) { \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int param = 1; \n"); //$NON-NLS-1$
+ buffer.append(" unsigned int borrow = buggy (¶m); \n"); //$NON-NLS-1$
+ buffer.append(" if (param != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" if (borrow +1 != 0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 19 );
+ assertEquals(collector.size(), 19);
IFunction buggy = (IFunction) collector.getName(0).resolveBinding();
IParameter param = (IParameter) collector.getName(1).resolveBinding();
- IVariable accu = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable zero = (IVariable) collector.getName( 3 ).resolveBinding();
- IVariable borrow = (IVariable) collector.getName( 4 ).resolveBinding();
- IVariable param2 = (IVariable) collector.getName( 13 ).resolveBinding();
- IVariable borrow2 = (IVariable) collector.getName( 14 ).resolveBinding();
+ IVariable accu = (IVariable) collector.getName(2).resolveBinding();
+ IVariable zero = (IVariable) collector.getName(3).resolveBinding();
+ IVariable borrow = (IVariable) collector.getName(4).resolveBinding();
+ IVariable param2 = (IVariable) collector.getName(13).resolveBinding();
+ IVariable borrow2 = (IVariable) collector.getName(14).resolveBinding();
- assertInstances( collector, buggy, 2 );
- assertInstances( collector, param, 2 );
- assertInstances( collector, accu, 3 );
- assertInstances( collector, zero, 2 );
- assertInstances( collector, borrow, 3 );
- assertInstances( collector, param2, 3 );
- assertInstances( collector, borrow2, 2 );
+ assertInstances(collector, buggy, 2);
+ assertInstances(collector, param, 2);
+ assertInstances(collector, accu, 3);
+ assertInstances(collector, zero, 2);
+ assertInstances(collector, borrow, 3);
+ assertInstances(collector, param2, 3);
+ assertInstances(collector, borrow2, 2);
}
public void testGCC20000314_1() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " long winds = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( winds != 0 ) { \n"); //$NON-NLS-1$
- buffer.append( " if( *(char*)winds ) \n"); //$NON-NLS-1$
- buffer.append( " break; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " if( winds == 0 || winds != 0 || *(char*)winds ) \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" long winds = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (winds != 0) { \n"); //$NON-NLS-1$
+ buffer.append(" if (*(char*)winds) \n"); //$NON-NLS-1$
+ buffer.append(" break; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" if (winds == 0 || winds != 0 || *(char*) winds) \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 7 );
- IVariable winds = (IVariable) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 7);
+ IVariable winds = (IVariable) collector.getName(1).resolveBinding();
- assertInstances( collector, winds, 6 );
+ assertInstances(collector, winds, 6);
}
public void testGCC20000314_2() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef unsigned long long uint64; \n" ); //$NON-NLS-1$
- buffer.append( "const uint64 bigconst = 1ULL << 34; \n" ); //$NON-NLS-1$
- buffer.append( "int a = 1; \n" ); //$NON-NLS-1$
- buffer.append( "static uint64 getmask(void) { \n" ); //$NON-NLS-1$
- buffer.append( " if(a) return bigconst; \n" ); //$NON-NLS-1$
- buffer.append( " else return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
- buffer.append( "main(){ \n" ); //$NON-NLS-1$
- buffer.append( " uint64 f = getmask(); \n" ); //$NON-NLS-1$
- buffer.append( " if( sizeof (long long) == 8 && f != bigconst ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef unsigned long long uint64; \n"); //$NON-NLS-1$
+ buffer.append("const uint64 bigconst = 1ULL << 34; \n"); //$NON-NLS-1$
+ buffer.append("int a = 1; \n"); //$NON-NLS-1$
+ buffer.append("static uint64 getmask(void) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a) return bigconst; \n"); //$NON-NLS-1$
+ buffer.append(" else return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" uint64 f = getmask(); \n"); //$NON-NLS-1$
+ buffer.append(" if (sizeof (long long) == 8 && f != bigconst) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 15 );
- ITypedef uint64 = (ITypedef) collector.getName( 0 ).resolveBinding();
- IVariable bigconst = (IVariable) collector.getName( 2 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 3 ).resolveBinding();
- IFunction getmask = (IFunction) collector.getName( 5 ).resolveBinding();
- IVariable f = (IVariable) collector.getName( 11 ).resolveBinding();
+ assertEquals(collector.size(), 15);
+ ITypedef uint64 = (ITypedef) collector.getName(0).resolveBinding();
+ IVariable bigconst = (IVariable) collector.getName(2).resolveBinding();
+ IVariable a = (IVariable) collector.getName(3).resolveBinding();
+ IFunction getmask = (IFunction) collector.getName(5).resolveBinding();
+ IVariable f = (IVariable) collector.getName(11).resolveBinding();
- assertInstances( collector, uint64, 4 );
- assertInstances( collector, bigconst, 3 );
- assertInstances( collector, a, 2 );
- assertInstances( collector, getmask, 2 );
- assertInstances( collector, f, 2 );
+ assertInstances(collector, uint64, 4);
+ assertInstances(collector, bigconst, 3);
+ assertInstances(collector, a, 2);
+ assertInstances(collector, getmask, 2);
+ assertInstances(collector, f, 2);
}
public void testGCC20000403() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "extern unsigned long aa[], bb[]; \n"); //$NON-NLS-1$
- buffer.append( "int seqgt( unsigned long a, unsigned short win, unsigned long b ); \n"); //$NON-NLS-1$
- buffer.append( "int seqgt2 ( unsigned long a, unsigned short win, unsigned long b ); \n"); //$NON-NLS-1$
- buffer.append( "main() { \n"); //$NON-NLS-1$
- buffer.append( " if( !seqgt( *aa, 0x1000, *bb) || !seqgt2( *aa, 0x1000, *bb) ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int seqgt( unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
- buffer.append( " return (long) ((a + win) - b) > 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int seqgt2( unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
- buffer.append( " long l = ((a + win) - b); \n"); //$NON-NLS-1$
- buffer.append( " return 1 > 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "unsigned long aa[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
- buffer.append( "unsigned long bb[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("extern unsigned long aa[], bb[]; \n"); //$NON-NLS-1$
+ buffer.append("int seqgt(unsigned long a, unsigned short win, unsigned long b); \n"); //$NON-NLS-1$
+ buffer.append("int seqgt2 (unsigned long a, unsigned short win, unsigned long b); \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (!seqgt(*aa, 0x1000, *bb) || !seqgt2(*aa, 0x1000, *bb)) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int seqgt(unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
+ buffer.append(" return (long) ((a + win) - b) > 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int seqgt2(unsigned long a, unsigned short win, unsigned long b) { \n"); //$NON-NLS-1$
+ buffer.append(" long l = ((a + win) - b); \n"); //$NON-NLS-1$
+ buffer.append(" return 1 > 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("unsigned long aa[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
+ buffer.append("unsigned long bb[] = { (1UL << (sizeof(long) *8 - 1)) = 0xfff }; \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 34 );
- IVariable aa = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable bb = (IVariable) collector.getName( 1 ).resolveBinding();
- IFunction seqgt = (IFunction) collector.getName( 2 ).resolveBinding();
- IParameter a1 = (IParameter) collector.getName( 3 ).resolveBinding();
- IParameter win1 = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter b1 = (IParameter) collector.getName( 5 ).resolveBinding();
- IFunction seqgt2 = (IFunction) collector.getName( 6 ).resolveBinding();
- IParameter a2 = (IParameter) collector.getName( 7 ).resolveBinding();
- IParameter win2 = (IParameter) collector.getName( 8 ).resolveBinding();
- IParameter b2 = (IParameter) collector.getName( 9 ).resolveBinding();
+ assertEquals(collector.size(), 34);
+ IVariable aa = (IVariable) collector.getName(0).resolveBinding();
+ IVariable bb = (IVariable) collector.getName(1).resolveBinding();
+ IFunction seqgt = (IFunction) collector.getName(2).resolveBinding();
+ IParameter a1 = (IParameter) collector.getName(3).resolveBinding();
+ IParameter win1 = (IParameter) collector.getName(4).resolveBinding();
+ IParameter b1 = (IParameter) collector.getName(5).resolveBinding();
+ IFunction seqgt2 = (IFunction) collector.getName(6).resolveBinding();
+ IParameter a2 = (IParameter) collector.getName(7).resolveBinding();
+ IParameter win2 = (IParameter) collector.getName(8).resolveBinding();
+ IParameter b2 = (IParameter) collector.getName(9).resolveBinding();
- assertInstances( collector, aa, 4 );
- assertInstances( collector, bb, 4 );
- assertInstances( collector, seqgt, 3 );
- assertInstances( collector, a1, 3 );
- assertInstances( collector, win1, 3 );
- assertInstances( collector, b1, 3 );
- assertInstances( collector, seqgt2, 3 );
- assertInstances( collector, a2, 3 );
- assertInstances( collector, win2, 3 );
- assertInstances( collector, b2, 3 );
+ assertInstances(collector, aa, 4);
+ assertInstances(collector, bb, 4);
+ assertInstances(collector, seqgt, 3);
+ assertInstances(collector, a1, 3);
+ assertInstances(collector, win1, 3);
+ assertInstances(collector, b1, 3);
+ assertInstances(collector, seqgt2, 3);
+ assertInstances(collector, a2, 3);
+ assertInstances(collector, win2, 3);
+ assertInstances(collector, b2, 3);
}
public void testGCC20000412_1 () throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "short int i = -1; \n" ); //$NON-NLS-1$
- buffer.append( "const char * const wordlist[207]; \n" ); //$NON-NLS-1$
- buffer.append( "const char * const * foo( void ) { \n" ); //$NON-NLS-1$
- buffer.append( " register const char * const *wordptr = &wordlist[207u + i]; \n" ); //$NON-NLS-1$
- buffer.append( " return wordptr; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
- buffer.append( "int main() { \n" ); //$NON-NLS-1$
- buffer.append( " if( foo() != &wordlist[206] ) \n" ); //$NON-NLS-1$
- buffer.append( " return -1; \n" ); //$NON-NLS-1$
- buffer.append( " return 0; \n" ); //$NON-NLS-1$
- buffer.append( "} \n" ); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("short int i = -1; \n"); //$NON-NLS-1$
+ buffer.append("const char * const wordlist[207]; \n"); //$NON-NLS-1$
+ buffer.append("const char * const * foo(void) { \n"); //$NON-NLS-1$
+ buffer.append(" register const char * const *wordptr = &wordlist[207u + i]; \n"); //$NON-NLS-1$
+ buffer.append(" return wordptr; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" if (foo() != &wordlist[206]) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IVariable i = (IVariable) collector.getName( 0 ).resolveBinding();
- IVariable wordlist = (IVariable) collector.getName( 1 ).resolveBinding();
- IFunction foo = (IFunction) collector.getName( 2 ).resolveBinding();
- IVariable wordptr = (IVariable) collector.getName( 4 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IVariable i = (IVariable) collector.getName(0).resolveBinding();
+ IVariable wordlist = (IVariable) collector.getName(1).resolveBinding();
+ IFunction foo = (IFunction) collector.getName(2).resolveBinding();
+ IVariable wordptr = (IVariable) collector.getName(4).resolveBinding();
- assertInstances( collector, i, 2 );
- assertInstances( collector, wordlist, 3 );
- assertInstances( collector, foo, 2 );
- assertInstances( collector, wordptr, 2 );
+ assertInstances(collector, i, 2);
+ assertInstances(collector, wordlist, 3);
+ assertInstances(collector, foo, 2);
+ assertInstances(collector, wordptr, 2);
}
public void testGCC20000412_2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int f( int a, int *y ) { \n"); //$NON-NLS-1$
- buffer.append( " int x = a; \n"); //$NON-NLS-1$
- buffer.append( " if( a == 0 ) return *y; \n"); //$NON-NLS-1$
- buffer.append( " return f( a-1, &x ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main( int argc, char** argv){ \n"); //$NON-NLS-1$
- buffer.append( " if( f(100, (int *) 0 ) != 1) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(int a, int *y) { \n"); //$NON-NLS-1$
+ buffer.append(" int x = a; \n"); //$NON-NLS-1$
+ buffer.append(" if (a == 0) return *y; \n"); //$NON-NLS-1$
+ buffer.append(" return f(a-1, &x); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main(int argc, char** argv) { \n"); //$NON-NLS-1$
+ buffer.append(" if (f(100, (int *) 0) != 1) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 14 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter a = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter y = (IParameter) collector.getName( 2 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 3 ).resolveBinding();
+ assertEquals(collector.size(), 14);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter a = (IParameter) collector.getName(1).resolveBinding();
+ IParameter y = (IParameter) collector.getName(2).resolveBinding();
+ IVariable x = (IVariable) collector.getName(3).resolveBinding();
- assertInstances( collector, f, 3 );
- assertInstances( collector, a, 4 );
- assertInstances( collector, y, 2 );
- assertInstances( collector, x, 2 );
+ assertInstances(collector, f, 3);
+ assertInstances(collector, a, 4);
+ assertInstances(collector, y, 2);
+ assertInstances(collector, x, 2);
}
public void testGCC20000412_3() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "typedef struct { \n"); //$NON-NLS-1$
- buffer.append( " char y; \n"); //$NON-NLS-1$
- buffer.append( " char x[32]; \n"); //$NON-NLS-1$
- buffer.append( "} X; \n"); //$NON-NLS-1$
- buffer.append( "int z(void) { \n"); //$NON-NLS-1$
- buffer.append( " X xxx; \n"); //$NON-NLS-1$
- buffer.append( " xxx.x[0] = xxx.x[31] = '0'; \n"); //$NON-NLS-1$
- buffer.append( " xxx.y = 0xf; \n"); //$NON-NLS-1$
- buffer.append( " return f( xxx, xxx ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main (void) { \n"); //$NON-NLS-1$
- buffer.append( " int val; \n"); //$NON-NLS-1$
- buffer.append( " val = z(); \n"); //$NON-NLS-1$
- buffer.append( " if( val != 0x60 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int f( X x, X y ) { \n"); //$NON-NLS-1$
- buffer.append( " if( x.y != y.y ) \n"); //$NON-NLS-1$
- buffer.append( " return 'F'; \n"); //$NON-NLS-1$
- buffer.append( " return x.x[0] + y.x[0]; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("typedef struct { \n"); //$NON-NLS-1$
+ buffer.append(" char y; \n"); //$NON-NLS-1$
+ buffer.append(" char x[32]; \n"); //$NON-NLS-1$
+ buffer.append("} X; \n"); //$NON-NLS-1$
+ buffer.append("int z(void) { \n"); //$NON-NLS-1$
+ buffer.append(" X xxx; \n"); //$NON-NLS-1$
+ buffer.append(" xxx.x[0] = xxx.x[31] = '0'; \n"); //$NON-NLS-1$
+ buffer.append(" xxx.y = 0xf; \n"); //$NON-NLS-1$
+ buffer.append(" return f(xxx, xxx); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main (void) { \n"); //$NON-NLS-1$
+ buffer.append(" int val; \n"); //$NON-NLS-1$
+ buffer.append(" val = z(); \n"); //$NON-NLS-1$
+ buffer.append(" if (val != 0x60) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int f(X x, X y) { \n"); //$NON-NLS-1$
+ buffer.append(" if (x.y != y.y) \n"); //$NON-NLS-1$
+ buffer.append(" return 'F'; \n"); //$NON-NLS-1$
+ buffer.append(" return x.x[0] + y.x[0]; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 36 );
- IField y = (IField) collector.getName( 1 ).resolveBinding();
- IField x = (IField) collector.getName( 2 ).resolveBinding();
- ITypedef X = (ITypedef) collector.getName( 3 ).resolveBinding();
- IFunction z = (IFunction) collector.getName( 4 ).resolveBinding();
- IVariable xxx = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable val = (IVariable) collector.getName( 19 ).resolveBinding();
- IParameter px = (IParameter) collector.getName( 25 ).resolveBinding();
- IParameter py = (IParameter) collector.getName( 27 ).resolveBinding();
+ assertEquals(collector.size(), 36);
+ IField y = (IField) collector.getName(1).resolveBinding();
+ IField x = (IField) collector.getName(2).resolveBinding();
+ ITypedef X = (ITypedef) collector.getName(3).resolveBinding();
+ IFunction z = (IFunction) collector.getName(4).resolveBinding();
+ IVariable xxx = (IVariable) collector.getName(7).resolveBinding();
+ IVariable val = (IVariable) collector.getName(19).resolveBinding();
+ IParameter px = (IParameter) collector.getName(25).resolveBinding();
+ IParameter py = (IParameter) collector.getName(27).resolveBinding();
- assertInstances( collector, y, 4 );
- assertInstances( collector, x, 5 );
- assertInstances( collector, X, 4 );
- assertInstances( collector, z, 2 );
- assertInstances( collector, xxx, 6 );
- assertInstances( collector, val, 3 );
- assertInstances( collector, px, 3 );
- assertInstances( collector, py, 3 );
+ assertInstances(collector, y, 4);
+ assertInstances(collector, x, 5);
+ assertInstances(collector, X, 4);
+ assertInstances(collector, z, 2);
+ assertInstances(collector, xxx, 6);
+ assertInstances(collector, val, 3);
+ assertInstances(collector, px, 3);
+ assertInstances(collector, py, 3);
}
public void testGCC20000412_4() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "void f(int i, int j, int radius, int width, int N) { \n"); //$NON-NLS-1$
- buffer.append( " const int diff = i - radius; \n"); //$NON-NLS-1$
- buffer.append( " const int lowk = (diff > 0 ? diff : 0 ); \n"); //$NON-NLS-1$
- buffer.append( " int k; \n"); //$NON-NLS-1$
- buffer.append( " for( k = lowk; k <= 2; k++ ){ \n"); //$NON-NLS-1$
- buffer.append( " int idx = ((k-i+radius) * width - j + radius); \n"); //$NON-NLS-1$
- buffer.append( " if( idx < 0 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " for( k = lowk; k <= 2; k++ ) ; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main (int argc, char** argv ){ \n"); //$NON-NLS-1$
- buffer.append( " int exc_rad = 2; \n"); //$NON-NLS-1$
- buffer.append( " int N = 8; \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " for( i = 1; i < 4; i++ ) \n"); //$NON-NLS-1$
- buffer.append( " f( i, 1, exc_rad, 2*exc_rad + 1, N ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("void f(int i, int j, int radius, int width, int N) { \n"); //$NON-NLS-1$
+ buffer.append(" const int diff = i - radius; \n"); //$NON-NLS-1$
+ buffer.append(" const int lowk = (diff > 0 ? diff : 0); \n"); //$NON-NLS-1$
+ buffer.append(" int k; \n"); //$NON-NLS-1$
+ buffer.append(" for (k = lowk; k <= 2; k++) { \n"); //$NON-NLS-1$
+ buffer.append(" int idx = ((k-i+radius) * width - j + radius); \n"); //$NON-NLS-1$
+ buffer.append(" if (idx < 0) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" for (k = lowk; k <= 2; k++) ; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main (int argc, char** argv) { \n"); //$NON-NLS-1$
+ buffer.append(" int exc_rad = 2; \n"); //$NON-NLS-1$
+ buffer.append(" int N = 8; \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" for (i = 1; i < 4; i++) \n"); //$NON-NLS-1$
+ buffer.append(" f(i, 1, exc_rad, 2*exc_rad + 1, N); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 43 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter i1 = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter j = (IParameter) collector.getName( 2 ).resolveBinding();
- IParameter radius = (IParameter) collector.getName( 3 ).resolveBinding();
- IParameter width = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter N1 = (IParameter) collector.getName( 5 ).resolveBinding();
- IVariable diff = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable lowk = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable k = (IVariable) collector.getName( 12 ).resolveBinding();
- IVariable idx = (IVariable) collector.getName( 17 ).resolveBinding();
- IVariable exc_rad = (IVariable) collector.getName( 32 ).resolveBinding();
- IVariable N2 = (IVariable) collector.getName( 33 ).resolveBinding();
- IVariable i2 = (IVariable) collector.getName( 34 ).resolveBinding();
+ assertEquals(collector.size(), 43);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter i1 = (IParameter) collector.getName(1).resolveBinding();
+ IParameter j = (IParameter) collector.getName(2).resolveBinding();
+ IParameter radius = (IParameter) collector.getName(3).resolveBinding();
+ IParameter width = (IParameter) collector.getName(4).resolveBinding();
+ IParameter N1 = (IParameter) collector.getName(5).resolveBinding();
+ IVariable diff = (IVariable) collector.getName(6).resolveBinding();
+ IVariable lowk = (IVariable) collector.getName(9).resolveBinding();
+ IVariable k = (IVariable) collector.getName(12).resolveBinding();
+ IVariable idx = (IVariable) collector.getName(17).resolveBinding();
+ IVariable exc_rad = (IVariable) collector.getName(32).resolveBinding();
+ IVariable N2 = (IVariable) collector.getName(33).resolveBinding();
+ IVariable i2 = (IVariable) collector.getName(34).resolveBinding();
- assertInstances( collector, f, 2 );
- assertInstances( collector, i1, 3 );
- assertInstances( collector, j, 2 );
- assertInstances( collector, radius, 4 );
- assertInstances( collector, width, 2 );
- assertInstances( collector, N1, 1 );
- assertInstances( collector, diff, 3 );
- assertInstances( collector, lowk, 3 );
- assertInstances( collector, k, 8 );
- assertInstances( collector, idx, 2 );
- assertInstances( collector, exc_rad, 3 );
- assertInstances( collector, N2, 2 );
- assertInstances( collector, i2, 5 );
+ assertInstances(collector, f, 2);
+ assertInstances(collector, i1, 3);
+ assertInstances(collector, j, 2);
+ assertInstances(collector, radius, 4);
+ assertInstances(collector, width, 2);
+ assertInstances(collector, N1, 1);
+ assertInstances(collector, diff, 3);
+ assertInstances(collector, lowk, 3);
+ assertInstances(collector, k, 8);
+ assertInstances(collector, idx, 2);
+ assertInstances(collector, exc_rad, 3);
+ assertInstances(collector, N2, 2);
+ assertInstances(collector, i2, 5);
}
public void testGCC20000412_5() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "int main( void ) { \n"); //$NON-NLS-1$
- buffer.append( " struct { \n"); //$NON-NLS-1$
- buffer.append( " int node; \n"); //$NON-NLS-1$
- buffer.append( " int type; \n"); //$NON-NLS-1$
- buffer.append( " } lastglob[1] = { { 0, 1 } }; \n"); //$NON-NLS-1$
- buffer.append( " if( lastglob[0].node != 0 || lastglob[0].type != 1 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int main(void) { \n"); //$NON-NLS-1$
+ buffer.append(" struct { \n"); //$NON-NLS-1$
+ buffer.append(" int node; \n"); //$NON-NLS-1$
+ buffer.append(" int type; \n"); //$NON-NLS-1$
+ buffer.append(" } lastglob[1] = { { 0, 1 } }; \n"); //$NON-NLS-1$
+ buffer.append(" if (lastglob[0].node != 0 || lastglob[0].type != 1) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 10 );
- IField node = (IField) collector.getName( 3 ).resolveBinding();
- IField type = (IField) collector.getName( 4 ).resolveBinding();
- IVariable lastglob = (IVariable) collector.getName( 5 ).resolveBinding();
+ assertEquals(collector.size(), 10);
+ IField node = (IField) collector.getName(3).resolveBinding();
+ IField type = (IField) collector.getName(4).resolveBinding();
+ IVariable lastglob = (IVariable) collector.getName(5).resolveBinding();
- assertInstances( collector, node, 2 );
- assertInstances( collector, type, 2 );
- assertInstances( collector, lastglob, 3 );
+ assertInstances(collector, node, 2);
+ assertInstances(collector, type, 2);
+ assertInstances(collector, lastglob, 3);
}
public void testGCC20000419() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct foo { int a, b, c; }; \n"); //$NON-NLS-1$
- buffer.append( "void brother( int a, int b, int c ) { \n"); //$NON-NLS-1$
- buffer.append( " if( a ) return; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "void sister( struct foo f, int b, int c ) { \n"); //$NON-NLS-1$
- buffer.append( " brother( (f.b == b), b, c ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " struct foo f = { 7, 8, 9 }; \n"); //$NON-NLS-1$
- buffer.append( " sister( f, 1, 2 ); \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct foo { int a, b, c; }; \n"); //$NON-NLS-1$
+ buffer.append("void brother(int a, int b, int c) { \n"); //$NON-NLS-1$
+ buffer.append(" if (a) return; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("void sister(struct foo f, int b, int c) { \n"); //$NON-NLS-1$
+ buffer.append(" brother((f.b == b), b, c); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct foo f = { 7, 8, 9 }; \n"); //$NON-NLS-1$
+ buffer.append(" sister(f, 1, 2); \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 25 );
- ICompositeType foo = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField fa = (IField) collector.getName( 1 ).resolveBinding();
- IField fb = (IField) collector.getName( 2 ).resolveBinding();
- IField fc = (IField) collector.getName( 3 ).resolveBinding();
- IFunction brother = (IFunction) collector.getName( 4 ).resolveBinding();
- IParameter pa = (IParameter) collector.getName( 5 ).resolveBinding();
- IParameter pb = (IParameter) collector.getName( 6 ).resolveBinding();
- IParameter pc = (IParameter) collector.getName( 7 ).resolveBinding();
- IFunction sister = (IFunction) collector.getName( 9 ).resolveBinding();
- IParameter sf = (IParameter) collector.getName( 11 ).resolveBinding();
- IParameter sb = (IParameter) collector.getName( 12 ).resolveBinding();
- IParameter sc = (IParameter) collector.getName( 13 ).resolveBinding();
- IVariable f = (IVariable) collector.getName( 22 ).resolveBinding();
+ assertEquals(collector.size(), 25);
+ ICompositeType foo = (ICompositeType) collector.getName(0).resolveBinding();
+ IField fa = (IField) collector.getName(1).resolveBinding();
+ IField fb = (IField) collector.getName(2).resolveBinding();
+ IField fc = (IField) collector.getName(3).resolveBinding();
+ IFunction brother = (IFunction) collector.getName(4).resolveBinding();
+ IParameter pa = (IParameter) collector.getName(5).resolveBinding();
+ IParameter pb = (IParameter) collector.getName(6).resolveBinding();
+ IParameter pc = (IParameter) collector.getName(7).resolveBinding();
+ IFunction sister = (IFunction) collector.getName(9).resolveBinding();
+ IParameter sf = (IParameter) collector.getName(11).resolveBinding();
+ IParameter sb = (IParameter) collector.getName(12).resolveBinding();
+ IParameter sc = (IParameter) collector.getName(13).resolveBinding();
+ IVariable f = (IVariable) collector.getName(22).resolveBinding();
- assertInstances( collector, foo, 3 );
- assertInstances( collector, fa, 1 );
- assertInstances( collector, fb, 2 );
- assertInstances( collector, fc, 1 );
- assertInstances( collector, brother, 2 );
- assertInstances( collector, pa, 2 );
- assertInstances( collector, pb, 1 );
- assertInstances( collector, pc, 1 );
- assertInstances( collector, sister, 2 );
- assertInstances( collector, sf, 2 );
- assertInstances( collector, sb, 3 );
- assertInstances( collector, sc, 2 );
- assertInstances( collector, f, 2 );
+ assertInstances(collector, foo, 3);
+ assertInstances(collector, fa, 1);
+ assertInstances(collector, fb, 2);
+ assertInstances(collector, fc, 1);
+ assertInstances(collector, brother, 2);
+ assertInstances(collector, pa, 2);
+ assertInstances(collector, pb, 1);
+ assertInstances(collector, pc, 1);
+ assertInstances(collector, sister, 2);
+ assertInstances(collector, sf, 2);
+ assertInstances(collector, sb, 3);
+ assertInstances(collector, sc, 2);
+ assertInstances(collector, f, 2);
}
public void testGCC20000503() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("unsigned long sub( int a ) { \n"); //$NON-NLS-1$
- buffer.append(" return ((0 > a - 2) ? 0 : a - 2) * sizeof(long); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
- buffer.append("main(){ \n"); //$NON-NLS-1$
- buffer.append(" return ( sub(0) != 0 ); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("unsigned long sub(int a) { \n"); //$NON-NLS-1$
+ buffer.append(" return ((0 > a - 2) ? 0 : a - 2) * sizeof(long); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" return (sub(0) != 0); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 6 );
- IFunction sub = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter a = (IParameter) collector.getName( 1 ).resolveBinding();
+ assertEquals(collector.size(), 6);
+ IFunction sub = (IFunction) collector.getName(0).resolveBinding();
+ IParameter a = (IParameter) collector.getName(1).resolveBinding();
- assertInstances( collector, sub, 2 );
- assertInstances( collector, a, 3 );
+ assertInstances(collector, sub, 2);
+ assertInstances(collector, a, 3);
}
public void testGCC20000511() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("int f( int value, int expect ) { \n"); //$NON-NLS-1$
- buffer.append(" return ( value == expect ); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
- buffer.append("main(){ \n"); //$NON-NLS-1$
- buffer.append(" int a = 7, b = 6, c = 4, d = 7, e = 2; \n"); //$NON-NLS-1$
- buffer.append(" f( a || b % c, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a ? b % c : 0, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a = b % c, 2); \n"); //$NON-NLS-1$
- buffer.append(" f( a *= b % c, 4 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a /= b % c, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a %= b % c, 0 ); \n"); //$NON-NLS-1$
- buffer.append(" f( a += b % c, 2 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d || c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d ? c && e : 0, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d = c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d *= c && e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d %= c && e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d += c && e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d -= c && e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d || c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d ? c || e : 0, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d = c || e, 1 ); \n"); //$NON-NLS-1$
- buffer.append(" f( d *= c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d %= c || e, 0); \n"); //$NON-NLS-1$
- buffer.append(" f( d += c || e, 1); \n"); //$NON-NLS-1$
- buffer.append(" f( d -= c || e, 0 ); \n"); //$NON-NLS-1$
- buffer.append("} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("int f(int value, int expect) { \n"); //$NON-NLS-1$
+ buffer.append(" return (value == expect); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" int a = 7, b = 6, c = 4, d = 7, e = 2; \n"); //$NON-NLS-1$
+ buffer.append(" f(a || b % c, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(a ? b % c : 0, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a = b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a *= b % c, 4); \n"); //$NON-NLS-1$
+ buffer.append(" f(a /= b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(a %= b % c, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(a += b % c, 2); \n"); //$NON-NLS-1$
+ buffer.append(" f(d || c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d ? c && e : 0, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d = c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d *= c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d %= c && e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d += c && e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d -= c && e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d || c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d ? c || e : 0, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d = c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d *= c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d %= c || e, 0); \n"); //$NON-NLS-1$
+ buffer.append(" f(d += c || e, 1); \n"); //$NON-NLS-1$
+ buffer.append(" f(d -= c || e, 0); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 95 );
- IFunction f = (IFunction) collector.getName( 0 ).resolveBinding();
- IParameter v = (IParameter) collector.getName( 1 ).resolveBinding();
- IParameter ex = (IParameter) collector.getName( 2 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 6 ).resolveBinding();
- IVariable b = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable c = (IVariable) collector.getName( 8 ).resolveBinding();
- IVariable d = (IVariable) collector.getName( 9 ).resolveBinding();
- IVariable e = (IVariable) collector.getName( 10).resolveBinding();
+ assertEquals(collector.size(), 95);
+ IFunction f = (IFunction) collector.getName(0).resolveBinding();
+ IParameter v = (IParameter) collector.getName(1).resolveBinding();
+ IParameter ex = (IParameter) collector.getName(2).resolveBinding();
+ IVariable a = (IVariable) collector.getName(6).resolveBinding();
+ IVariable b = (IVariable) collector.getName(7).resolveBinding();
+ IVariable c = (IVariable) collector.getName(8).resolveBinding();
+ IVariable d = (IVariable) collector.getName(9).resolveBinding();
+ IVariable e = (IVariable) collector.getName(10).resolveBinding();
- assertInstances( collector, f, 22 );
- assertInstances( collector, v, 2 );
- assertInstances( collector, ex, 2 );
- assertInstances( collector, a, 8 );
- assertInstances( collector, b, 8 );
- assertInstances( collector, c, 22 );
- assertInstances( collector, d, 15 );
- assertInstances( collector, e, 15 );
+ assertInstances(collector, f, 22);
+ assertInstances(collector, v, 2);
+ assertInstances(collector, ex, 2);
+ assertInstances(collector, a, 8);
+ assertInstances(collector, b, 8);
+ assertInstances(collector, c, 22);
+ assertInstances(collector, d, 15);
+ assertInstances(collector, e, 15);
}
public void testGCC20000603() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct s1 { double d; }; \n"); //$NON-NLS-1$
- buffer.append( "struct s2 { double d; }; \n"); //$NON-NLS-1$
- buffer.append( "double f( struct s1 * a, struct s2 *b) { \n"); //$NON-NLS-1$
- buffer.append( " a->d = 1.0; \n"); //$NON-NLS-1$
- buffer.append( " return b->d + 1.0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " struct s1 a; \n"); //$NON-NLS-1$
- buffer.append( " a.d = 0.0; \n"); //$NON-NLS-1$
- buffer.append( " if( f( &a, (struct s2 *)&a ) != 2.0 ) \n"); //$NON-NLS-1$
- buffer.append( " return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct s1 { double d; }; \n"); //$NON-NLS-1$
+ buffer.append("struct s2 { double d; }; \n"); //$NON-NLS-1$
+ buffer.append("double f(struct s1 * a, struct s2 *b) { \n"); //$NON-NLS-1$
+ buffer.append(" a->d = 1.0; \n"); //$NON-NLS-1$
+ buffer.append(" return b->d + 1.0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct s1 a; \n"); //$NON-NLS-1$
+ buffer.append(" a.d = 0.0; \n"); //$NON-NLS-1$
+ buffer.append(" if (f(&a, (struct s2 *)&a) != 2.0) \n"); //$NON-NLS-1$
+ buffer.append(" return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 22 );
- ICompositeType s1 = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField d1 = (IField) collector.getName( 1 ).resolveBinding();
- ICompositeType s2 = (ICompositeType) collector.getName( 2 ).resolveBinding();
- IField d2 = (IField) collector.getName( 3 ).resolveBinding();
- IFunction f = (IFunction) collector.getName( 4 ).resolveBinding();
- IParameter pa = (IParameter) collector.getName( 6 ).resolveBinding();
- IParameter pb = (IParameter) collector.getName( 8 ).resolveBinding();
- IVariable a = (IVariable) collector.getName( 15 ).resolveBinding();
+ assertEquals(collector.size(), 22);
+ ICompositeType s1 = (ICompositeType) collector.getName(0).resolveBinding();
+ IField d1 = (IField) collector.getName(1).resolveBinding();
+ ICompositeType s2 = (ICompositeType) collector.getName(2).resolveBinding();
+ IField d2 = (IField) collector.getName(3).resolveBinding();
+ IFunction f = (IFunction) collector.getName(4).resolveBinding();
+ IParameter pa = (IParameter) collector.getName(6).resolveBinding();
+ IParameter pb = (IParameter) collector.getName(8).resolveBinding();
+ IVariable a = (IVariable) collector.getName(15).resolveBinding();
- assertInstances( collector, s1, 3 );
- assertInstances( collector, s2, 3 );
- assertInstances( collector, d1, 3 );
- assertInstances( collector, d2, 2 );
- assertInstances( collector, f, 2 );
- assertInstances( collector, pa, 2 );
- assertInstances( collector, pb, 2 );
- assertInstances( collector, a, 4 );
+ assertInstances(collector, s1, 3);
+ assertInstances(collector, s2, 3);
+ assertInstances(collector, d1, 3);
+ assertInstances(collector, d2, 2);
+ assertInstances(collector, f, 2);
+ assertInstances(collector, pa, 2);
+ assertInstances(collector, pb, 2);
+ assertInstances(collector, a, 4);
}
public void testGCC20000605_2() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct F { int i; }; \n"); //$NON-NLS-1$
- buffer.append( "void f1( struct F *x, struct F * y ) { \n"); //$NON-NLS-1$
- buffer.append( " int timeout = 0; \n"); //$NON-NLS-1$
- buffer.append( " for( ; ((const struct F*)x)->i < y->i; x->i++ ) \n"); //$NON-NLS-1$
- buffer.append( " if( ++timeout > 5 ) \n"); //$NON-NLS-1$
- buffer.append( " return; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
- buffer.append( "main() { \n"); //$NON-NLS-1$
- buffer.append( " struct F x, y; \n"); //$NON-NLS-1$
- buffer.append( " x.i = 0; y.i = 1; \n"); //$NON-NLS-1$
- buffer.append( " f1( &x, &y ); \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct F { int i; }; \n"); //$NON-NLS-1$
+ buffer.append("void f1(struct F *x, struct F * y) { \n"); //$NON-NLS-1$
+ buffer.append(" int timeout = 0; \n"); //$NON-NLS-1$
+ buffer.append(" for (; ((const struct F*)x)->i < y->i; x->i++) \n"); //$NON-NLS-1$
+ buffer.append(" if (++timeout > 5) \n"); //$NON-NLS-1$
+ buffer.append(" return; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ buffer.append("main() { \n"); //$NON-NLS-1$
+ buffer.append(" struct F x, y; \n"); //$NON-NLS-1$
+ buffer.append(" x.i = 0; y.i = 1; \n"); //$NON-NLS-1$
+ buffer.append(" f1(&x, &y); \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 27 );
- ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField i = (IField) collector.getName( 1 ).resolveBinding();
- IFunction f1 = (IFunction) collector.getName( 2 ).resolveBinding();
- IParameter px = (IParameter) collector.getName( 4 ).resolveBinding();
- IParameter py = (IParameter) collector.getName( 6 ).resolveBinding();
- IVariable timeout = (IVariable) collector.getName( 7 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 18 ).resolveBinding();
- IVariable y = (IVariable) collector.getName( 19 ).resolveBinding();
+ assertEquals(collector.size(), 27);
+ ICompositeType F = (ICompositeType) collector.getName(0).resolveBinding();
+ IField i = (IField) collector.getName(1).resolveBinding();
+ IFunction f1 = (IFunction) collector.getName(2).resolveBinding();
+ IParameter px = (IParameter) collector.getName(4).resolveBinding();
+ IParameter py = (IParameter) collector.getName(6).resolveBinding();
+ IVariable timeout = (IVariable) collector.getName(7).resolveBinding();
+ IVariable x = (IVariable) collector.getName(18).resolveBinding();
+ IVariable y = (IVariable) collector.getName(19).resolveBinding();
- assertInstances( collector, F, 5 );
- assertInstances( collector, i, 6 );
- assertInstances( collector, f1, 2 );
- assertInstances( collector, px, 3 );
- assertInstances( collector, py, 2 );
- assertInstances( collector, timeout, 2 );
- assertInstances( collector, x, 3 );
- assertInstances( collector, y, 3 );
+ assertInstances(collector, F, 5);
+ assertInstances(collector, i, 6);
+ assertInstances(collector, f1, 2);
+ assertInstances(collector, px, 3);
+ assertInstances(collector, py, 2);
+ assertInstances(collector, timeout, 2);
+ assertInstances(collector, x, 3);
+ assertInstances(collector, y, 3);
}
public void testGCC20000605_3() throws Exception{
- StringBuffer buffer = new StringBuffer();
- buffer.append( "struct F { int x; int y; }; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int timeout = 0, x = 0; \n"); //$NON-NLS-1$
- buffer.append( " while( 1 ) { \n"); //$NON-NLS-1$
- buffer.append( " const struct F i = { x++, }; \n"); //$NON-NLS-1$
- buffer.append( " if( i.x > 0 ) \n"); //$NON-NLS-1$
- buffer.append( " break; \n"); //$NON-NLS-1$
- buffer.append( " if( ++timeout > 5 ) \n"); //$NON-NLS-1$
- buffer.append( " goto die; \n"); //$NON-NLS-1$
- buffer.append( " } \n"); //$NON-NLS-1$
- buffer.append( " die: return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("struct F { int x; int y; }; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int timeout = 0, x = 0; \n"); //$NON-NLS-1$
+ buffer.append(" while (1) { \n"); //$NON-NLS-1$
+ buffer.append(" const struct F i = { x++, }; \n"); //$NON-NLS-1$
+ buffer.append(" if (i.x > 0) \n"); //$NON-NLS-1$
+ buffer.append(" break; \n"); //$NON-NLS-1$
+ buffer.append(" if (++timeout > 5) \n"); //$NON-NLS-1$
+ buffer.append(" goto die; \n"); //$NON-NLS-1$
+ buffer.append(" } \n"); //$NON-NLS-1$
+ buffer.append(" die: return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 14 );
- ICompositeType F = (ICompositeType) collector.getName( 0 ).resolveBinding();
- IField fx = (IField) collector.getName( 1 ).resolveBinding();
- IField fy = (IField) collector.getName( 2 ).resolveBinding();
- IVariable timeout = (IVariable) collector.getName( 4 ).resolveBinding();
- IVariable x = (IVariable) collector.getName( 5 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 7 ).resolveBinding();
- ILabel die = (ILabel) collector.getName( 13 ).resolveBinding();
+ assertEquals(collector.size(), 14);
+ ICompositeType F = (ICompositeType) collector.getName(0).resolveBinding();
+ IField fx = (IField) collector.getName(1).resolveBinding();
+ IField fy = (IField) collector.getName(2).resolveBinding();
+ IVariable timeout = (IVariable) collector.getName(4).resolveBinding();
+ IVariable x = (IVariable) collector.getName(5).resolveBinding();
+ IVariable i = (IVariable) collector.getName(7).resolveBinding();
+ ILabel die = (ILabel) collector.getName(13).resolveBinding();
- assertInstances( collector, F, 2 );
- assertInstances( collector, fx, 2 );
- assertInstances( collector, fy, 1 );
- assertInstances( collector, timeout, 2 );
- assertInstances( collector, x, 2 );
- assertInstances( collector, i, 2 );
- assertInstances( collector, die, 2 );
+ assertInstances(collector, F, 2);
+ assertInstances(collector, fx, 2);
+ assertInstances(collector, fy, 1);
+ assertInstances(collector, timeout, 2);
+ assertInstances(collector, x, 2);
+ assertInstances(collector, i, 2);
+ assertInstances(collector, die, 2);
}
public void testGCCenum_2() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append( "enum foo { FOO, BAR }; \n"); //$NON-NLS-1$
- buffer.append( "int main() { \n"); //$NON-NLS-1$
- buffer.append( " int i; \n"); //$NON-NLS-1$
- buffer.append( " for( i = BAR; i >= FOO; --i ) \n"); //$NON-NLS-1$
- buffer.append( " if( i == -1 ) return -1; \n"); //$NON-NLS-1$
- buffer.append( " return 0; \n"); //$NON-NLS-1$
- buffer.append( "} \n"); //$NON-NLS-1$
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("enum foo { FOO, BAR }; \n"); //$NON-NLS-1$
+ buffer.append("int main() { \n"); //$NON-NLS-1$
+ buffer.append(" int i; \n"); //$NON-NLS-1$
+ buffer.append(" for (i = BAR; i >= FOO; --i) \n"); //$NON-NLS-1$
+ buffer.append(" if (i == -1) return -1; \n"); //$NON-NLS-1$
+ buffer.append(" return 0; \n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
- IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.C );
+ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C);
CNameCollector collector = new CNameCollector();
- tu.accept( collector );
+ tu.accept(collector);
- assertEquals( collector.size(), 11 );
- IEnumeration foo = (IEnumeration) collector.getName( 0 ).resolveBinding();
- IEnumerator FOO = (IEnumerator) collector.getName( 1 ).resolveBinding();
- IEnumerator BAR = (IEnumerator) collector.getName( 2 ).resolveBinding();
- IVariable i = (IVariable) collector.getName( 4 ).resolveBinding();
+ assertEquals(collector.size(), 11);
+ IEnumeration foo = (IEnumeration) collector.getName(0).resolveBinding();
+ IEnumerator FOO = (IEnumerator) collector.getName(1).resolveBinding();
+ IEnumerator BAR = (IEnumerator) collector.getName(2).resolveBinding();
+ IVariable i = (IVariable) collector.getName(4).resolveBinding();
- assertInstances( collector, foo, 1 );
- assertInstances( collector, FOO, 2 );
- assertInstances( collector, BAR, 2 );
- assertInstances( collector, i, 5 );
+ assertInstances(collector, foo, 1);
+ assertInstances(collector, FOO, 2);
+ assertInstances(collector, BAR, 2);
+ assertInstances(collector, i, 5);
}
}