mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Content Assist after braces as part of macro expansion, bug 257915.
This commit is contained in:
parent
a8a55aa932
commit
f0c0936852
6 changed files with 70 additions and 11 deletions
|
@ -6,25 +6,30 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Yuan Zhang / Beth Tibbitts (IBM Research)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* Node for elaborated type specifiers (examples: struct S; union U; enum E;)
|
||||
*/
|
||||
public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implements
|
||||
ICASTElaboratedTypeSpecifier {
|
||||
ICASTElaboratedTypeSpecifier, IASTCompletionContext {
|
||||
|
||||
private int kind;
|
||||
private IASTName name;
|
||||
|
@ -102,4 +107,41 @@ public class CASTElaboratedTypeSpecifier extends CASTBaseDeclSpecifier implement
|
|||
}
|
||||
return r_reference;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] result= CVisitor.findBindingsForContentAssist(n, isPrefix);
|
||||
int nextPos= 0;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
IBinding b= result[i];
|
||||
if (b instanceof ICompositeType) {
|
||||
ICompositeType ct= (ICompositeType) b;
|
||||
try {
|
||||
switch (ct.getKey()) {
|
||||
case ICompositeType.k_struct:
|
||||
if (getKind() != k_struct)
|
||||
b= null;
|
||||
break;
|
||||
case ICompositeType.k_union:
|
||||
if (getKind() != k_union)
|
||||
b= null;
|
||||
break;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
// ignore and propose binding
|
||||
}
|
||||
} else if (b instanceof IEnumeration) {
|
||||
if (getKind() != k_enum)
|
||||
b= null;
|
||||
}
|
||||
if (b != null) {
|
||||
result[nextPos++]= b;
|
||||
}
|
||||
}
|
||||
if (nextPos != result.length) {
|
||||
IBinding[] copy = new IBinding[nextPos];
|
||||
System.arraycopy(result, 0, copy, 0, nextPos);
|
||||
return copy;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* Andrew Niefer (IBM Rational Software) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Andrew Ferguson (Symbian)
|
||||
|
@ -109,8 +109,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* Created on Nov 5, 2004
|
||||
* @author aniefer
|
||||
* Collection of methods to find information in an AST.
|
||||
*/
|
||||
public class CVisitor {
|
||||
public static class ClearBindingAction extends CASTVisitor {
|
||||
|
|
|
@ -2294,7 +2294,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
identifier= qualifiedName();
|
||||
if (identifier.getLastName().toCharArray().length == 0)
|
||||
if (identifier.getLastName().toCharArray().length == 0 && LT(1) != IToken.tEOC)
|
||||
throwBacktrack(LA(1));
|
||||
|
||||
endOffset= calculateEndOffset(identifier);
|
||||
|
|
|
@ -406,7 +406,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
|
||||
public boolean isOnTopContext() {
|
||||
return fCurrentContext == fRootContext;
|
||||
ScannerContext ctx= fCurrentContext;
|
||||
while (ctx != null && ctx.getLocationCtx() instanceof LocationCtxMacroExpansion) {
|
||||
ctx= ctx.getParent();
|
||||
}
|
||||
return ctx == fRootContext;
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
|
|
@ -1174,4 +1174,17 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
final String[] expected= {"_f204758(_e204758 x) : void"};
|
||||
assertCompletionResults(fCursorOffset, expected, COMPARE_DISP_STRINGS);
|
||||
}
|
||||
|
||||
// #define CATCH(X) } catch (X) {
|
||||
// void foo() {
|
||||
// try {
|
||||
// CATCH(float var)
|
||||
// v/*cursor*/
|
||||
// } catch (int var2) {
|
||||
// }
|
||||
// }
|
||||
public void testContentAssistWithBraceInMacro_Bug257915() throws Exception {
|
||||
final String[] expected= {"var : float"};
|
||||
assertCompletionResults(fCursorOffset, expected, COMPARE_DISP_STRINGS);
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
return BaseTestCase.suite(ParameterHintTests.class, "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IFile setUpProjectContent(IProject project) throws Exception {
|
||||
String headerContent= readTaggedComment(HEADER_FILE_NAME);
|
||||
StringBuffer sourceContent= getContentsForTest(1)[0];
|
||||
|
@ -142,7 +143,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
public void testTemplateConstructor() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
"tClass(T t)",
|
||||
"tClass(const tClass &)"
|
||||
"tClass(const tClass<T> &)"
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue