mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Merge remote-tracking branch 'cdt/master' into sd90
This commit is contained in:
commit
d33a32f212
17 changed files with 268 additions and 117 deletions
|
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.CCorePreferenceConstants;
|
import org.eclipse.cdt.core.CCorePreferenceConstants;
|
||||||
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
|
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
|
||||||
import org.eclipse.cdt.core.language.WorkspaceLanguageConfiguration;
|
import org.eclipse.cdt.core.language.WorkspaceLanguageConfiguration;
|
||||||
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
import org.eclipse.cdt.core.settings.model.ICStorageElement;
|
||||||
import org.eclipse.cdt.internal.core.Util;
|
import org.eclipse.cdt.internal.core.Util;
|
||||||
|
@ -71,6 +72,13 @@ public class LanguageMappingStore {
|
||||||
ICProjectDescription descriptor = getProjectDescription(project, false);
|
ICProjectDescription descriptor = getProjectDescription(project, false);
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
|
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false);
|
||||||
|
if (rootElement == null) {
|
||||||
|
// bug 367061 - backwards compatibility: fallback to default configuration settings
|
||||||
|
ICConfigurationDescription cfgDesc = descriptor.getDefaultSettingConfiguration();
|
||||||
|
if (cfgDesc != null) {
|
||||||
|
rootElement = cfgDesc.getStorage(LANGUAGE_MAPPING_ID, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (rootElement != null) {
|
if (rootElement != null) {
|
||||||
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
|
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
|
||||||
if (mappingElements.length > 0) {
|
if (mappingElements.length > 0) {
|
||||||
|
@ -143,6 +151,11 @@ public class LanguageMappingStore {
|
||||||
|
|
||||||
public void storeMappings(IProject project, ProjectLanguageConfiguration config) throws CoreException {
|
public void storeMappings(IProject project, ProjectLanguageConfiguration config) throws CoreException {
|
||||||
ICProjectDescription descriptor = getProjectDescription(project, true);
|
ICProjectDescription descriptor = getProjectDescription(project, true);
|
||||||
|
ICConfigurationDescription cfgDesc = descriptor.getDefaultSettingConfiguration();
|
||||||
|
// remove old storage location if any
|
||||||
|
if (cfgDesc != null && cfgDesc.getStorage(LANGUAGE_MAPPING_ID, false) != null) {
|
||||||
|
cfgDesc.removeStorage(LANGUAGE_MAPPING_ID);
|
||||||
|
}
|
||||||
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, true);
|
ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, true);
|
||||||
// clear all children and settings
|
// clear all children and settings
|
||||||
rootElement.clear();
|
rootElement.clear();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Doug Schaefer (IBM) - Initial API and implementation
|
* Doug Schaefer (IBM) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IASTArrayDeclarator extends IASTDeclarator {
|
public interface IASTArrayDeclarator extends IASTDeclarator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node property that describes the relationship between an
|
* Node property that describes the relationship between an
|
||||||
* <code>IASTArrayDeclarator</code> and an <code>IASTArrayModifier</code>.
|
* <code>IASTArrayDeclarator</code> and an <code>IASTArrayModifier</code>.
|
||||||
|
@ -43,11 +42,13 @@ public interface IASTArrayDeclarator extends IASTDeclarator {
|
||||||
/**
|
/**
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTArrayDeclarator copy();
|
public IASTArrayDeclarator copy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTArrayDeclarator copy(CopyStyle style);
|
public IASTArrayDeclarator copy(CopyStyle style);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IASTArrayModifier extends IASTNode {
|
public interface IASTArrayModifier extends IASTNode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node property that describes the relationship between an
|
* Node property that describes the relationship between an
|
||||||
* <code>IASTArrayModifier</code> and an <code>IASTExpression</code>.
|
* <code>IASTArrayModifier</code> and an <code>IASTExpression</code>.
|
||||||
|
@ -49,10 +48,12 @@ public interface IASTArrayModifier extends IASTNode {
|
||||||
/**
|
/**
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTArrayModifier copy();
|
public IASTArrayModifier copy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTArrayModifier copy(CopyStyle style);
|
public IASTArrayModifier copy(CopyStyle style);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,34 +6,23 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface represents a postfix array subscript expression. x[ 10 ]
|
* This interface represents a postfix array subscript expression. x[10]
|
||||||
* y.z()[ t * t ]
|
* y.z()[t * t]
|
||||||
*
|
*
|
||||||
* @noextend This interface is not intended to be extended by clients.
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IASTArraySubscriptExpression extends IASTExpression {
|
public interface IASTArraySubscriptExpression extends IASTExpression {
|
||||||
|
|
||||||
public static final ASTNodeProperty ARRAY = new ASTNodeProperty(
|
public static final ASTNodeProperty ARRAY = new ASTNodeProperty(
|
||||||
"IASTArraySubscriptExpression.ARRAY [IASTExpression]"); //$NON-NLS-1$
|
"IASTArraySubscriptExpression.ARRAY [IASTExpression]"); //$NON-NLS-1$
|
||||||
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
|
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
|
||||||
"IASTArraySubscriptExpression.SUBSCRIPT - [IASTFunctionArgument]"); //$NON-NLS-1$
|
"IASTArraySubscriptExpression.SUBSCRIPT - [IASTFunctionArgument]"); //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 5.1
|
|
||||||
*/
|
|
||||||
IASTArraySubscriptExpression copy();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @since 5.3
|
|
||||||
*/
|
|
||||||
IASTArraySubscriptExpression copy(CopyStyle style);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the expression that represents the array
|
* Get the expression that represents the array
|
||||||
*
|
*
|
||||||
|
@ -74,4 +63,16 @@ public interface IASTArraySubscriptExpression extends IASTExpression {
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setSubscriptExpression(IASTExpression expression);
|
public void setSubscriptExpression(IASTExpression expression);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.1
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
IASTArraySubscriptExpression copy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.3
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
IASTArraySubscriptExpression copy(CopyStyle style);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Doug Schaefer (IBM) - Initial API and implementation
|
* Doug Schaefer (IBM) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.dom.ast;
|
package org.eclipse.cdt.core.dom.ast;
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
*/
|
*/
|
||||||
public interface IASTPointer extends IASTPointerOperator {
|
public interface IASTPointer extends IASTPointerOperator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the pointer is const qualified.
|
* Returns whether the pointer is const qualified.
|
||||||
*/
|
*/
|
||||||
|
@ -53,10 +52,12 @@ public interface IASTPointer extends IASTPointerOperator {
|
||||||
/**
|
/**
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTPointer copy();
|
public IASTPointer copy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public IASTPointer copy(CopyStyle style);
|
public IASTPointer copy(CopyStyle style);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||||
|
|
||||||
|
@ -22,9 +22,8 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator {
|
public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator {
|
||||||
|
private IASTArrayModifier[] arrayMods = null;
|
||||||
private IASTArrayModifier [] arrayMods = null;
|
private int arrayModsPos = -1;
|
||||||
private int arrayModsPos=-1;
|
|
||||||
|
|
||||||
public CASTArrayDeclarator() {
|
public CASTArrayDeclarator() {
|
||||||
}
|
}
|
||||||
|
@ -46,7 +45,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
|
||||||
public CASTArrayDeclarator copy(CopyStyle style) {
|
public CASTArrayDeclarator copy(CopyStyle style) {
|
||||||
CASTArrayDeclarator copy = new CASTArrayDeclarator();
|
CASTArrayDeclarator copy = new CASTArrayDeclarator();
|
||||||
copyBaseDeclarator(copy, style);
|
copyBaseDeclarator(copy, style);
|
||||||
for(IASTArrayModifier modifier : getArrayModifiers())
|
for (IASTArrayModifier modifier : getArrayModifiers())
|
||||||
copy.addArrayModifier(modifier == null ? null : modifier.copy());
|
copy.addArrayModifier(modifier == null ? null : modifier.copy());
|
||||||
if (style == CopyStyle.withLocations) {
|
if (style == CopyStyle.withLocations) {
|
||||||
copy.setCopyLocation(this);
|
copy.setCopyLocation(this);
|
||||||
|
@ -54,19 +53,24 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTArrayModifier[] getArrayModifiers() {
|
public IASTArrayModifier[] getArrayModifiers() {
|
||||||
if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY;
|
if (arrayMods == null)
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter( IASTArrayModifier.class, arrayMods, arrayModsPos );
|
return IASTArrayModifier.EMPTY_ARRAY;
|
||||||
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
|
||||||
|
arrayMods, arrayModsPos);
|
||||||
return arrayMods;
|
return arrayMods;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
@Override
|
||||||
|
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (arrayModifier != null) {
|
if (arrayModifier != null) {
|
||||||
arrayModifier.setParent(this);
|
arrayModifier.setParent(this);
|
||||||
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.append(IASTArrayModifier.class, arrayMods,
|
||||||
|
++arrayModsPos, arrayModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* John Camelon (IBM) - Initial API and implementation
|
* John Camelon (IBM) - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -22,10 +22,8 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
* Array declarator for c++.
|
* Array declarator for c++.
|
||||||
*/
|
*/
|
||||||
public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTArrayDeclarator {
|
public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTArrayDeclarator {
|
||||||
|
private IASTArrayModifier[] arrayMods = null;
|
||||||
private IASTArrayModifier [] arrayMods = null;
|
private int arrayModsPos = -1;
|
||||||
private int arrayModsPos=-1;
|
|
||||||
|
|
||||||
|
|
||||||
public CPPASTArrayDeclarator(IASTName name, IASTInitializer initializer) {
|
public CPPASTArrayDeclarator(IASTName name, IASTInitializer initializer) {
|
||||||
super(name, initializer);
|
super(name, initializer);
|
||||||
|
@ -35,7 +33,6 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CPPASTArrayDeclarator() {
|
public CPPASTArrayDeclarator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +41,6 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
|
||||||
return copy(CopyStyle.withoutLocations);
|
return copy(CopyStyle.withoutLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CPPASTArrayDeclarator copy(CopyStyle style) {
|
public CPPASTArrayDeclarator copy(CopyStyle style) {
|
||||||
CPPASTArrayDeclarator copy = new CPPASTArrayDeclarator();
|
CPPASTArrayDeclarator copy = new CPPASTArrayDeclarator();
|
||||||
|
@ -58,16 +54,21 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTArrayModifier[] getArrayModifiers() {
|
public IASTArrayModifier[] getArrayModifiers() {
|
||||||
if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY;
|
if (arrayMods == null)
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter( IASTArrayModifier.class, arrayMods, arrayModsPos );
|
return IASTArrayModifier.EMPTY_ARRAY;
|
||||||
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
|
||||||
|
arrayMods, arrayModsPos);
|
||||||
return arrayMods;
|
return arrayMods;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
@Override
|
||||||
|
public void addArrayModifier(IASTArrayModifier arrayModifier) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
if (arrayModifier != null) {
|
if (arrayModifier != null) {
|
||||||
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
|
arrayMods = (IASTArrayModifier[]) ArrayUtil.append(IASTArrayModifier.class, arrayMods,
|
||||||
|
++arrayModsPos, arrayModifier);
|
||||||
arrayModifier.setParent(this);
|
arrayModifier.setParent(this);
|
||||||
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
*/
|
*/
|
||||||
public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, IASTAmbiguityParent {
|
public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, IASTAmbiguityParent {
|
||||||
|
|
||||||
private IASTExpression exp;
|
private IASTExpression exp;
|
||||||
|
|
||||||
public CPPASTArrayModifier() {
|
public CPPASTArrayModifier() {
|
||||||
|
@ -32,14 +31,17 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
|
||||||
setConstantExpression(exp);
|
setConstantExpression(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression getConstantExpression() {
|
public IASTExpression getConstantExpression() {
|
||||||
return exp;
|
return exp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CPPASTArrayModifier copy() {
|
public CPPASTArrayModifier copy() {
|
||||||
return copy(CopyStyle.withoutLocations);
|
return copy(CopyStyle.withoutLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CPPASTArrayModifier copy(CopyStyle style) {
|
public CPPASTArrayModifier copy(CopyStyle style) {
|
||||||
CPPASTArrayModifier copy = new CPPASTArrayModifier(exp == null ? null : exp.copy(style));
|
CPPASTArrayModifier copy = new CPPASTArrayModifier(exp == null ? null : exp.copy(style));
|
||||||
copy.setOffsetAndLength(this);
|
copy.setOffsetAndLength(this);
|
||||||
|
@ -49,7 +51,8 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstantExpression(IASTExpression expression) {
|
@Override
|
||||||
|
public void setConstantExpression(IASTExpression expression) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
exp = expression;
|
exp = expression;
|
||||||
if (expression != null) {
|
if (expression != null) {
|
||||||
|
@ -62,9 +65,9 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
|
||||||
public boolean accept(ASTVisitor action) {
|
public boolean accept(ASTVisitor action) {
|
||||||
if (action.shouldVisitArrayModifiers) {
|
if (action.shouldVisitArrayModifiers) {
|
||||||
switch (action.visit(this)) {
|
switch (action.visit(this)) {
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
case ASTVisitor.PROCESS_ABORT: return false;
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
case ASTVisitor.PROCESS_SKIP: return true;
|
||||||
default : break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exp != null && !exp.accept(action))
|
if (exp != null && !exp.accept(action))
|
||||||
|
@ -76,7 +79,8 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace(IASTNode child, IASTNode other) {
|
@Override
|
||||||
|
public void replace(IASTNode child, IASTNode other) {
|
||||||
if (child == exp) {
|
if (child == exp) {
|
||||||
other.setPropertyInParent(child.getPropertyInParent());
|
other.setPropertyInParent(child.getPropertyInParent());
|
||||||
other.setParent(child.getParent());
|
other.setParent(child.getParent());
|
||||||
|
|
|
@ -37,13 +37,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||||
|
|
||||||
public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent {
|
public class CPPASTArraySubscriptExpression extends ASTNode
|
||||||
|
implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent {
|
||||||
private IASTExpression arrayExpression;
|
private IASTExpression arrayExpression;
|
||||||
private IASTInitializerClause subscriptExp;
|
private IASTInitializerClause subscriptExp;
|
||||||
private ICPPFunction overload= UNINITIALIZED_FUNCTION;
|
private ICPPFunction overload= UNINITIALIZED_FUNCTION;
|
||||||
|
|
||||||
private IASTImplicitName[] implicitNames = null;
|
private IASTImplicitName[] implicitNames;
|
||||||
|
|
||||||
public CPPASTArraySubscriptExpression() {
|
public CPPASTArraySubscriptExpression() {
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,12 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
setArgument(operand);
|
setArgument(operand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CPPASTArraySubscriptExpression copy() {
|
public CPPASTArraySubscriptExpression copy() {
|
||||||
return copy(CopyStyle.withoutLocations);
|
return copy(CopyStyle.withoutLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CPPASTArraySubscriptExpression copy(CopyStyle style) {
|
public CPPASTArraySubscriptExpression copy(CopyStyle style) {
|
||||||
CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression();
|
CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression();
|
||||||
copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy(style));
|
copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy(style));
|
||||||
|
@ -68,11 +70,13 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IASTExpression getArrayExpression() {
|
public IASTExpression getArrayExpression() {
|
||||||
return arrayExpression;
|
return arrayExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArrayExpression(IASTExpression expression) {
|
@Override
|
||||||
|
public void setArrayExpression(IASTExpression expression) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
arrayExpression = expression;
|
arrayExpression = expression;
|
||||||
if (expression != null) {
|
if (expression != null) {
|
||||||
|
@ -81,11 +85,13 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTInitializerClause getArgument() {
|
@Override
|
||||||
|
public IASTInitializerClause getArgument() {
|
||||||
return subscriptExp;
|
return subscriptExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArgument(IASTInitializerClause arg) {
|
@Override
|
||||||
|
public void setArgument(IASTInitializerClause arg) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
subscriptExp = arg;
|
subscriptExp = arg;
|
||||||
if (arg != null) {
|
if (arg != null) {
|
||||||
|
@ -94,19 +100,22 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Override
|
||||||
|
@Deprecated
|
||||||
public IASTExpression getSubscriptExpression() {
|
public IASTExpression getSubscriptExpression() {
|
||||||
if (subscriptExp instanceof IASTExpression)
|
if (subscriptExp instanceof IASTExpression)
|
||||||
return (IASTExpression) subscriptExp;
|
return (IASTExpression) subscriptExp;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void setSubscriptExpression(IASTExpression expression) {
|
public void setSubscriptExpression(IASTExpression expression) {
|
||||||
setArgument(expression);
|
setArgument(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTImplicitName[] getImplicitNames() {
|
@Override
|
||||||
|
public IASTImplicitName[] getImplicitNames() {
|
||||||
if (implicitNames == null) {
|
if (implicitNames == null) {
|
||||||
ICPPFunction overload = getOverload();
|
ICPPFunction overload = getOverload();
|
||||||
if (overload == null || overload instanceof CPPImplicitFunction)
|
if (overload == null || overload instanceof CPPImplicitFunction)
|
||||||
|
@ -128,7 +137,6 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
return implicitNames;
|
return implicitNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ICPPFunction getOverload() {
|
public ICPPFunction getOverload() {
|
||||||
if (overload == UNINITIALIZED_FUNCTION) {
|
if (overload == UNINITIALIZED_FUNCTION) {
|
||||||
overload= null;
|
overload= null;
|
||||||
|
@ -174,7 +182,8 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replace(IASTNode child, IASTNode other) {
|
@Override
|
||||||
|
public void replace(IASTNode child, IASTNode other) {
|
||||||
if (child == subscriptExp) {
|
if (child == subscriptExp) {
|
||||||
other.setPropertyInParent(child.getPropertyInParent());
|
other.setPropertyInParent(child.getPropertyInParent());
|
||||||
other.setParent(child.getParent());
|
other.setParent(child.getParent());
|
||||||
|
@ -187,7 +196,8 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IType getExpressionType() {
|
@Override
|
||||||
|
public IType getExpressionType() {
|
||||||
ICPPFunction op = getOverload();
|
ICPPFunction op = getOverload();
|
||||||
if (op != null) {
|
if (op != null) {
|
||||||
return ExpressionTypes.typeFromFunctionCall(op);
|
return ExpressionTypes.typeFromFunctionCall(op);
|
||||||
|
@ -216,10 +226,12 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
|
||||||
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isLValue() {
|
public boolean isLValue() {
|
||||||
return getValueCategory() == LVALUE;
|
return getValueCategory() == LVALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ValueCategory getValueCategory() {
|
public ValueCategory getValueCategory() {
|
||||||
ICPPFunction op = getOverload();
|
ICPPFunction op = getOverload();
|
||||||
if (op != null) {
|
if (op != null) {
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* John Camelon (IBM) - Initial API and implementation
|
* John Camelon (IBM) - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
* A pointer operator of a declarator
|
* A pointer operator of a declarator
|
||||||
*/
|
*/
|
||||||
public class CPPASTPointer extends ASTNode implements IASTPointer {
|
public class CPPASTPointer extends ASTNode implements IASTPointer {
|
||||||
|
|
||||||
private boolean isConst;
|
private boolean isConst;
|
||||||
private boolean isVolatile;
|
private boolean isVolatile;
|
||||||
private boolean isRestrict;
|
private boolean isRestrict;
|
||||||
|
@ -27,10 +26,12 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
|
||||||
public CPPASTPointer() {
|
public CPPASTPointer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPPASTPointer copy() {
|
@Override
|
||||||
|
public CPPASTPointer copy() {
|
||||||
return copy(CopyStyle.withoutLocations);
|
return copy(CopyStyle.withoutLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CPPASTPointer copy(CopyStyle style) {
|
public CPPASTPointer copy(CopyStyle style) {
|
||||||
CPPASTPointer copy = new CPPASTPointer();
|
CPPASTPointer copy = new CPPASTPointer();
|
||||||
copy.isConst = isConst;
|
copy.isConst = isConst;
|
||||||
|
@ -43,29 +44,35 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConst() {
|
@Override
|
||||||
|
public boolean isConst() {
|
||||||
return isConst;
|
return isConst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVolatile() {
|
@Override
|
||||||
|
public boolean isVolatile() {
|
||||||
return isVolatile;
|
return isVolatile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRestrict() {
|
@Override
|
||||||
|
public boolean isRestrict() {
|
||||||
return isRestrict;
|
return isRestrict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConst(boolean value) {
|
@Override
|
||||||
|
public void setConst(boolean value) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
isConst = value;
|
isConst = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVolatile(boolean value) {
|
@Override
|
||||||
|
public void setVolatile(boolean value) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
isVolatile = value;
|
isVolatile = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRestrict(boolean value) {
|
@Override
|
||||||
|
public void setRestrict(boolean value) {
|
||||||
assertNotFrozen();
|
assertNotFrozen();
|
||||||
isRestrict = value;
|
isRestrict = value;
|
||||||
}
|
}
|
||||||
|
@ -74,8 +81,8 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
|
||||||
public boolean accept(ASTVisitor action) {
|
public boolean accept(ASTVisitor action) {
|
||||||
if (action.shouldVisitPointerOperators) {
|
if (action.shouldVisitPointerOperators) {
|
||||||
switch (action.visit(this)) {
|
switch (action.visit(this)) {
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
case ASTVisitor.PROCESS_ABORT: return false;
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
case ASTVisitor.PROCESS_SKIP: return true;
|
||||||
}
|
}
|
||||||
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -460,7 +460,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
IFile file = FileHelper.getFileFromNode(anchorNode);
|
IFile file = FileHelper.getFileFromNode(anchorNode);
|
||||||
MultiTextEdit parentEdit = getEdit(anchorNode, file);
|
MultiTextEdit parentEdit = getEdit(anchorNode, file);
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
sourceOffsets.put(file.getName(), Integer.valueOf(edit.getOffset()));
|
sourceOffsets.put(file.getName(), edit.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleReplace(IASTNode node) {
|
private void handleReplace(IASTNode node) {
|
||||||
|
@ -469,10 +469,13 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
TextEdit edit;
|
TextEdit edit;
|
||||||
ChangeGeneratorWriterVisitor writer =
|
ChangeGeneratorWriterVisitor writer =
|
||||||
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
|
new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
|
||||||
|
IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
|
Integer val = sourceOffsets.get(fileLocation.getFileName());
|
||||||
|
int processedOffset = val != null ? val.intValue() : 0;
|
||||||
if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
|
if (modifications.size() == 1 && modifications.get(0).getNewNode() == null) {
|
||||||
int offset = getOffsetIncludingComments(node);
|
int offset = getOffsetIncludingComments(node);
|
||||||
int endOffset = getEndOffsetIncludingComments(node);
|
int endOffset = getEndOffsetIncludingComments(node);
|
||||||
offset = skipPrecedingBlankLines(source, offset);
|
offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
|
||||||
endOffset = skipTrailingBlankLines(source, endOffset);
|
endOffset = skipTrailingBlankLines(source, endOffset);
|
||||||
IASTNode[] siblingsList = getContainingNodeList(node);
|
IASTNode[] siblingsList = getContainingNodeList(node);
|
||||||
if (siblingsList != null) {
|
if (siblingsList != null) {
|
||||||
|
@ -500,9 +503,8 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
} else {
|
} else {
|
||||||
node.accept(writer);
|
node.accept(writer);
|
||||||
String code = writer.toString();
|
String code = writer.toString();
|
||||||
IASTFileLocation location = node.getFileLocation();
|
int offset = fileLocation.getNodeOffset();
|
||||||
int offset = location.getNodeOffset();
|
int endOffset = offset + fileLocation.getNodeLength();
|
||||||
int endOffset = offset + location.getNodeLength();
|
|
||||||
if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
|
if (node instanceof IASTStatement || node instanceof IASTDeclaration) {
|
||||||
// Include trailing comments in the area to be replaced.
|
// Include trailing comments in the area to be replaced.
|
||||||
endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
|
endOffset = Math.max(endOffset, getEndOffsetIncludingTrailingComments(node));
|
||||||
|
@ -517,9 +519,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
MultiTextEdit parentEdit = getEdit(node, file);
|
MultiTextEdit parentEdit = getEdit(node, file);
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
|
|
||||||
IASTFileLocation fileLocation = node.getFileLocation();
|
sourceOffsets.put(fileLocation.getFileName(), edit.getExclusiveEnd());
|
||||||
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
|
||||||
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAppends(IASTNode node) {
|
private void handleAppends(IASTNode node) {
|
||||||
|
@ -553,8 +553,7 @@ public class ChangeGenerator extends ASTVisitor {
|
||||||
code + anchor.getText());
|
code + anchor.getText());
|
||||||
parentEdit.addChild(edit);
|
parentEdit.addChild(edit);
|
||||||
IASTFileLocation fileLocation = node.getFileLocation();
|
IASTFileLocation fileLocation = node.getFileLocation();
|
||||||
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
sourceOffsets.put(fileLocation.getFileName(), endOffset(fileLocation));
|
||||||
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAppends(IASTTranslationUnit tu) {
|
private void handleAppends(IASTTranslationUnit tu) {
|
||||||
|
|
|
@ -2512,24 +2512,60 @@ visibility=public
|
||||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||||
//@main.c
|
//@main.c
|
||||||
int main() {
|
int main() {
|
||||||
int a,b;
|
int a, b;
|
||||||
/*$*/a = b*2;/*$$*/
|
/*$*/a = b * 2;/*$$*/
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//=
|
//=
|
||||||
void test(int* a, int b) {
|
void test(int* a, int b) {
|
||||||
a = b * 2;
|
a = b * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int a,b;
|
int a, b;
|
||||||
test(a, b);
|
test(a, b);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@.config
|
//@.config
|
||||||
filename=main.c
|
filename=main.c
|
||||||
methodname=test
|
methodname=test
|
||||||
replaceduplicates=false
|
replaceduplicates=false
|
||||||
returnvalue=false
|
returnvalue=false
|
||||||
|
|
||||||
|
//!Handling of blank lines
|
||||||
|
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||||
|
//@main.c
|
||||||
|
int main() {
|
||||||
|
int f;
|
||||||
|
/*$*/int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
int c = a + b;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}/*$$*/
|
||||||
|
|
||||||
|
f = b;
|
||||||
|
}
|
||||||
|
//=
|
||||||
|
int fib() {
|
||||||
|
int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
for (int i = 0; i < 10; ++i) {
|
||||||
|
int c = a + b;
|
||||||
|
a = b;
|
||||||
|
b = c;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int f;
|
||||||
|
int b = fib();
|
||||||
|
f = b;
|
||||||
|
}
|
||||||
|
//@.config
|
||||||
|
filename=main.c
|
||||||
|
methodname=fib
|
||||||
|
replaceduplicates=false
|
||||||
|
|
|
@ -1451,3 +1451,31 @@ public:
|
||||||
int test;
|
int test;
|
||||||
};
|
};
|
||||||
#endif /* A_H_ */
|
#endif /* A_H_ */
|
||||||
|
//!Bug ??? - Getter for an array field
|
||||||
|
//#org.eclipse.cdt.ui.tests.refactoring.gettersandsetters.GenerateGettersAndSettersTest
|
||||||
|
//@.config
|
||||||
|
filename=A.h
|
||||||
|
getters=a
|
||||||
|
//@A.h
|
||||||
|
#ifndef A_H_
|
||||||
|
#define A_H_
|
||||||
|
|
||||||
|
class A {
|
||||||
|
private:
|
||||||
|
int /*$*/a[2]/*$$*/;
|
||||||
|
};
|
||||||
|
#endif /* A_H_ */
|
||||||
|
//=
|
||||||
|
#ifndef A_H_
|
||||||
|
#define A_H_
|
||||||
|
|
||||||
|
class A {
|
||||||
|
private:
|
||||||
|
int a[2];
|
||||||
|
|
||||||
|
public:
|
||||||
|
const int* getA() const {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif /* A_H_ */
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage impl
|
||||||
for (Object funct : funtions) {
|
for (Object funct : funtions) {
|
||||||
if (funct instanceof GetterSetterInsertEditProvider) {
|
if (funct instanceof GetterSetterInsertEditProvider) {
|
||||||
GetterSetterInsertEditProvider getSet = (GetterSetterInsertEditProvider) funct;
|
GetterSetterInsertEditProvider getSet = (GetterSetterInsertEditProvider) funct;
|
||||||
if(getSet.getType() == type) {
|
if (getSet.getType() == type) {
|
||||||
checked.add(getSet);
|
checked.add(getSet);
|
||||||
variableSelectionView.setChecked(getSet, true);
|
variableSelectionView.setChecked(getSet, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
|
|
||||||
private IASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTName selectedName) {
|
private IASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTName selectedName) {
|
||||||
IASTNode node = selectedName;
|
IASTNode node = selectedName;
|
||||||
while(node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
|
while (node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
return (IASTCompositeTypeSpecifier) node;
|
return (IASTCompositeTypeSpecifier) node;
|
||||||
|
@ -181,7 +181,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
|
|
||||||
private IASTName getSelectedName(IASTTranslationUnit ast) {
|
private IASTName getSelectedName(IASTTranslationUnit ast) {
|
||||||
List<IASTName> names = findAllMarkedNames(ast);
|
List<IASTName> names = findAllMarkedNames(ast);
|
||||||
if (names.size() < 1) {
|
if (names.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return names.get(names.size() - 1);
|
return names.get(names.size() - 1);
|
||||||
|
|
|
@ -23,6 +23,15 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IQualifierType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind;
|
import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind;
|
||||||
|
|
||||||
|
@ -45,7 +54,7 @@ public class GetterSetterContext implements ITreeContentProvider {
|
||||||
if (!wrapper.getter.exists()) {
|
if (!wrapper.getter.exists()) {
|
||||||
wrapper.childNodes.add(createGetterInserter(wrapper.field));
|
wrapper.childNodes.add(createGetterInserter(wrapper.field));
|
||||||
}
|
}
|
||||||
if (!wrapper.setter.exists() && !wrapper.field.getDeclSpecifier().isConst()) {
|
if (!wrapper.setter.exists() && isAssignable(wrapper.field)) {
|
||||||
wrapper.childNodes.add(createSetterInserter(wrapper.field));
|
wrapper.childNodes.add(createSetterInserter(wrapper.field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,12 +64,12 @@ public class GetterSetterContext implements ITreeContentProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
||||||
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
|
IASTName fieldName = getDeclarationName(simpleDeclaration);
|
||||||
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.GETTER);
|
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.GETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) {
|
||||||
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
|
IASTName fieldName = getDeclarationName(simpleDeclaration);
|
||||||
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.SETTER);
|
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.SETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,11 +124,11 @@ public class GetterSetterContext implements ITreeContentProvider {
|
||||||
private ArrayList<FieldWrapper> getWrappedFields() {
|
private ArrayList<FieldWrapper> getWrappedFields() {
|
||||||
if (wrappedFields == null) {
|
if (wrappedFields == null) {
|
||||||
wrappedFields = new ArrayList<FieldWrapper>();
|
wrappedFields = new ArrayList<FieldWrapper>();
|
||||||
for (IASTSimpleDeclaration currentField : existingFields) {
|
for (IASTSimpleDeclaration field : existingFields) {
|
||||||
FieldWrapper wrapper = new FieldWrapper();
|
FieldWrapper wrapper = new FieldWrapper();
|
||||||
wrapper.field = currentField;
|
wrapper.field = field;
|
||||||
wrapper.getter = getGetterForField(currentField);
|
wrapper.getter = getGetterForField(field);
|
||||||
wrapper.setter = getSetterForField(currentField);
|
wrapper.setter = getSetterForField(field);
|
||||||
if (wrapper.missingGetterOrSetter()) {
|
if (wrapper.missingGetterOrSetter()) {
|
||||||
wrappedFields.add(wrapper);
|
wrappedFields.add(wrapper);
|
||||||
}
|
}
|
||||||
|
@ -130,35 +139,52 @@ public class GetterSetterContext implements ITreeContentProvider {
|
||||||
|
|
||||||
private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) {
|
private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) {
|
||||||
FunctionWrapper wrapper = new FunctionWrapper();
|
FunctionWrapper wrapper = new FunctionWrapper();
|
||||||
String name = GetterSetterNameGenerator.generateGetterName(getFieldDeclarationName(currentField));
|
String name = GetterSetterNameGenerator.generateGetterName(getDeclarationName(currentField));
|
||||||
setFunctionToWrapper(wrapper, name);
|
setFunctionToWrapper(wrapper, name);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTName getFieldDeclarationName(IASTSimpleDeclaration fieldDeclaration) {
|
private FunctionWrapper getSetterForField(IASTSimpleDeclaration field) {
|
||||||
IASTDeclarator declarator = fieldDeclaration.getDeclarators()[0];
|
FunctionWrapper wrapper = new FunctionWrapper();
|
||||||
|
String name = GetterSetterNameGenerator.generateSetterName(getDeclarationName(field));
|
||||||
|
setFunctionToWrapper(wrapper, name);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IASTName getDeclarationName(IASTSimpleDeclaration declaration) {
|
||||||
|
IASTDeclarator declarator = declaration.getDeclarators()[0];
|
||||||
while (declarator.getNestedDeclarator() != null) {
|
while (declarator.getNestedDeclarator() != null) {
|
||||||
declarator = declarator.getNestedDeclarator();
|
declarator = declarator.getNestedDeclarator();
|
||||||
}
|
}
|
||||||
return declarator.getName();
|
return declarator.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FunctionWrapper getSetterForField(IASTSimpleDeclaration currentField) {
|
private static boolean isAssignable(IASTSimpleDeclaration declaration) {
|
||||||
FunctionWrapper wrapper = new FunctionWrapper();
|
IASTName name = getDeclarationName(declaration);
|
||||||
String name = GetterSetterNameGenerator.generateSetterName(getFieldDeclarationName(currentField));
|
IBinding binding = name.resolveBinding();
|
||||||
setFunctionToWrapper(wrapper, name);
|
if (!(binding instanceof ICPPField))
|
||||||
return wrapper;
|
return false;
|
||||||
|
ICPPField field = (ICPPField) binding;
|
||||||
|
IType type = field.getType();
|
||||||
|
type = SemanticUtil.getNestedType(type, SemanticUtil.TDEF);
|
||||||
|
if (type instanceof IArrayType || type instanceof ICPPReferenceType)
|
||||||
|
return false;
|
||||||
|
if (type instanceof IPointerType && ((IPointerType) type).isConst())
|
||||||
|
return false;
|
||||||
|
if (type instanceof IQualifierType && ((IQualifierType) type).isConst())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFunctionToWrapper(FunctionWrapper wrapper, String getterName) {
|
private void setFunctionToWrapper(FunctionWrapper wrapper, String accessorName) {
|
||||||
for (IASTFunctionDefinition currentDefinition : existingFunctionDefinitions) {
|
for (IASTFunctionDefinition currentDefinition : existingFunctionDefinitions) {
|
||||||
if (currentDefinition.getDeclarator().getName().toString().endsWith(getterName)) {
|
if (currentDefinition.getDeclarator().getName().toString().equals(accessorName)) {
|
||||||
wrapper.functionDefinition = currentDefinition;
|
wrapper.functionDefinition = currentDefinition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IASTSimpleDeclaration currentDeclaration : existingFunctionDeclarations) {
|
for (IASTSimpleDeclaration currentDeclaration : existingFunctionDeclarations) {
|
||||||
if (getFieldDeclarationName(currentDeclaration).toString().endsWith(getterName)) {
|
if (getDeclarationName(currentDeclaration).toString().equals(accessorName)) {
|
||||||
wrapper.functionDeclaration = currentDeclaration;
|
wrapper.functionDeclaration = currentDeclaration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -25,12 +26,16 @@ import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTArrayDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.TypeHelper;
|
import org.eclipse.cdt.core.dom.rewrite.TypeHelper;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
import org.eclipse.cdt.core.parser.Keywords;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CASTDeclarator;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTBinaryExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTExpressionStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFieldReference;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
|
||||||
|
@ -39,6 +44,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReferenceOperator;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReferenceOperator;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
|
||||||
|
@ -90,6 +96,17 @@ public class GetterSetterFactory {
|
||||||
// Copy declarator hierarchy
|
// Copy declarator hierarchy
|
||||||
IASTDeclarator topDeclarator = fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations);
|
IASTDeclarator topDeclarator = fieldDeclaration.getDeclarators()[0].copy(CopyStyle.withLocations);
|
||||||
|
|
||||||
|
if (topDeclarator instanceof IASTArrayDeclarator) {
|
||||||
|
boolean isCpp = topDeclarator instanceof ICPPASTArrayDeclarator;
|
||||||
|
IASTDeclarator decl = isCpp ? new CPPASTDeclarator() : new CASTDeclarator();
|
||||||
|
decl.setName(topDeclarator.getName());
|
||||||
|
decl.setNestedDeclarator(topDeclarator.getNestedDeclarator());
|
||||||
|
decl.addPointerOperator(isCpp ? new CPPASTPointer() : new CASTPointer());
|
||||||
|
for (IASTPointerOperator pointer : topDeclarator.getPointerOperators()) {
|
||||||
|
decl.addPointerOperator(pointer);
|
||||||
|
}
|
||||||
|
topDeclarator = decl;
|
||||||
|
}
|
||||||
// Find the innermost declarator in hierarchy
|
// Find the innermost declarator in hierarchy
|
||||||
IASTDeclarator innermost = topDeclarator;
|
IASTDeclarator innermost = topDeclarator;
|
||||||
while (innermost.getNestedDeclarator() != null) {
|
while (innermost.getNestedDeclarator() != null) {
|
||||||
|
@ -203,7 +220,7 @@ public class GetterSetterFactory {
|
||||||
|
|
||||||
private IASTDeclSpecifier getParamOrReturnDeclSpecifier() {
|
private IASTDeclSpecifier getParamOrReturnDeclSpecifier() {
|
||||||
IASTDeclSpecifier declSpec = fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations);
|
IASTDeclSpecifier declSpec = fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations);
|
||||||
if (passByReference) {
|
if (passByReference || fieldDeclaration.getDeclarators()[0] instanceof IASTArrayDeclarator) {
|
||||||
declSpec.setConst(true);
|
declSpec.setConst(true);
|
||||||
}
|
}
|
||||||
return declSpec;
|
return declSpec;
|
||||||
|
|
Loading…
Add table
Reference in a new issue