mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Replace usage of ASTSignatureUtil by ASTStringUtil.
This commit is contained in:
parent
358955dd13
commit
4adeb3cefb
12 changed files with 557 additions and 139 deletions
|
@ -21,7 +21,6 @@ import java.util.List;
|
|||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
|
@ -33,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||
|
@ -86,6 +86,7 @@ import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
|
||||
|
||||
|
@ -357,29 +358,32 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected void isExpressionStringEqual(IASTInitializerClause exp, String str) {
|
||||
String expressionString = ASTSignatureUtil.getExpressionString((IASTExpression) exp);
|
||||
String expressionString = ASTStringUtil.getExpressionString((IASTExpression) exp);
|
||||
assertEquals(str, expressionString);
|
||||
}
|
||||
|
||||
protected void isExpressionStringEqual(IASTExpression exp, String str) {
|
||||
String expressionString = ASTSignatureUtil.getExpressionString(exp);
|
||||
String expressionString = ASTStringUtil.getExpressionString(exp);
|
||||
assertEquals(str, expressionString);
|
||||
}
|
||||
|
||||
protected void isParameterSignatureEqual(IASTDeclarator decltor, String str) {
|
||||
assertEquals(str, ASTSignatureUtil.getParameterSignature(decltor));
|
||||
assertTrue(decltor instanceof IASTFunctionDeclarator);
|
||||
final String[] sigArray = ASTStringUtil.getParameterSignatureArray((IASTFunctionDeclarator) decltor);
|
||||
assertEquals(str, "(" + ASTStringUtil.join(sigArray, ", ") + ")");
|
||||
}
|
||||
|
||||
protected void isSignatureEqual(IASTDeclarator decltor, String str) {
|
||||
assertEquals(str, ASTSignatureUtil.getSignature(decltor));
|
||||
protected void isSignatureEqual(IASTDeclarator declarator, String expected) {
|
||||
String signature= ASTStringUtil.getSignatureString(declarator);
|
||||
assertEquals(expected, signature);
|
||||
}
|
||||
|
||||
protected void isSignatureEqual(IASTDeclSpecifier declSpec, String str) {
|
||||
assertEquals(str, ASTSignatureUtil.getSignature(declSpec));
|
||||
assertEquals(str, ASTStringUtil.getSignatureString(declSpec, null));
|
||||
}
|
||||
|
||||
protected void isSignatureEqual(IASTTypeId typeId, String str) {
|
||||
assertEquals(str, ASTSignatureUtil.getSignature(typeId));
|
||||
assertEquals(str, ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator()));
|
||||
}
|
||||
|
||||
protected void isTypeEqual(IASTDeclarator decltor, String str) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Iterator;
|
|||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
|
@ -179,7 +178,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
public void testBug75340() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings( "void f(int i = 0, int * p = 0);"); //$NON-NLS-1$
|
||||
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals( ASTSignatureUtil.getParameterSignature( sd.getDeclarators()[0] ), "(int, int *)" ); //$NON-NLS-1$
|
||||
isParameterSignatureEqual( sd.getDeclarators()[0], "(int=0, int*=0)" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// #define REF_WRAP(e) class A { public: A (){ } A& foo2(e& v) { return *this; } }
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.io.IOException;
|
|||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.ExpansionOverlapsBoundaryException;
|
||||
|
@ -117,6 +116,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
/**
|
||||
|
@ -150,7 +150,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
public void testBug75340() throws Exception {
|
||||
IASTTranslationUnit tu = parseAndCheckBindings("void f(int i = 0, int * p = 0);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals(ASTSignatureUtil.getParameterSignature(sd.getDeclarators()[0]), "(int, int *)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(sd.getDeclarators()[0], "(int=0, int*=0)"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// int *p1; int *p2;
|
||||
|
@ -5444,7 +5444,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
buf.append(',');
|
||||
polnishNotation(bexpr.getOperand2(), buf);
|
||||
buf.append(',');
|
||||
buf.append(ASTSignatureUtil.getBinaryOperatorString(bexpr));
|
||||
buf.append(ASTStringUtil.getBinaryOperatorString(bexpr));
|
||||
} else if (expr instanceof IASTCastExpression) {
|
||||
IASTCastExpression castExpr= (IASTCastExpression) expr;
|
||||
buf.append(castExpr.getTypeId().getRawSignature());
|
||||
|
@ -5479,13 +5479,13 @@ public class AST2Tests extends AST2BaseTest {
|
|||
case IASTUnaryExpression.op_minus:
|
||||
case IASTUnaryExpression.op_star:
|
||||
buf.append(",unary");
|
||||
buf.append(ASTSignatureUtil.getUnaryOperatorString(unaryExpr));
|
||||
buf.append(ASTStringUtil.getUnaryOperatorString(unaryExpr));
|
||||
break;
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
break;
|
||||
default:
|
||||
buf.append(',');
|
||||
buf.append(ASTSignatureUtil.getUnaryOperatorString(unaryExpr));
|
||||
buf.append(ASTStringUtil.getUnaryOperatorString(unaryExpr));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -146,7 +146,7 @@ public class AST2UtilOldTests extends AST2BaseTest {
|
|||
public void testPostfixDynamicCast() throws Exception{
|
||||
IASTTranslationUnit tu = parse("int x = foo( dynamic_cast<B*>(a) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
|
||||
IASTDeclaration[] d = tu.getDeclarations();
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(dynamic_cast<B *>(a))" ); //$NON-NLS-1$
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(dynamic_cast<B*>(a))" ); //$NON-NLS-1$
|
||||
}
|
||||
// Kind POSTFIX_REINTERPRET_CAST
|
||||
public void testPostfixReinterpretCast() throws Exception{
|
||||
|
@ -183,7 +183,7 @@ public class AST2UtilOldTests extends AST2BaseTest {
|
|||
public void testPostfixTypeIdTypeId2() throws Exception{
|
||||
IASTTranslationUnit tu = parse("class A { }; int foo( int ); int x = foo( typeid(const A) );".toString(), ParserLanguage.CPP); //$NON-NLS-1$
|
||||
IASTDeclaration[] d = tu.getDeclarations();
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(typeid (const A))" ); //$NON-NLS-1$
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo(typeid(const A))" ); //$NON-NLS-1$
|
||||
}
|
||||
// Kind UNARY_INCREMENT : LHS
|
||||
public void testUnaryIncrement() throws Exception
|
||||
|
@ -261,7 +261,7 @@ public class AST2UtilOldTests extends AST2BaseTest {
|
|||
public void testCastExpression() throws Exception{
|
||||
IASTTranslationUnit tu = parse("int x = foo( (A*)b );".toString(), ParserLanguage.C); //$NON-NLS-1$
|
||||
IASTDeclaration[] d = tu.getDeclarations();
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo((A *)b)" ); //$NON-NLS-1$
|
||||
isExpressionStringEqual( ((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause(), "foo((A*)b)" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// Kind MULTIPLICATIVE_MULTIPLY : usual arithmetic conversions
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
|
@ -22,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ public class AST2UtilTests extends AST2BaseTest {
|
|||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[1]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ? m : n"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[2]).getDeclarators()[0].getInitializer()).getInitializerClause(), "l ^ m"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[3]).getDeclarators()[0].getInitializer()).getInitializerClause(), "i <<= j"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof (int)"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[4]).getDeclarators()[0].getInitializer()).getInitializerClause(), "sizeof(int)"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[5]).getDeclarators()[0].getInitializer()).getInitializerClause(), "~f"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause(), "++e"); //$NON-NLS-1$
|
||||
isExpressionStringEqual(((IASTEqualsInitializer)((IASTSimpleDeclaration)d[7]).getDeclarators()[0].getInitializer()).getInitializerClause(), "d++"); //$NON-NLS-1$
|
||||
|
@ -76,20 +76,20 @@ public class AST2UtilTests extends AST2BaseTest {
|
|||
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "(int)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "(char, int)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float * *)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int [restrict])"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "(const char * const)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int*, float**)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int[])"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "(const char* const)"); //$NON-NLS-1$
|
||||
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "int (int)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "int *(char, int)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "void (int *, float * *)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "static int (int [restrict])"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "void (const char * const)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "int(int)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "int*(char, int)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "void(int*, float**)"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "int(int[])"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclarators()[0], "void(const char* const)"); //$NON-NLS-1$
|
||||
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclSpecifier(), "int"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclSpecifier(), "int"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclSpecifier(), "void"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclSpecifier(), "static int"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclSpecifier(), "int"); //$NON-NLS-1$
|
||||
isSignatureEqual(((IASTSimpleDeclaration)d[4]).getDeclSpecifier(), "void"); //$NON-NLS-1$
|
||||
|
||||
isTypeEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "int (int)"); //$NON-NLS-1$
|
||||
|
@ -123,8 +123,8 @@ public class AST2UtilTests extends AST2BaseTest {
|
|||
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[0]).getDeclarators()[0], "(int)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[1]).getDeclarators()[0], "(char, int)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int *, float * *)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int [restrict])"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[2]).getDeclarators()[0], "(int*, float**)"); //$NON-NLS-1$
|
||||
isParameterSignatureEqual(((IASTSimpleDeclaration)d[3]).getDeclarators()[0], "(int[])"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testSimpleTypeId() throws Exception {
|
||||
|
@ -142,7 +142,7 @@ public class AST2UtilTests extends AST2BaseTest {
|
|||
|
||||
// verify signatures
|
||||
isSignatureEqual( ((IASTTypeIdExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[0]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId(), "int"); //$NON-NLS-1$
|
||||
isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "Squaw"); //$NON-NLS-1$
|
||||
isSignatureEqual( ((IASTTypeIdExpression)((IASTReturnStatement)((IASTCompoundStatement)((IASTFunctionDefinition)d[2]).getBody()).getStatements()[0]).getReturnValue()).getTypeId(), "union Squaw"); //$NON-NLS-1$
|
||||
isSignatureEqual( ((IASTCastExpression)((IASTEqualsInitializer)((IASTSimpleDeclaration)d[6]).getDeclarators()[0].getInitializer()).getInitializerClause()).getTypeId() , "jc"); //$NON-NLS-1$
|
||||
|
||||
// verify types
|
||||
|
@ -159,8 +159,8 @@ public class AST2UtilTests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(buff.toString(), ParserLanguage.C, true);
|
||||
IASTDeclaration[] d = tu.getDeclarations();
|
||||
|
||||
String fooSignature = ASTSignatureUtil.getSignature(((IASTFunctionDefinition)d[0]).getDeclarator());
|
||||
String foo2Signature = ASTSignatureUtil.getSignature(((IASTFunctionDefinition)d[1]).getDeclarator());
|
||||
String fooSignature = ASTStringUtil.getSignatureString(((IASTFunctionDefinition)d[0]).getDeclarator());
|
||||
String foo2Signature = ASTStringUtil.getSignatureString(((IASTFunctionDefinition)d[1]).getDeclarator());
|
||||
|
||||
assertEquals(fooSignature, foo2Signature);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
||||
|
@ -29,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
|||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CASTFunctionDefinition;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
|
||||
/**
|
||||
|
@ -90,12 +90,12 @@ public class GCCCompleteParseExtensionsTest extends AST2BaseTest {
|
|||
public void testBug39698A() throws Exception
|
||||
{
|
||||
IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a <? b;").getDeclarations(); //$NON-NLS-1$
|
||||
assertEquals( ASTSignatureUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a <? b" ); //$NON-NLS-1$
|
||||
assertEquals( ASTStringUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a <? b" ); //$NON-NLS-1$
|
||||
}
|
||||
public void testBug39698B() throws Exception
|
||||
{
|
||||
IASTDeclaration[] decls = parseGPP("int a=0; \n int b=1; \n int c = a >? b;").getDeclarations(); //$NON-NLS-1$
|
||||
assertEquals( ASTSignatureUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a >? b" ); //$NON-NLS-1$
|
||||
assertEquals( ASTStringUtil.getExpressionString( (IASTExpression) ((IASTEqualsInitializer)((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getInitializer()).getInitializerClause() ), "a >? b" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testPredefinedSymbol_bug69791() throws Exception {
|
||||
|
|
|
@ -11,10 +11,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
|
@ -23,6 +26,8 @@ import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
|
@ -40,14 +45,21 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPackExpansionExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
@ -58,21 +70,25 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
|
||||
|
||||
/**
|
||||
* This is a utility class to help convert AST elements to Strings.
|
||||
*
|
||||
* @see org.eclipse.cdt.core.dom.ast.ASTSignatureUtil
|
||||
* @see org.eclipse.cdt.core.dom.ast.ASTTypeUtil
|
||||
*/
|
||||
|
||||
public class ASTStringUtil {
|
||||
|
||||
private static final String SPACE= " "; //$NON-NLS-1$
|
||||
private static final String COMMA_SPACE= ", "; //$NON-NLS-1$
|
||||
private static final String[] EMPTY_STRING_ARRAY= new String[0];
|
||||
|
||||
|
@ -99,10 +115,6 @@ public class ASTStringUtil {
|
|||
|
||||
/**
|
||||
* Compute a signature string with parameters, without initializers.
|
||||
*
|
||||
* @param declarator
|
||||
* @return the type string
|
||||
* @see ASTSignatureUtil#getSignature(IASTDeclarator)
|
||||
*/
|
||||
public static String getSignatureString(IASTDeclarator declarator) {
|
||||
return trimRight(appendSignatureString(new StringBuilder(), declarator)).toString();
|
||||
|
@ -140,8 +152,6 @@ public class ASTStringUtil {
|
|||
*
|
||||
* @param functionDeclarator
|
||||
* @return the parameter signature array
|
||||
*
|
||||
* @see ASTSignatureUtil#getParameterSignatureArray(IASTDeclarator)
|
||||
*/
|
||||
public static String[] getParameterSignatureArray(IASTFunctionDeclarator functionDeclarator) {
|
||||
if (functionDeclarator instanceof IASTStandardFunctionDeclarator) {
|
||||
|
@ -193,6 +203,19 @@ public class ASTStringUtil {
|
|||
return parameterTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for the given expression
|
||||
*/
|
||||
public static String getExpressionString(IASTExpression expression) {
|
||||
StringBuilder buf= new StringBuilder();
|
||||
return appendExpressionString(buf, expression).toString();
|
||||
}
|
||||
|
||||
public static String getInitializerString(IASTInitializer init) {
|
||||
StringBuilder buf= new StringBuilder();
|
||||
return appendInitializerString(buf, init).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins strings together using a given delimiter.
|
||||
* @param strings the strings to join.
|
||||
|
@ -364,12 +387,14 @@ public class ASTStringUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
private static void appendInitClauseString(StringBuilder buffer, IASTInitializerClause initializerClause) {
|
||||
private static StringBuilder appendInitClauseString(StringBuilder buffer, IASTInitializerClause initializerClause) {
|
||||
if (initializerClause instanceof IASTExpression) {
|
||||
appendExpressionString(buffer, (IASTExpression) initializerClause);
|
||||
} else if (initializerClause instanceof IASTInitializer) {
|
||||
appendInitializerString(buffer, (IASTInitializer) initializerClause);
|
||||
return appendExpressionString(buffer, (IASTExpression) initializerClause);
|
||||
}
|
||||
if (initializerClause instanceof IASTInitializer) {
|
||||
return appendInitializerString(buffer, (IASTInitializer) initializerClause);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendTypeIdString(StringBuilder buffer, IASTTypeId typeId) {
|
||||
|
@ -452,6 +477,7 @@ public class ASTStringUtil {
|
|||
trimRight(buffer);
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
} else if (functionDeclarator instanceof ICASTKnRFunctionDeclarator) {
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
final ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)functionDeclarator;
|
||||
final IASTName[] names= knrDeclarator.getParameterNames();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
|
@ -465,6 +491,8 @@ public class ASTStringUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
trimRight(buffer);
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
@ -487,9 +515,9 @@ public class ASTStringUtil {
|
|||
if (declSpecifier.isConst()) {
|
||||
buffer.append(Keywords.CONST).append(' ');
|
||||
}
|
||||
// if (declSpecifier.isVolatile()) {
|
||||
// buffer.append(Keywords.VOLATILE).append(' ');
|
||||
// }
|
||||
if (declSpecifier.isVolatile()) {
|
||||
buffer.append(Keywords.VOLATILE).append(' ');
|
||||
}
|
||||
// if (declSpecifier.isInline()) {
|
||||
// buffer.append(Keywords.INLINE).append(' ');
|
||||
// }
|
||||
|
@ -688,34 +716,6 @@ public class ASTStringUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendExpressionString(StringBuilder buffer, IASTExpression expression) {
|
||||
if (expression instanceof IASTIdExpression) {
|
||||
final IASTIdExpression idExpression= (IASTIdExpression)expression;
|
||||
appendQualifiedNameString(buffer, idExpression.getName());
|
||||
} else if (expression instanceof IASTExpressionList) {
|
||||
final IASTExpressionList expressionList= (IASTExpressionList)expression;
|
||||
final IASTExpression[] expressions= expressionList.getExpressions();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
appendExpressionString(buffer, expressions[i]);
|
||||
}
|
||||
} else if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
|
||||
final ICPPASTSimpleTypeConstructorExpression typeCast= (ICPPASTSimpleTypeConstructorExpression)expression;
|
||||
appendDeclSpecifierString(buffer, typeCast.getDeclSpecifier());
|
||||
final IASTInitializer init= typeCast.getInitializer();
|
||||
if (init != null) {
|
||||
appendInitializerString(buffer, init);
|
||||
}
|
||||
} else if (expression instanceof IASTLiteralExpression) {
|
||||
buffer.append(ASTSignatureUtil.getExpressionString(expression));
|
||||
} else if (expression != null) {
|
||||
buffer.append(ASTSignatureUtil.getExpressionString(expression));
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendTemplateParameterString(StringBuilder buffer, ICPPASTTemplateParameter parameter) {
|
||||
if (parameter instanceof ICPPASTParameterDeclaration) {
|
||||
appendParameterDeclarationString(buffer, (ICPPASTParameterDeclaration)parameter);
|
||||
|
@ -751,4 +751,383 @@ public class ASTStringUtil {
|
|||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendExpressionString(StringBuilder buffer, IASTExpression expression) {
|
||||
if (expression instanceof IASTIdExpression) {
|
||||
final IASTIdExpression idExpression= (IASTIdExpression)expression;
|
||||
return appendQualifiedNameString(buffer, idExpression.getName());
|
||||
}
|
||||
if (expression instanceof IASTExpressionList) {
|
||||
final IASTExpressionList expressionList= (IASTExpressionList)expression;
|
||||
final IASTExpression[] expressions= expressionList.getExpressions();
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
appendExpressionString(buffer, expressions[i]);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
if (expression instanceof ICPPASTSimpleTypeConstructorExpression) {
|
||||
final ICPPASTSimpleTypeConstructorExpression typeCast= (ICPPASTSimpleTypeConstructorExpression)expression;
|
||||
appendDeclSpecifierString(buffer, typeCast.getDeclSpecifier());
|
||||
trimRight(buffer);
|
||||
return appendInitializerString(buffer, typeCast.getInitializer());
|
||||
}
|
||||
if (expression instanceof IASTArraySubscriptExpression)
|
||||
return appendArraySubscriptExpression(buffer, (IASTArraySubscriptExpression) expression);
|
||||
if (expression instanceof IASTBinaryExpression)
|
||||
return appendBinaryExpression(buffer, (IASTBinaryExpression) expression);
|
||||
if (expression instanceof IASTCastExpression)
|
||||
return appendCastExpression(buffer, (IASTCastExpression) expression);
|
||||
if (expression instanceof IASTConditionalExpression)
|
||||
return appendConditionalExpression(buffer, (IASTConditionalExpression) expression);
|
||||
if (expression instanceof IASTExpressionList)
|
||||
return appendExpressionList(buffer, (IASTExpressionList) expression);
|
||||
if (expression instanceof IASTFieldReference)
|
||||
return appendFieldReference(buffer, (IASTFieldReference) expression);
|
||||
if (expression instanceof IASTFunctionCallExpression)
|
||||
return appendFunctionCallExpression(buffer, (IASTFunctionCallExpression) expression);
|
||||
if (expression instanceof IASTLiteralExpression)
|
||||
return appendLiteralExpression(buffer, (IASTLiteralExpression) expression);
|
||||
if (expression instanceof IASTTypeIdExpression)
|
||||
return appendTypeIdExpression(buffer, (IASTTypeIdExpression) expression);
|
||||
if (expression instanceof IASTUnaryExpression)
|
||||
return appendUnaryExpression(buffer, (IASTUnaryExpression) expression);
|
||||
if (expression instanceof ICASTTypeIdInitializerExpression)
|
||||
return appendTypeIdInitializerExpression(buffer, (ICASTTypeIdInitializerExpression) expression);
|
||||
if (expression instanceof ICPPASTDeleteExpression)
|
||||
return appendDeleteExpression(buffer, (ICPPASTDeleteExpression) expression);
|
||||
if (expression instanceof ICPPASTNewExpression)
|
||||
return appendNewExpression(buffer, (ICPPASTNewExpression) expression);
|
||||
if (expression instanceof IGNUASTCompoundStatementExpression)
|
||||
return appendCompoundStatementExpression(buffer, (IGNUASTCompoundStatementExpression) expression);
|
||||
if (expression instanceof ICPPASTPackExpansionExpression)
|
||||
return appendPackExpansionExpression(buffer, (ICPPASTPackExpansionExpression) expression);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendArraySubscriptExpression(StringBuilder buffer, IASTArraySubscriptExpression expression) {
|
||||
appendExpressionString(buffer, expression.getArrayExpression());
|
||||
buffer.append(Keywords.cpLBRACKET);
|
||||
appendInitClauseString(buffer, expression.getArgument());
|
||||
return buffer.append(Keywords.cpRBRACKET);
|
||||
}
|
||||
|
||||
private static StringBuilder appendCastExpression(StringBuilder buffer, IASTCastExpression expression) {
|
||||
if ((expression.getOperator() == IASTCastExpression.op_cast)) {
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
appendTypeIdString(buffer, expression.getTypeId());
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
return appendExpressionString(buffer, expression.getOperand());
|
||||
}
|
||||
|
||||
buffer.append(getCastOperatorString(expression));
|
||||
buffer.append(Keywords.cpLT);
|
||||
appendTypeIdString(buffer, expression.getTypeId());
|
||||
trimRight(buffer);
|
||||
buffer.append(Keywords.cpGT);
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
appendExpressionString(buffer, expression.getOperand());
|
||||
return buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
|
||||
private static StringBuilder appendFieldReference(StringBuilder buffer, IASTFieldReference expression) {
|
||||
appendExpressionString(buffer, expression.getFieldOwner());
|
||||
buffer.append(expression.isPointerDereference() ? Keywords.cpARROW : Keywords.cpDOT);
|
||||
|
||||
return appendNameString(buffer, expression.getFieldName(), true);
|
||||
}
|
||||
|
||||
private static StringBuilder appendFunctionCallExpression(StringBuilder buffer, IASTFunctionCallExpression expression) {
|
||||
appendExpressionString(buffer, expression.getFunctionNameExpression());
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
IASTInitializerClause[] clauses = expression.getArguments();
|
||||
for (int i= 0; i < clauses.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
appendInitClauseString(buffer, (clauses[i]));
|
||||
}
|
||||
return buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
|
||||
private static StringBuilder appendTypeIdInitializerExpression(StringBuilder buffer, ICASTTypeIdInitializerExpression expression) {
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
appendTypeIdString(buffer, expression.getTypeId());
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
return appendInitializerString(buffer, expression.getInitializer());
|
||||
}
|
||||
|
||||
private static StringBuilder appendDeleteExpression(StringBuilder buffer, ICPPASTDeleteExpression expression) {
|
||||
buffer.append(Keywords.DELETE);
|
||||
buffer.append(SPACE);
|
||||
return appendExpressionString(buffer, expression.getOperand());
|
||||
}
|
||||
|
||||
private static StringBuilder appendCompoundStatementExpression(StringBuilder buffer, IGNUASTCompoundStatementExpression expression) {
|
||||
buffer.append(Keywords.cpLPAREN).append(Keywords.cpLBRACE);
|
||||
buffer.append(Keywords.cpELLIPSIS);
|
||||
return buffer.append(Keywords.cpRBRACE).append(Keywords.cpRPAREN);
|
||||
}
|
||||
|
||||
private static StringBuilder appendTypeIdExpression(StringBuilder buffer, IASTTypeIdExpression expression) {
|
||||
buffer.append(getTypeIdExpressionOperator(expression));
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
appendTypeIdString(buffer, expression.getTypeId());
|
||||
trimRight(buffer);
|
||||
return buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
|
||||
private static StringBuilder appendExpressionList(StringBuilder buffer, IASTExpressionList expression) {
|
||||
IASTExpression[] exps = expression.getExpressions();
|
||||
if (exps != null) {
|
||||
for (int i = 0; i < exps.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
appendExpressionString(buffer, exps[i]);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendLiteralExpression(StringBuilder buffer, IASTLiteralExpression expression) {
|
||||
return buffer.append(expression.toString());
|
||||
}
|
||||
|
||||
private static StringBuilder appendConditionalExpression(StringBuilder buffer, IASTConditionalExpression expression) {
|
||||
appendExpressionString(buffer, expression.getLogicalConditionExpression());
|
||||
buffer.append(SPACE);
|
||||
buffer.append(Keywords.cpQUESTION);
|
||||
buffer.append(SPACE);
|
||||
appendExpressionString(buffer, expression.getPositiveResultExpression());
|
||||
buffer.append(SPACE);
|
||||
buffer.append(Keywords.cpCOLON);
|
||||
buffer.append(SPACE);
|
||||
return appendExpressionString(buffer, expression.getNegativeResultExpression());
|
||||
}
|
||||
|
||||
private static StringBuilder appendNewExpression(StringBuilder buffer, ICPPASTNewExpression expression) {
|
||||
buffer.append(Keywords.NEW);
|
||||
buffer.append(SPACE);
|
||||
final IASTInitializerClause[] args = expression.getPlacementArguments();
|
||||
if (args != null) {
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (i != 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
appendInitClauseString(buffer, args[i]);
|
||||
}
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
appendTypeIdString(buffer, expression.getTypeId());
|
||||
return appendInitializerString(buffer, expression.getInitializer());
|
||||
}
|
||||
|
||||
private static StringBuilder appendBinaryExpression(StringBuilder buffer, IASTBinaryExpression expression) {
|
||||
appendExpressionString(buffer, expression.getOperand1());
|
||||
buffer.append(SPACE);
|
||||
buffer.append(getBinaryOperatorString(expression));
|
||||
buffer.append(SPACE);
|
||||
return appendExpressionString(buffer, expression.getOperand2());
|
||||
}
|
||||
|
||||
private static StringBuilder appendUnaryExpression(StringBuilder buffer, IASTUnaryExpression expression) {
|
||||
boolean postOperator = false;
|
||||
boolean primaryBracketed = false;
|
||||
|
||||
switch (expression.getOperator()) {
|
||||
case IASTUnaryExpression.op_postFixDecr:
|
||||
case IASTUnaryExpression.op_postFixIncr:
|
||||
postOperator = true;
|
||||
break;
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
primaryBracketed = true;
|
||||
break;
|
||||
default:
|
||||
postOperator = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!postOperator && !primaryBracketed)
|
||||
buffer.append(getUnaryOperatorString(expression));
|
||||
|
||||
// need to add a space to the unary expression if it is a specific operator
|
||||
switch (expression.getOperator()) {
|
||||
case IASTUnaryExpression.op_sizeof:
|
||||
case ICPPASTUnaryExpression.op_throw:
|
||||
case ICPPASTUnaryExpression.op_typeid:
|
||||
buffer.append(SPACE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (primaryBracketed)
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
buffer.append(getExpressionString(expression.getOperand()));
|
||||
if (primaryBracketed)
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
if (postOperator && !primaryBracketed)
|
||||
buffer.append(getUnaryOperatorString(expression));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static String getCastOperatorString(IASTCastExpression expression) {
|
||||
int op = expression.getOperator();
|
||||
switch (op) {
|
||||
case ICPPASTCastExpression.op_const_cast:
|
||||
return Keywords.CONST_CAST;
|
||||
case ICPPASTCastExpression.op_dynamic_cast:
|
||||
return Keywords.DYNAMIC_CAST;
|
||||
case ICPPASTCastExpression.op_reinterpret_cast:
|
||||
return Keywords.REINTERPRET_CAST;
|
||||
case ICPPASTCastExpression.op_static_cast:
|
||||
return Keywords.STATIC_CAST;
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of the IASTUnaryExpression's operator.
|
||||
*
|
||||
* @param ue
|
||||
* @return the String representation of the IASTUnaryExpression's operator
|
||||
*/
|
||||
public static char[] getUnaryOperatorString(IASTUnaryExpression ue) {
|
||||
int op = ue.getOperator();
|
||||
switch (op) {
|
||||
case IASTUnaryExpression.op_throw:
|
||||
return Keywords.cTHROW;
|
||||
case IASTUnaryExpression.op_typeid:
|
||||
return Keywords.cTYPEID;
|
||||
case IASTUnaryExpression.op_alignOf:
|
||||
return Keywords.cALIGNOF;
|
||||
case IASTUnaryExpression.op_amper:
|
||||
return Keywords.cpAMPER;
|
||||
case IASTUnaryExpression.op_minus:
|
||||
return Keywords.cpMINUS;
|
||||
case IASTUnaryExpression.op_not:
|
||||
return Keywords.cpNOT;
|
||||
case IASTUnaryExpression.op_plus:
|
||||
return Keywords.cpPLUS;
|
||||
case IASTUnaryExpression.op_postFixDecr:
|
||||
case IASTUnaryExpression.op_prefixDecr:
|
||||
return Keywords.cpDECR;
|
||||
case IASTUnaryExpression.op_postFixIncr:
|
||||
case IASTUnaryExpression.op_prefixIncr:
|
||||
return Keywords.cpINCR;
|
||||
case IASTUnaryExpression.op_sizeof:
|
||||
return Keywords.cSIZEOF;
|
||||
case IASTUnaryExpression.op_sizeofParameterPack:
|
||||
return Keywords.cSIZEOFPACK;
|
||||
case IASTUnaryExpression.op_star:
|
||||
return Keywords.cpSTAR;
|
||||
case IASTUnaryExpression.op_tilde:
|
||||
return Keywords.cpCOMPL;
|
||||
}
|
||||
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the char[] representation of the IASTBinaryExpression's operator.
|
||||
*/
|
||||
public static char[] getBinaryOperatorString(IASTBinaryExpression be) {
|
||||
switch (be.getOperator()) {
|
||||
case IASTBinaryExpression.op_multiply:
|
||||
return Keywords.cpSTAR;
|
||||
case IASTBinaryExpression.op_divide:
|
||||
return Keywords.cpDIV;
|
||||
case IASTBinaryExpression.op_modulo:
|
||||
return Keywords.cpMOD;
|
||||
case IASTBinaryExpression.op_plus:
|
||||
return Keywords.cpPLUS;
|
||||
case IASTBinaryExpression.op_minus:
|
||||
return Keywords.cpMINUS;
|
||||
case IASTBinaryExpression.op_shiftLeft:
|
||||
return Keywords.cpSHIFTL;
|
||||
case IASTBinaryExpression.op_shiftRight:
|
||||
return Keywords.cpSHIFTR;
|
||||
case IASTBinaryExpression.op_lessThan:
|
||||
return Keywords.cpLT;
|
||||
case IASTBinaryExpression.op_greaterThan:
|
||||
return Keywords.cpGT;
|
||||
case IASTBinaryExpression.op_lessEqual:
|
||||
return Keywords.cpLTEQUAL;
|
||||
case IASTBinaryExpression.op_greaterEqual:
|
||||
return Keywords.cpGTEQUAL;
|
||||
case IASTBinaryExpression.op_binaryAnd:
|
||||
return Keywords.cpAMPER;
|
||||
case IASTBinaryExpression.op_binaryXor:
|
||||
return Keywords.cpXOR;
|
||||
case IASTBinaryExpression.op_binaryOr:
|
||||
return Keywords.cpBITOR;
|
||||
case IASTBinaryExpression.op_logicalAnd:
|
||||
return Keywords.cpAND;
|
||||
case IASTBinaryExpression.op_logicalOr:
|
||||
return Keywords.cpOR;
|
||||
case IASTBinaryExpression.op_assign:
|
||||
return Keywords.cpASSIGN;
|
||||
case IASTBinaryExpression.op_multiplyAssign:
|
||||
return Keywords.cpSTARASSIGN;
|
||||
case IASTBinaryExpression.op_divideAssign:
|
||||
return Keywords.cpDIVASSIGN;
|
||||
case IASTBinaryExpression.op_moduloAssign:
|
||||
return Keywords.cpMODASSIGN;
|
||||
case IASTBinaryExpression.op_plusAssign:
|
||||
return Keywords.cpPLUSASSIGN;
|
||||
case IASTBinaryExpression.op_minusAssign:
|
||||
return Keywords.cpMINUSASSIGN;
|
||||
case IASTBinaryExpression.op_shiftLeftAssign:
|
||||
return Keywords.cpSHIFTLASSIGN;
|
||||
case IASTBinaryExpression.op_shiftRightAssign:
|
||||
return Keywords.cpSHIFTRASSIGN;
|
||||
case IASTBinaryExpression.op_binaryAndAssign:
|
||||
return Keywords.cpAMPERASSIGN;
|
||||
case IASTBinaryExpression.op_binaryXorAssign:
|
||||
return Keywords.cpXORASSIGN;
|
||||
case IASTBinaryExpression.op_binaryOrAssign:
|
||||
return Keywords.cpBITORASSIGN;
|
||||
case IASTBinaryExpression.op_equals:
|
||||
return Keywords.cpEQUAL;
|
||||
case IASTBinaryExpression.op_notequals:
|
||||
return Keywords.cpNOTEQUAL;
|
||||
case IASTBinaryExpression.op_max:
|
||||
return Keywords.cpMAX;
|
||||
case IASTBinaryExpression.op_min:
|
||||
return Keywords.cpMIN;
|
||||
case IASTBinaryExpression.op_pmarrow:
|
||||
return Keywords.cpARROW;
|
||||
case IASTBinaryExpression.op_pmdot:
|
||||
return Keywords.cpDOT;
|
||||
}
|
||||
|
||||
return CharArrayUtils.EMPTY;
|
||||
}
|
||||
|
||||
private static String getTypeIdExpressionOperator(IASTTypeIdExpression expression) {
|
||||
switch (expression.getOperator()) {
|
||||
case IGNUASTTypeIdExpression.op_alignof:
|
||||
return Keywords.ALIGNOF;
|
||||
case IGNUASTTypeIdExpression.op_typeof:
|
||||
return Keywords.TYPEOF;
|
||||
case ICPPASTTypeIdExpression.op_typeid:
|
||||
return Keywords.TYPEID;
|
||||
case IASTTypeIdExpression.op_sizeof:
|
||||
return Keywords.SIZEOF;
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of the pack expansion expression.
|
||||
* @param buffer
|
||||
*/
|
||||
private static StringBuilder appendPackExpansionExpression(StringBuilder buffer, ICPPASTPackExpansionExpression expression) {
|
||||
appendExpressionString(buffer, expression.getPattern());
|
||||
return buffer.append(Keywords.cpELLIPSIS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Map;
|
|||
import java.util.Stack;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
|
@ -28,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -47,8 +47,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
|
@ -67,7 +67,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
|
@ -614,7 +613,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
|
||||
IASTExpression initialValue= enumDef.getValue();
|
||||
if (initialValue != null){
|
||||
element.setConstantExpression(ASTSignatureUtil.getExpressionString(initialValue));
|
||||
element.setConstantExpression(ASTStringUtil.getExpressionString(initialValue));
|
||||
}
|
||||
// add to parent
|
||||
enumarator.addChild(element);
|
||||
|
@ -781,7 +780,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
final FieldInfo fieldInfo= (FieldInfo)getElementInfo(newElement);
|
||||
if (specifier instanceof ICPPASTDeclSpecifier) {
|
||||
final ICPPASTDeclSpecifier cppSpecifier= (ICPPASTDeclSpecifier)specifier;
|
||||
fieldInfo.setMutable(cppSpecifier.getStorageClass() == ICPPASTDeclSpecifier.sc_mutable);
|
||||
fieldInfo.setMutable(cppSpecifier.getStorageClass() == IASTDeclSpecifier.sc_mutable);
|
||||
}
|
||||
fieldInfo.setTypeName(ASTStringUtil.getSignatureString(specifier, declarator));
|
||||
fieldInfo.setVisibility(getCurrentVisibility());
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
|||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
|
||||
/**
|
||||
* This is a utility class to help convert AST elements to Strings corresponding to the AST element's
|
||||
|
@ -45,7 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
|
|||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
* @deprecated The class is provided for testing purposes, only. It should not be used by clients.
|
||||
* Within CDT it is recommended to use {@link ASTSignatureUtil}, instead.
|
||||
* Within CDT it is recommended to use {@link ASTStringUtil}, instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ASTSignatureUtil {
|
||||
|
|
|
@ -117,6 +117,8 @@ public class Keywords {
|
|||
public static final char[] c_BOOL = "_Bool".toCharArray();
|
||||
public static final char[] c_COMPLEX = "_Complex".toCharArray();
|
||||
public static final char[] c_IMAGINARY = "_Imaginary".toCharArray();
|
||||
/** @since 5.3 */
|
||||
public static final char[] cALIGNOF = "alignof".toCharArray();
|
||||
public static final char[] cAND = "and".toCharArray();
|
||||
public static final char[] cAND_EQ = "and_eq".toCharArray();
|
||||
public static final char[] cASM = "asm".toCharArray();
|
||||
|
@ -176,6 +178,8 @@ public class Keywords {
|
|||
public static final char[] cSHORT = "short".toCharArray();
|
||||
public static final char[] cSIGNED = "signed".toCharArray();
|
||||
public static final char[] cSIZEOF = "sizeof".toCharArray();
|
||||
/** @since 5.3 */
|
||||
public static final char[] cSIZEOFPACK= "sizeof...".toCharArray();
|
||||
public static final char[] cSTATIC = "static".toCharArray();
|
||||
/** @since 5.2 */
|
||||
public static final char[] cSTATIC_ASSERT = STATIC_ASSERT.toCharArray();
|
||||
|
|
|
@ -62,13 +62,13 @@ import org.eclipse.ui.part.ViewPart;
|
|||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
import org.eclipse.ui.views.properties.PropertySheet;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -87,9 +87,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
@ -101,6 +101,7 @@ import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
|||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
|
@ -278,15 +279,15 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
|
||||
private void expandTreeIfNecessary(TreeItem[] tree, Object[] theExpanded) {
|
||||
for( int i=0; i<tree.length; i++) {
|
||||
for( int j=0; j<theExpanded.length; j++) {
|
||||
if (theExpanded[j] instanceof DOMASTNodeLeaf &&
|
||||
tree[i].getData() instanceof DOMASTNodeLeaf &&
|
||||
((DOMASTNodeLeaf)theExpanded[j]).toString().equals(((DOMASTNodeLeaf)tree[i].getData()).toString()) &&
|
||||
((DOMASTNodeLeaf)theExpanded[j]).getOffset() == (((DOMASTNodeLeaf)tree[i].getData()).getOffset())) {
|
||||
tree[i].setExpanded(true);
|
||||
for (TreeItem element : tree) {
|
||||
for (Object element2 : theExpanded) {
|
||||
if (element2 instanceof DOMASTNodeLeaf &&
|
||||
element.getData() instanceof DOMASTNodeLeaf &&
|
||||
((DOMASTNodeLeaf)element2).toString().equals(((DOMASTNodeLeaf)element.getData()).toString()) &&
|
||||
((DOMASTNodeLeaf)element2).getOffset() == (((DOMASTNodeLeaf)element.getData()).getOffset())) {
|
||||
element.setExpanded(true);
|
||||
viewer.refresh();
|
||||
expandTreeIfNecessary(tree[i].getItems(), theExpanded);
|
||||
expandTreeIfNecessary(element.getItems(), theExpanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -486,25 +487,25 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
|
||||
private TreeItem expandTreeToTreeObject(TreeItem[] treeItems, DOMASTNodeLeaf treeObj) {
|
||||
for (int i=0; i<treeItems.length; i++) {
|
||||
if (treeItems[i].getData() == treeObj) {
|
||||
return treeItems[i];
|
||||
for (TreeItem treeItem : treeItems) {
|
||||
if (treeItem.getData() == treeObj) {
|
||||
return treeItem;
|
||||
}
|
||||
|
||||
DOMASTNodeParent parent = treeObj.getParent();
|
||||
|
||||
if (parent == null) return null;
|
||||
|
||||
while (parent != treeItems[i].getData()) {
|
||||
while (parent != treeItem.getData()) {
|
||||
parent = parent.getParent();
|
||||
if (parent == null) break;
|
||||
}
|
||||
|
||||
if (parent == treeItems[i].getData()) {
|
||||
treeItems[i].setExpanded(true);
|
||||
if (parent == treeItem.getData()) {
|
||||
treeItem.setExpanded(true);
|
||||
viewer.refresh();
|
||||
|
||||
return expandTreeToTreeObject(treeItems[i].getItems(), treeObj);
|
||||
return expandTreeToTreeObject(treeItem.getItems(), treeObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -700,13 +701,13 @@ public void createPartControl(Composite parent) {
|
|||
private void hideMenuItems(IMenuManager manager) {
|
||||
IContributionItem[] items = manager.getItems();
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] instanceof IMenuManager) {
|
||||
hideMenuItems((IMenuManager)items[i]);
|
||||
for (IContributionItem item : items) {
|
||||
if (item instanceof IMenuManager) {
|
||||
hideMenuItems((IMenuManager)item);
|
||||
}
|
||||
|
||||
if (items[i] instanceof ActionContributionItem) {
|
||||
String text = ((ActionContributionItem) items[i]).getAction().getText();
|
||||
if (item instanceof ActionContributionItem) {
|
||||
String text = ((ActionContributionItem) item).getAction().getText();
|
||||
IASTNode selectedNode = null;
|
||||
if (viewer.getSelection() instanceof StructuredSelection
|
||||
&& ((StructuredSelection) viewer.getSelection())
|
||||
|
@ -717,9 +718,9 @@ public void createPartControl(Composite parent) {
|
|||
|
||||
if (text.equals(OPEN_REFERENCES) || text.equals(OPEN_DECLARATIONS)) {
|
||||
if (selectedNode instanceof IASTName) {
|
||||
items[i].setVisible(true);
|
||||
item.setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
item.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -727,9 +728,9 @@ public void createPartControl(Composite parent) {
|
|||
if (selectedNode instanceof IASTDeclarator ||
|
||||
selectedNode instanceof IASTDeclSpecifier ||
|
||||
selectedNode instanceof IASTTypeId) {
|
||||
items[i].setVisible(true);
|
||||
item.setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
item.setVisible(false);
|
||||
}
|
||||
} else if (text.equals(DISPLAY_TYPE)) {
|
||||
if (selectedNode instanceof IASTDeclarator ||
|
||||
|
@ -738,21 +739,21 @@ public void createPartControl(Composite parent) {
|
|||
((IASTName)selectedNode).resolveBinding() instanceof IVariable ||
|
||||
((IASTName)selectedNode).resolveBinding() instanceof IFunction ||
|
||||
((IASTName)selectedNode).resolveBinding() instanceof IType))) {
|
||||
items[i].setVisible(true);
|
||||
item.setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
item.setVisible(false);
|
||||
}
|
||||
} else if (text.equals(DISPLAY_EXPRESSION)) {
|
||||
if (selectedNode instanceof IASTExpression) {
|
||||
items[i].setVisible(true);
|
||||
item.setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
item.setVisible(false);
|
||||
}
|
||||
} else if (text.equals(DISPLAY_INITIALIZER)) {
|
||||
if (selectedNode instanceof IASTInitializer) {
|
||||
items[i].setVisible(true);
|
||||
item.setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
item.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -909,7 +910,7 @@ public void createPartControl(Composite parent) {
|
|||
if (selection instanceof IStructuredSelection &&
|
||||
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
|
||||
((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) {
|
||||
showMessage("ASTSignatureUtil#getNodeSignature(IASTNode): \"" + ASTSignatureUtil.getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
showMessage("Node Signature: \"" + getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} };
|
||||
displayNodeSignatureAction.setText(DISPLAY_SIGNATURE);
|
||||
|
@ -923,7 +924,7 @@ public void createPartControl(Composite parent) {
|
|||
if (selection instanceof IStructuredSelection &&
|
||||
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
|
||||
((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTExpression) {
|
||||
showMessage("ASTSignatureUtil#getExpressionString(IASTExpression): \"" + ASTSignatureUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
showMessage("Expression String: \"" + ASTStringUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} };
|
||||
displayExpressionAction.setText(DISPLAY_EXPRESSION);
|
||||
|
@ -937,7 +938,7 @@ public void createPartControl(Composite parent) {
|
|||
if (selection instanceof IStructuredSelection &&
|
||||
((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
|
||||
((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTInitializer) {
|
||||
showMessage("ASTSignatureUtil#getInitializerString(IASTInitializer): \"" + ASTSignatureUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
showMessage("Initializer String: \"" + ASTStringUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} };
|
||||
displayInitializerAction.setText(DISPLAY_INITIALIZER);
|
||||
|
@ -947,18 +948,49 @@ public void createPartControl(Composite parent) {
|
|||
singleClickAction = new ASTHighlighterAction(part);
|
||||
}
|
||||
|
||||
protected IEditorPart getActiveEditor() {
|
||||
IEditorPart editor = null;
|
||||
|
||||
if (getSite().getPage().isEditorAreaVisible() &&
|
||||
getSite().getPage().getActiveEditor() != null &&
|
||||
getSite().getPage().getActiveEditor() instanceof CEditor) {
|
||||
editor = getSite().getPage().getActiveEditor();
|
||||
part = editor;
|
||||
}
|
||||
protected static String getNodeSignature(IASTNode node) {
|
||||
if (node instanceof IASTDeclarator)
|
||||
return ASTStringUtil.getSignatureString(null, (IASTDeclarator) node);
|
||||
if (node instanceof IASTDeclSpecifier)
|
||||
return ASTStringUtil.getSignatureString((IASTDeclSpecifier) node, null);
|
||||
if (node instanceof IASTTypeId) {
|
||||
final IASTTypeId typeId = (IASTTypeId) node;
|
||||
return ASTStringUtil.getSignatureString(typeId.getDeclSpecifier(), typeId.getAbstractDeclarator());
|
||||
}
|
||||
if (node instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(getNodeSignature(decl.getDeclSpecifier()));
|
||||
IASTDeclarator[] declarators = decl.getDeclarators();
|
||||
for (int i = 0; i < declarators.length; ++i) {
|
||||
buffer.append(" ");
|
||||
buffer.append(getNodeSignature(declarators[i]));
|
||||
if (declarators[i].getInitializer() != null
|
||||
&& declarators[i].getInitializer() instanceof ICPPASTConstructorInitializer) {
|
||||
buffer.append(ASTStringUtil.getInitializerString(declarators[i].getInitializer()));
|
||||
}
|
||||
}
|
||||
buffer.append(";"); //$NON-NLS-1$
|
||||
return buffer.toString();
|
||||
}
|
||||
if (node instanceof IASTExpression) {
|
||||
return ASTStringUtil.getExpressionString((IASTExpression) node);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
protected IEditorPart getActiveEditor() {
|
||||
IEditorPart editor = null;
|
||||
|
||||
if (getSite().getPage().isEditorAreaVisible()
|
||||
&& getSite().getPage().getActiveEditor() != null
|
||||
&& getSite().getPage().getActiveEditor() instanceof CEditor) {
|
||||
editor = getSite().getPage().getActiveEditor();
|
||||
part = editor;
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
private class ASTHighlighterAction extends Action {
|
||||
private static final String A_PART_INSTANCEOF = "aPart instanceof "; //$NON-NLS-1$
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.eclipse.ui.views.properties.IPropertySource;
|
|||
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
|
@ -62,6 +61,7 @@ import org.eclipse.cdt.core.parser.Keywords;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -218,13 +218,13 @@ public class DOMASTNodeLeaf implements IAdaptable {
|
|||
buffer.append(node.toString());
|
||||
} else if ( node instanceof IASTCastExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append( ASTSignatureUtil.getCastOperatorString( (IASTCastExpression)node ) );
|
||||
buffer.append( ASTStringUtil.getCastOperatorString( (IASTCastExpression)node ) );
|
||||
} else if ( node instanceof IASTUnaryExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append( ASTSignatureUtil.getUnaryOperatorString( (IASTUnaryExpression)node ) );
|
||||
buffer.append( ASTStringUtil.getUnaryOperatorString( (IASTUnaryExpression)node ) );
|
||||
} else if ( node instanceof IASTBinaryExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append( ASTSignatureUtil.getBinaryOperatorString( (IASTBinaryExpression)node ) );
|
||||
buffer.append( ASTStringUtil.getBinaryOperatorString( (IASTBinaryExpression)node ) );
|
||||
} else if ( node instanceof ICASTDesignator ) {
|
||||
if ( node instanceof ICASTArrayDesignator && ((ICASTArrayDesignator)node).getSubscriptExpression() != null ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
|
@ -572,9 +572,9 @@ public class DOMASTNodeLeaf implements IAdaptable {
|
|||
buffer.append(COLON_SEPARATOR);
|
||||
buffer.append(getType(obj));
|
||||
} else if (obj instanceof IASTExpression) {
|
||||
buffer.append(ASTSignatureUtil.getExpressionString((IASTExpression)obj));
|
||||
buffer.append(ASTStringUtil.getExpressionString((IASTExpression)obj));
|
||||
} else if (obj instanceof IASTNode) {
|
||||
String utilString = ASTSignatureUtil.getNodeSignature((IASTNode)obj);
|
||||
String utilString = DOMAST.getNodeSignature((IASTNode)obj);
|
||||
if (utilString != null && !utilString.equals(BLANK_STRING)) {
|
||||
buffer.append(trimObjectToString(obj.toString()));
|
||||
buffer.append(COLON_SEPARATOR);
|
||||
|
|
Loading…
Add table
Reference in a new issue