1
0
Fork 0
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:
Andrew Gvozdev 2011-12-20 11:36:24 -05:00
commit d33a32f212
17 changed files with 268 additions and 117 deletions

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.language.ProjectLanguageConfiguration;
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.ICStorageElement;
import org.eclipse.cdt.internal.core.Util;
@ -71,6 +72,13 @@ public class LanguageMappingStore {
ICProjectDescription descriptor = getProjectDescription(project, false);
if (descriptor != null) {
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) {
ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS);
if (mappingElements.length > 0) {
@ -143,6 +151,11 @@ public class LanguageMappingStore {
public void storeMappings(IProject project, ProjectLanguageConfiguration config) throws CoreException {
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);
// clear all children and settings
rootElement.clear();

View file

@ -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;
@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTArrayDeclarator extends IASTDeclarator {
/**
* Node property that describes the relationship between an
* <code>IASTArrayDeclarator</code> and an <code>IASTArrayModifier</code>.
@ -43,11 +42,13 @@ public interface IASTArrayDeclarator extends IASTDeclarator {
/**
* @since 5.1
*/
@Override
public IASTArrayDeclarator copy();
/**
* @since 5.3
*/
@Override
public IASTArrayDeclarator copy(CopyStyle style);
}

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* 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;
@ -18,7 +18,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTArrayModifier extends IASTNode {
/**
* Node property that describes the relationship between an
* <code>IASTArrayModifier</code> and an <code>IASTExpression</code>.
@ -49,10 +48,12 @@ public interface IASTArrayModifier extends IASTNode {
/**
* @since 5.1
*/
@Override
public IASTArrayModifier copy();
/**
* @since 5.3
*/
@Override
public IASTArrayModifier copy(CopyStyle style);
}

View file

@ -6,34 +6,23 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* 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;
/**
* This interface represents a postfix array subscript expression. x[ 10 ]
* y.z()[ t * t ]
* This interface represents a postfix array subscript expression. x[10]
* y.z()[t * t]
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTArraySubscriptExpression extends IASTExpression {
public static final ASTNodeProperty ARRAY = new ASTNodeProperty(
"IASTArraySubscriptExpression.ARRAY [IASTExpression]"); //$NON-NLS-1$
public static final ASTNodeProperty SUBSCRIPT = new ASTNodeProperty(
"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
*
@ -74,4 +63,16 @@ public interface IASTArraySubscriptExpression extends IASTExpression {
*/
@Deprecated
public void setSubscriptExpression(IASTExpression expression);
/**
* @since 5.1
*/
@Override
IASTArraySubscriptExpression copy();
/**
* @since 5.3
*/
@Override
IASTArraySubscriptExpression copy(CopyStyle style);
}

View file

@ -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;
@ -17,7 +17,6 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTPointer extends IASTPointerOperator {
/**
* Returns whether the pointer is const qualified.
*/
@ -53,10 +52,12 @@ public interface IASTPointer extends IASTPointerOperator {
/**
* @since 5.1
*/
@Override
public IASTPointer copy();
/**
* @since 5.3
*/
@Override
public IASTPointer copy(CopyStyle style);
}

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@ -22,9 +22,8 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
* @author jcamelon
*/
public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDeclarator {
private IASTArrayModifier [] arrayMods = null;
private int arrayModsPos=-1;
private IASTArrayModifier[] arrayMods = null;
private int arrayModsPos = -1;
public CASTArrayDeclarator() {
}
@ -46,7 +45,7 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
public CASTArrayDeclarator copy(CopyStyle style) {
CASTArrayDeclarator copy = new CASTArrayDeclarator();
copyBaseDeclarator(copy, style);
for(IASTArrayModifier modifier : getArrayModifiers())
for (IASTArrayModifier modifier : getArrayModifiers())
copy.addArrayModifier(modifier == null ? null : modifier.copy());
if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this);
@ -54,19 +53,24 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
return copy;
}
@Override
public IASTArrayModifier[] getArrayModifiers() {
if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY;
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter( IASTArrayModifier.class, arrayMods, arrayModsPos );
if (arrayMods == null)
return IASTArrayModifier.EMPTY_ARRAY;
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
arrayMods, arrayModsPos);
return arrayMods;
}
public void addArrayModifier(IASTArrayModifier arrayModifier) {
@Override
public void addArrayModifier(IASTArrayModifier arrayModifier) {
assertNotFrozen();
if (arrayModifier != null) {
arrayModifier.setParent(this);
arrayModifier.setPropertyInParent(ARRAY_MODIFIER);
arrayMods = (IASTArrayModifier[]) ArrayUtil.append( IASTArrayModifier.class, arrayMods, ++arrayModsPos, arrayModifier );
arrayMods = (IASTArrayModifier[]) ArrayUtil.append(IASTArrayModifier.class, arrayMods,
++arrayModsPos, arrayModifier);
}
}

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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++.
*/
public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTArrayDeclarator {
private IASTArrayModifier [] arrayMods = null;
private int arrayModsPos=-1;
private IASTArrayModifier[] arrayMods = null;
private int arrayModsPos = -1;
public CPPASTArrayDeclarator(IASTName name, IASTInitializer initializer) {
super(name, initializer);
@ -35,7 +33,6 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
super(name);
}
public CPPASTArrayDeclarator() {
}
@ -44,7 +41,6 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
return copy(CopyStyle.withoutLocations);
}
@Override
public CPPASTArrayDeclarator copy(CopyStyle style) {
CPPASTArrayDeclarator copy = new CPPASTArrayDeclarator();
@ -58,16 +54,21 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements ICPPASTAr
return copy;
}
@Override
public IASTArrayModifier[] getArrayModifiers() {
if( arrayMods == null ) return IASTArrayModifier.EMPTY_ARRAY;
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter( IASTArrayModifier.class, arrayMods, arrayModsPos );
if (arrayMods == null)
return IASTArrayModifier.EMPTY_ARRAY;
arrayMods = (IASTArrayModifier[]) ArrayUtil.removeNullsAfter(IASTArrayModifier.class,
arrayMods, arrayModsPos);
return arrayMods;
}
public void addArrayModifier(IASTArrayModifier arrayModifier) {
@Override
public void addArrayModifier(IASTArrayModifier arrayModifier) {
assertNotFrozen();
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.setPropertyInParent(ARRAY_MODIFIER);
}

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -22,7 +22,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
* @author jcamelon
*/
public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, IASTAmbiguityParent {
private IASTExpression exp;
public CPPASTArrayModifier() {
@ -32,14 +31,17 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
setConstantExpression(exp);
}
@Override
public IASTExpression getConstantExpression() {
return exp;
}
@Override
public CPPASTArrayModifier copy() {
return copy(CopyStyle.withoutLocations);
}
@Override
public CPPASTArrayModifier copy(CopyStyle style) {
CPPASTArrayModifier copy = new CPPASTArrayModifier(exp == null ? null : exp.copy(style));
copy.setOffsetAndLength(this);
@ -49,7 +51,8 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
return copy;
}
public void setConstantExpression(IASTExpression expression) {
@Override
public void setConstantExpression(IASTExpression expression) {
assertNotFrozen();
exp = expression;
if (expression != null) {
@ -62,9 +65,9 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
public boolean accept(ASTVisitor action) {
if (action.shouldVisitArrayModifiers) {
switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP: return true;
default: break;
}
}
if (exp != null && !exp.accept(action))
@ -76,7 +79,8 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
return true;
}
public void replace(IASTNode child, IASTNode other) {
@Override
public void replace(IASTNode child, IASTNode other) {
if (child == exp) {
other.setPropertyInParent(child.getPropertyInParent());
other.setParent(child.getParent());

View file

@ -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.SemanticUtil;
public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent {
public class CPPASTArraySubscriptExpression extends ASTNode
implements ICPPASTArraySubscriptExpression, IASTAmbiguityParent {
private IASTExpression arrayExpression;
private IASTInitializerClause subscriptExp;
private ICPPFunction overload= UNINITIALIZED_FUNCTION;
private IASTImplicitName[] implicitNames = null;
private IASTImplicitName[] implicitNames;
public CPPASTArraySubscriptExpression() {
}
@ -53,10 +53,12 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
setArgument(operand);
}
@Override
public CPPASTArraySubscriptExpression copy() {
return copy(CopyStyle.withoutLocations);
}
@Override
public CPPASTArraySubscriptExpression copy(CopyStyle style) {
CPPASTArraySubscriptExpression copy = new CPPASTArraySubscriptExpression();
copy.setArrayExpression(arrayExpression == null ? null : arrayExpression.copy(style));
@ -68,11 +70,13 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
return copy;
}
@Override
public IASTExpression getArrayExpression() {
return arrayExpression;
}
public void setArrayExpression(IASTExpression expression) {
@Override
public void setArrayExpression(IASTExpression expression) {
assertNotFrozen();
arrayExpression = expression;
if (expression != null) {
@ -81,11 +85,13 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
}
}
public IASTInitializerClause getArgument() {
@Override
public IASTInitializerClause getArgument() {
return subscriptExp;
}
public void setArgument(IASTInitializerClause arg) {
@Override
public void setArgument(IASTInitializerClause arg) {
assertNotFrozen();
subscriptExp = arg;
if (arg != null) {
@ -94,19 +100,22 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
}
}
@Deprecated
@Override
@Deprecated
public IASTExpression getSubscriptExpression() {
if (subscriptExp instanceof IASTExpression)
return (IASTExpression) subscriptExp;
return null;
}
@Deprecated
@Override
@Deprecated
public void setSubscriptExpression(IASTExpression expression) {
setArgument(expression);
}
public IASTImplicitName[] getImplicitNames() {
@Override
public IASTImplicitName[] getImplicitNames() {
if (implicitNames == null) {
ICPPFunction overload = getOverload();
if (overload == null || overload instanceof CPPImplicitFunction)
@ -128,7 +137,6 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
return implicitNames;
}
public ICPPFunction getOverload() {
if (overload == UNINITIALIZED_FUNCTION) {
overload= null;
@ -174,7 +182,8 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
return true;
}
public void replace(IASTNode child, IASTNode other) {
@Override
public void replace(IASTNode child, IASTNode other) {
if (child == subscriptExp) {
other.setPropertyInParent(child.getPropertyInParent());
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();
if (op != null) {
return ExpressionTypes.typeFromFunctionCall(op);
@ -216,10 +226,12 @@ public class CPPASTArraySubscriptExpression extends ASTNode implements ICPPASTAr
return new ProblemType(ISemanticProblem.TYPE_UNKNOWN_FOR_EXPRESSION);
}
@Override
public boolean isLValue() {
return getValueCategory() == LVALUE;
}
@Override
public ValueCategory getValueCategory() {
ICPPFunction op = getOverload();
if (op != null) {

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
* John Camelon (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
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
*/
public class CPPASTPointer extends ASTNode implements IASTPointer {
private boolean isConst;
private boolean isVolatile;
private boolean isRestrict;
@ -27,10 +26,12 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
public CPPASTPointer() {
}
public CPPASTPointer copy() {
@Override
public CPPASTPointer copy() {
return copy(CopyStyle.withoutLocations);
}
@Override
public CPPASTPointer copy(CopyStyle style) {
CPPASTPointer copy = new CPPASTPointer();
copy.isConst = isConst;
@ -43,29 +44,35 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
return copy;
}
public boolean isConst() {
@Override
public boolean isConst() {
return isConst;
}
public boolean isVolatile() {
@Override
public boolean isVolatile() {
return isVolatile;
}
public boolean isRestrict() {
@Override
public boolean isRestrict() {
return isRestrict;
}
public void setConst(boolean value) {
@Override
public void setConst(boolean value) {
assertNotFrozen();
isConst = value;
}
public void setVolatile(boolean value) {
@Override
public void setVolatile(boolean value) {
assertNotFrozen();
isVolatile = value;
}
public void setRestrict(boolean value) {
@Override
public void setRestrict(boolean value) {
assertNotFrozen();
isRestrict = value;
}
@ -74,8 +81,8 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
public boolean accept(ASTVisitor action) {
if (action.shouldVisitPointerOperators) {
switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
case ASTVisitor.PROCESS_ABORT: return false;
case ASTVisitor.PROCESS_SKIP: return true;
}
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;

View file

@ -460,7 +460,7 @@ public class ChangeGenerator extends ASTVisitor {
IFile file = FileHelper.getFileFromNode(anchorNode);
MultiTextEdit parentEdit = getEdit(anchorNode, file);
parentEdit.addChild(edit);
sourceOffsets.put(file.getName(), Integer.valueOf(edit.getOffset()));
sourceOffsets.put(file.getName(), edit.getOffset());
}
private void handleReplace(IASTNode node) {
@ -469,10 +469,13 @@ public class ChangeGenerator extends ASTVisitor {
TextEdit edit;
ChangeGeneratorWriterVisitor writer =
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) {
int offset = getOffsetIncludingComments(node);
int endOffset = getEndOffsetIncludingComments(node);
offset = skipPrecedingBlankLines(source, offset);
offset = Math.max(skipPrecedingBlankLines(source, offset), processedOffset);
endOffset = skipTrailingBlankLines(source, endOffset);
IASTNode[] siblingsList = getContainingNodeList(node);
if (siblingsList != null) {
@ -500,9 +503,8 @@ public class ChangeGenerator extends ASTVisitor {
} else {
node.accept(writer);
String code = writer.toString();
IASTFileLocation location = node.getFileLocation();
int offset = location.getNodeOffset();
int endOffset = offset + location.getNodeLength();
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));
@ -517,9 +519,7 @@ public class ChangeGenerator extends ASTVisitor {
MultiTextEdit parentEdit = getEdit(node, file);
parentEdit.addChild(edit);
IASTFileLocation fileLocation = node.getFileLocation();
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
sourceOffsets.put(fileLocation.getFileName(), edit.getExclusiveEnd());
}
private void handleAppends(IASTNode node) {
@ -553,8 +553,7 @@ public class ChangeGenerator extends ASTVisitor {
code + anchor.getText());
parentEdit.addChild(edit);
IASTFileLocation fileLocation = node.getFileLocation();
int newOffset = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
sourceOffsets.put(fileLocation.getFileName(), Integer.valueOf(newOffset));
sourceOffsets.put(fileLocation.getFileName(), endOffset(fileLocation));
}
private void handleAppends(IASTTranslationUnit tu) {

View file

@ -2512,24 +2512,60 @@ visibility=public
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
//@main.c
int main() {
int a,b;
/*$*/a = b*2;/*$$*/
int a, b;
/*$*/a = b * 2;/*$$*/
return a;
}
//=
void test(int* a, int b) {
a = b * 2;
}
int main() {
int a,b;
int a, b;
test(a, b);
return a;
}
//@.config
filename=main.c
methodname=test
replaceduplicates=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

View file

@ -1451,3 +1451,31 @@ public:
int test;
};
#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_ */

View file

@ -171,7 +171,7 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage impl
for (Object funct : funtions) {
if (funct instanceof GetterSetterInsertEditProvider) {
GetterSetterInsertEditProvider getSet = (GetterSetterInsertEditProvider) funct;
if(getSet.getType() == type) {
if (getSet.getType() == type) {
checked.add(getSet);
variableSelectionView.setChecked(getSet, true);
}

View file

@ -173,7 +173,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
private IASTCompositeTypeSpecifier getCompositeTypeSpecifier(IASTName selectedName) {
IASTNode node = selectedName;
while(node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
while (node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
node = node.getParent();
}
return (IASTCompositeTypeSpecifier) node;
@ -181,7 +181,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
private IASTName getSelectedName(IASTTranslationUnit ast) {
List<IASTName> names = findAllMarkedNames(ast);
if (names.size() < 1) {
if (names.isEmpty()) {
return null;
}
return names.get(names.size() - 1);

View file

@ -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.IASTName;
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;
@ -45,7 +54,7 @@ public class GetterSetterContext implements ITreeContentProvider {
if (!wrapper.getter.exists()) {
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));
}
}
@ -55,12 +64,12 @@ public class GetterSetterContext implements ITreeContentProvider {
}
public GetterSetterInsertEditProvider createGetterInserter(IASTSimpleDeclaration simpleDeclaration) {
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
IASTName fieldName = getDeclarationName(simpleDeclaration);
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.GETTER);
}
public GetterSetterInsertEditProvider createSetterInserter(IASTSimpleDeclaration simpleDeclaration) {
IASTName fieldName = getFieldDeclarationName(simpleDeclaration);
IASTName fieldName = getDeclarationName(simpleDeclaration);
return new GetterSetterInsertEditProvider(fieldName, simpleDeclaration, AccessorKind.SETTER);
}
@ -115,11 +124,11 @@ public class GetterSetterContext implements ITreeContentProvider {
private ArrayList<FieldWrapper> getWrappedFields() {
if (wrappedFields == null) {
wrappedFields = new ArrayList<FieldWrapper>();
for (IASTSimpleDeclaration currentField : existingFields) {
for (IASTSimpleDeclaration field : existingFields) {
FieldWrapper wrapper = new FieldWrapper();
wrapper.field = currentField;
wrapper.getter = getGetterForField(currentField);
wrapper.setter = getSetterForField(currentField);
wrapper.field = field;
wrapper.getter = getGetterForField(field);
wrapper.setter = getSetterForField(field);
if (wrapper.missingGetterOrSetter()) {
wrappedFields.add(wrapper);
}
@ -130,35 +139,52 @@ public class GetterSetterContext implements ITreeContentProvider {
private FunctionWrapper getGetterForField(IASTSimpleDeclaration currentField) {
FunctionWrapper wrapper = new FunctionWrapper();
String name = GetterSetterNameGenerator.generateGetterName(getFieldDeclarationName(currentField));
String name = GetterSetterNameGenerator.generateGetterName(getDeclarationName(currentField));
setFunctionToWrapper(wrapper, name);
return wrapper;
}
private IASTName getFieldDeclarationName(IASTSimpleDeclaration fieldDeclaration) {
IASTDeclarator declarator = fieldDeclaration.getDeclarators()[0];
private FunctionWrapper getSetterForField(IASTSimpleDeclaration field) {
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) {
declarator = declarator.getNestedDeclarator();
}
return declarator.getName();
}
private FunctionWrapper getSetterForField(IASTSimpleDeclaration currentField) {
FunctionWrapper wrapper = new FunctionWrapper();
String name = GetterSetterNameGenerator.generateSetterName(getFieldDeclarationName(currentField));
setFunctionToWrapper(wrapper, name);
return wrapper;
private static boolean isAssignable(IASTSimpleDeclaration declaration) {
IASTName name = getDeclarationName(declaration);
IBinding binding = name.resolveBinding();
if (!(binding instanceof ICPPField))
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) {
if (currentDefinition.getDeclarator().getName().toString().endsWith(getterName)) {
if (currentDefinition.getDeclarator().getName().toString().equals(accessorName)) {
wrapper.functionDefinition = currentDefinition;
}
}
for (IASTSimpleDeclaration currentDeclaration : existingFunctionDeclarations) {
if (getFieldDeclarationName(currentDeclaration).toString().endsWith(getterName)) {
if (getDeclarationName(currentDeclaration).toString().equals(accessorName)) {
wrapper.functionDeclaration = currentDeclaration;
}
}

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
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.IASTDeclSpecifier;
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.IASTSimpleDeclaration;
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.rewrite.TypeHelper;
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.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.CPPASTFieldReference;
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.CPPASTName;
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.CPPASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
@ -90,6 +96,17 @@ public class GetterSetterFactory {
// Copy declarator hierarchy
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
IASTDeclarator innermost = topDeclarator;
while (innermost.getNestedDeclarator() != null) {
@ -203,7 +220,7 @@ public class GetterSetterFactory {
private IASTDeclSpecifier getParamOrReturnDeclSpecifier() {
IASTDeclSpecifier declSpec = fieldDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations);
if (passByReference) {
if (passByReference || fieldDeclaration.getDeclarators()[0] instanceof IASTArrayDeclarator) {
declSpec.setConst(true);
}
return declSpec;