Browse Source

- moved some expression contexts to CSharpExpressionContext

- removed IdentifierExpected-Blocks

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@6128 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
aab8d9b0e0
  1. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Block.cs
  2. 30
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg
  3. 13
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs
  4. 1
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinderState.cs
  5. 2882
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs
  6. 2
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame
  7. 128
      src/Libraries/NRefactory/Test/Lexer/VBNet/LexerContextTests.cs
  8. 5
      src/Main/Base/Project/Src/Editor/CodeCompletion/MethodInsightProvider.cs
  9. 62
      src/Main/Base/Test/CSharpExpressionFinderTests.cs
  10. 19
      src/Main/Base/Test/NRefactoryResolverTests.cs
  11. 10
      src/Main/Base/Test/VBExpressionFinderTests.cs
  12. 1
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj
  13. 59
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpExpressionContext.cs
  14. 22
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs
  15. 78
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs
  16. 29
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs
  17. 6
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

2
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Block.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
Type,
Member,
Parameter,
IdentifierExpected,
Identifier,
Body,
Xml,
Attribute,

30
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.atg

@ -303,7 +303,7 @@ NamespaceMemberDeclaration = @@ -303,7 +303,7 @@ NamespaceMemberDeclaration =
.
NamespaceDeclaration =
"Namespace" (. PushContext(Context.IdentifierExpected, la, t); .) { ANY } (. PopContext(); .) StatementTerminator
"Namespace" (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) { ANY } (. PopContext(); .) StatementTerminator
{ NamespaceMemberDeclaration }
"End" "Namespace" StatementTerminator
.
@ -316,7 +316,7 @@ TypeDeclaration = @@ -316,7 +316,7 @@ TypeDeclaration =
.
ClassOrModuleOrStructureTypeDeclaration =
( "Module" | "Class" | "Structure" ) (. PushContext(Context.IdentifierExpected, la, t); .) ANY (. PopContext(); .)
( "Module" | "Class" | "Structure" ) (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) ANY (. PopContext(); .)
[ "(" "Of" [ "Out" | "In" ] IdentifierExceptOut [ (. PushContext(Context.Type, la, t); .) "As" GenericConstraintList (. PopContext(); .) ] { "," [ "Out" | "In" ] IdentifierExceptOut [ (. PushContext(Context.Type, la, t); .) "As" GenericConstraintList (. PopContext(); .) ] } ")" ] { ANY } [ StatementTerminator ]
[ "Inherits" { ANY } StatementTerminator ]
[ "Implements" { ANY } StatementTerminator ]
@ -336,7 +336,7 @@ GenericConstraintList = @@ -336,7 +336,7 @@ GenericConstraintList =
DelegateTypeDeclaration =
"Delegate" ("Sub" | "Function")
(. PushContext(Context.IdentifierExpected, la, t); .) ANY (. PopContext(); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) ANY (. PopContext(); .)
[ "(" [ ParameterList ] ")" ] [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] StatementTerminator
.
@ -356,19 +356,19 @@ MemberDeclaration = @@ -356,19 +356,19 @@ MemberDeclaration =
SubOrFunctionDeclaration =
("Sub" | "Function")
(. PushContext(Context.IdentifierExpected, la, t); .) ANY (. PopContext(); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) ANY (. PopContext(); .)
[ "(" [ ParameterList ] ")" ] [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ]
StatementTerminatorAndBlock
"End" ("Sub" | "Function") StatementTerminator
.
ExternalMemberDeclaration =
"Declare" [ "Ansi" | "Unicode" | "Auto" ] ( "Sub" | "Function" ) (. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .)
"Declare" [ "Ansi" | "Unicode" | "Auto" ] ( "Sub" | "Function" ) (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
"Lib" LiteralString [ "Alias" LiteralString ] [ "(" [ ParameterList ] ")" ] [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] StatementTerminator
.
EventMemberDeclaration =
"Event" (. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .) ( (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) | [ "(" [ ParameterList ] ")" ] )
"Event" (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .) ( (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) | [ "(" [ ParameterList ] ")" ] )
[ "Implements" TypeName /*"." IdentifierOrKeyword*/ { "," TypeName /*"." IdentifierOrKeyword*/ } ]
/* the TypeName production already allows the "." IdentifierOrKeyword syntax, so to avoid an ambiguous grammer we just leave that out */
StatementTerminator
@ -385,14 +385,14 @@ CustomEventMemberDeclaration = @@ -385,14 +385,14 @@ CustomEventMemberDeclaration =
.
OperatorDeclaration =
"Operator" (. PushContext(Context.IdentifierExpected, la, t); .) ANY (. PopContext(); .) "(" ParameterList ")" [ "As" { AttributeBlock } (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) ]
"Operator" (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) ANY (. PopContext(); .) "(" ParameterList ")" [ "As" { AttributeBlock } (. PushContext(Context.Type, la, t); .) TypeName (. PopContext(); .) ]
StatementTerminatorAndBlock
"End" "Operator" StatementTerminator
.
MemberVariableOrConstantDeclaration =
[ "Const" ]
(. PushContext(Context.IdentifierExpected, la, t); .) IdentifierForFieldDeclaration (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] [ "=" Expression ] StatementTerminator
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) IdentifierForFieldDeclaration (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] [ "=" Expression ] StatementTerminator
.
ParameterList =
@ -402,7 +402,7 @@ ParameterList = @@ -402,7 +402,7 @@ ParameterList =
Parameter =
(. PushContext(Context.Parameter, la, t); .)
{ AttributeBlock } { ParameterModifier }
(. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
[ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ]
[ "=" Expression ]
(. PopContext(); .)
@ -652,7 +652,7 @@ ExpressionRangeVariable = @@ -652,7 +652,7 @@ ExpressionRangeVariable =
"Explicit", "Equals", "Distinct", "Descending", "Compare", "By",
"Binary", "Auto", "Assembly", "Ascending", "Ansi", "Aggregate", ident)
(
(. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .)
(
(. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) "="
| "="
@ -671,7 +671,7 @@ ExpressionRangeVariable = @@ -671,7 +671,7 @@ ExpressionRangeVariable =
.
CollectionRangeVariable =
(. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] "In" Expression
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] "In" Expression
.
/* semantic action will be inserted on all paths that possibly lead to XmlLiteral */
@ -938,10 +938,10 @@ Statement = @@ -938,10 +938,10 @@ Statement =
VariableDeclarationStatement =
( "Dim" | "Static" | "Const" )
(. PushContext(Context.IdentifierExpected, la, t); .)
(. PushContext(Context.Identifier, la, t); .)
Identifier (. PopContext(); .) [ "?" ] [ ( "(" { "," } ")" ) ]
{ ","
(. PushContext(Context.IdentifierExpected, la, t); .)
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .)
Identifier (. PopContext(); .) [ "?" ] [ ( "(" { "," } ")" ) ]
}
[ (. PushContext(Context.Type, la, t); .)
@ -1042,7 +1042,7 @@ ForEachLoopStatement = @@ -1042,7 +1042,7 @@ ForEachLoopStatement =
.
ForLoopVariable =
(. PushContext(Context.IdentifierExpected, la, t); .) SimpleExpression (. PopContext(); .) [ "?" ] { ExpressionSuffix } [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ]
(. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) SimpleExpression (. PopContext(); .) [ "?" ] { ExpressionSuffix } [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ]
.
ErrorHandlingStatement =
@ -1059,7 +1059,7 @@ TryStatement = @@ -1059,7 +1059,7 @@ TryStatement =
StatementTerminatorAndBlock
{
"Catch"
[ (. PushContext(Context.IdentifierExpected, la, t); .) Identifier (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] ]
[ (. PushContext(Context.Identifier, la, t); .) (.OnEachPossiblePath: SetIdentifierExpected(la); .) Identifier (. PopContext(); .) [ (. PushContext(Context.Type, la, t); .) "As" TypeName (. PopContext(); .) ] ]
[ "When" Expression ]
StatementTerminatorAndBlock
}

13
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinder.cs

@ -50,6 +50,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -50,6 +50,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
nextTokenIsPotentialStartOfExpression = state.NextTokenIsPotentialStartOfExpression;
nextTokenIsStartOfImportsOrAccessExpression = state.NextTokenIsStartOfImportsOrAccessExpression;
readXmlIdentifier = state.ReadXmlIdentifier;
identifierExpected = state.IdentifierExpected;
stateStack = new Stack<int>(state.StateStack.Reverse());
stack = new Stack<Block>(state.BlockStack.Select(x => (Block)x.Clone()).Reverse());
currentState = state.CurrentState;
@ -94,9 +95,14 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -94,9 +95,14 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
public bool IsIdentifierExpected {
get {
return stack.Take(2).Any(c => c.context == Context.IdentifierExpected);
}
get { return identifierExpected; }
}
void SetIdentifierExpected(Token la)
{
identifierExpected = true;
if (la != null)
CurrentBlock.lastExpressionStart = la.Location;
}
public bool InContext(Context expected)
@ -134,6 +140,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -134,6 +140,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
NextTokenIsPotentialStartOfExpression = nextTokenIsPotentialStartOfExpression,
NextTokenIsStartOfImportsOrAccessExpression = nextTokenIsStartOfImportsOrAccessExpression,
ReadXmlIdentifier = readXmlIdentifier,
IdentifierExpected = identifierExpected,
StateStack = new Stack<int>(stateStack.Reverse()),
BlockStack = new Stack<Block>(stack.Select(x => (Block)x.Clone()).Reverse()),
CurrentState = currentState

1
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/ExpressionFinderState.cs

@ -17,6 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -17,6 +17,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
public bool WasQualifierTokenAtStart { get; set; }
public bool NextTokenIsPotentialStartOfExpression { get; set; }
public bool ReadXmlIdentifier { get; set; }
public bool IdentifierExpected { get; set; }
public bool NextTokenIsStartOfImportsOrAccessExpression { get; set; }
public Stack<int> StateStack { get; set; }
public Stack<Block> BlockStack { get; set; }

2882
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

2
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/PushParser.frame

@ -37,6 +37,7 @@ partial class ExpressionFinder { @@ -37,6 +37,7 @@ partial class ExpressionFinder {
bool wasQualifierTokenAtStart = false;
bool nextTokenIsPotentialStartOfExpression = false;
bool readXmlIdentifier = false;
bool identifierExpected = false;
bool nextTokenIsStartOfImportsOrAccessExpression = false;
List<Token> errors = new List<Token>();
@ -68,6 +69,7 @@ partial class ExpressionFinder { @@ -68,6 +69,7 @@ partial class ExpressionFinder {
nextTokenIsPotentialStartOfExpression = false;
readXmlIdentifier = false;
nextTokenIsStartOfImportsOrAccessExpression = false;
identifierExpected = false;
wasQualifierTokenAtStart = false;
-->informToken
if (la != null) t = la;

128
src/Libraries/NRefactory/Test/Lexer/VBNet/LexerContextTests.cs

@ -39,15 +39,15 @@ exit Global @@ -39,15 +39,15 @@ exit Global
End Class
",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -77,12 +77,12 @@ exit Global @@ -77,12 +77,12 @@ exit Global
End Class
",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Type
exit Type
enter Expression
@ -95,11 +95,11 @@ End Class @@ -95,11 +95,11 @@ End Class
exit Expression
exit Member
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -130,15 +130,15 @@ End Class @@ -130,15 +130,15 @@ End Class
@"enter Global
enter Attribute
exit Attribute
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -167,15 +167,15 @@ End Class @@ -167,15 +167,15 @@ End Class
@"enter Global
enter Attribute
exit Attribute
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -202,17 +202,17 @@ exit Global @@ -202,17 +202,17 @@ exit Global
End Class
",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter Attribute
exit Attribute
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -240,12 +240,12 @@ exit Global @@ -240,12 +240,12 @@ exit Global
End Class
",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter Expression
enter Expression
@ -286,17 +286,17 @@ exit Global @@ -286,17 +286,17 @@ exit Global
End Class
",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter IdentifierExpected
enter Identifier
enter Expression
exit Expression
exit IdentifierExpected
exit Identifier
enter Type
exit Type
enter Expression
@ -311,10 +311,10 @@ End Class @@ -311,10 +311,10 @@ End Class
exit Expression
enter Body
exit Body
enter IdentifierExpected
enter Identifier
enter Expression
exit Expression
exit IdentifierExpected
exit Identifier
enter Type
exit Type
enter Expression
@ -327,8 +327,8 @@ End Class @@ -327,8 +327,8 @@ End Class
exit Body
enter Body
exit Body
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Type
exit Type
enter Body
@ -354,18 +354,18 @@ exit Global @@ -354,18 +354,18 @@ exit Global
End Sub
End Class",
@"enter Global
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Type
exit Type
exit Member
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter Expression
enter Expression
@ -377,10 +377,10 @@ End Class", @@ -377,10 +377,10 @@ End Class",
exit Expression
exit Expression
exit Expression
enter IdentifierExpected
enter Identifier
enter Expression
exit Expression
exit IdentifierExpected
exit Identifier
enter Expression
enter Expression
enter Expression
@ -430,12 +430,12 @@ End Module", @@ -430,12 +430,12 @@ End Module",
exit Importable
enter Importable
exit Importable
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter TypeDeclaration
enter Member
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Body
enter Expression
enter Expression
@ -449,16 +449,16 @@ End Module", @@ -449,16 +449,16 @@ End Module",
exit Expression
exit Expression
exit Expression
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
exit Expression
exit Expression
exit Expression
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression
@ -493,8 +493,8 @@ End Module", @@ -493,8 +493,8 @@ End Module",
exit Expression
exit Expression
exit Expression
enter IdentifierExpected
exit IdentifierExpected
enter Identifier
exit Identifier
enter Expression
enter Expression
enter Expression

5
src/Main/Base/Project/Src/Editor/CodeCompletion/MethodInsightProvider.cs

@ -12,6 +12,7 @@ using System.Linq; @@ -12,6 +12,7 @@ using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.CSharp;
namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
{
@ -71,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -71,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
} else if (expressionResult.Context.IsObjectCreation) {
constructorInsight = true;
expressionResult.Context = ExpressionContext.Type;
} else if (expressionResult.Context == ExpressionContext.BaseConstructorCall) {
} else if (expressionResult.Context == CSharpExpressionContext.BaseConstructorCall) {
constructorInsight = true;
}
@ -93,7 +94,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion @@ -93,7 +94,7 @@ namespace ICSharpCode.SharpDevelop.Editor.CodeCompletion
List<IMethod> methods = new List<IMethod>();
if (constructorInsight) {
if (trr != null || expressionResult.Context == ExpressionContext.BaseConstructorCall) {
if (trr != null || expressionResult.Context == CSharpExpressionContext.BaseConstructorCall) {
if (result.ResolvedType != null) {
methods.AddRange(GetConstructors(result.ResolvedType));
}

62
src/Main/Base/Test/CSharpExpressionFinderTests.cs

@ -208,7 +208,7 @@ class Main { @@ -208,7 +208,7 @@ class Main {
public void GlobalNamespace()
{
// context = context after the found word
FindFull(program3, "global", "global", ExpressionContext.FirstParameterType);
FindFull(program3, "global", "global", CSharpExpressionContext.FirstParameterType);
FindFull(program3, "System.Ex", "global::System", ExpressionContext.IdentifierExpected);
FindFull(program3, "Excep", "global::System.Exception", ExpressionContext.Type);
}
@ -229,8 +229,8 @@ class Main { @@ -229,8 +229,8 @@ class Main {
[Test]
public void ConstructorCall()
{
FindFull(program3, "this(", "this()", ExpressionContext.BaseConstructorCall);
FindFull(program3, "base(", "base(arg + 3)", ExpressionContext.BaseConstructorCall);
FindFull(program3, "this(", "this()", CSharpExpressionContext.BaseConstructorCall);
FindFull(program3, "base(", "base(arg + 3)", CSharpExpressionContext.BaseConstructorCall);
}
[Test]
@ -308,10 +308,10 @@ class Main { @@ -308,10 +308,10 @@ class Main {
}
}";
FindExpr(propertyProgram, "\t/* in prop", null, ExpressionContext.PropertyDeclaration);
FindExpr(propertyProgram, "\t/* in prop", null, CSharpExpressionContext.PropertyDeclaration);
FindExpr(propertyProgram, "\t/* in getter ", null, ExpressionContext.MethodBody);
FindExpr(propertyProgram, "\t/* in setter", null, ExpressionContext.MethodBody);
FindExpr(propertyProgram, "\t/* still in prop", null, ExpressionContext.PropertyDeclaration);
FindExpr(propertyProgram, "\t/* still in prop", null, CSharpExpressionContext.PropertyDeclaration);
}
[Test]
@ -440,7 +440,7 @@ class Main { @@ -440,7 +440,7 @@ class Main {
body;
} }";
FindFull(program, "base", "base(arg)", ExpressionContext.BaseConstructorCall);
FindFull(program, "base", "base(arg)", CSharpExpressionContext.BaseConstructorCall);
FindFull(program, "body", "body", ExpressionContext.MethodBody);
FindFull(program, "arg", "arg", ExpressionContext.Default);
}
@ -549,7 +549,7 @@ class Dictionary<K, "; @@ -549,7 +549,7 @@ class Dictionary<K, ";
class List<T> ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("List<T> ", result.Expression);
Assert.AreEqual(ExpressionContext.ConstraintsStart, result.Context);
Assert.AreEqual(CSharpExpressionContext.ConstraintsStart, result.Context);
}
[Test]
@ -559,7 +559,7 @@ class List<T> "; @@ -559,7 +559,7 @@ class List<T> ";
class List<T> where ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("where ", result.Expression);
Assert.AreEqual(ExpressionContext.Constraints, result.Context);
Assert.AreEqual(CSharpExpressionContext.Constraints, result.Context);
}
[Test]
@ -569,7 +569,7 @@ class List<T> where "; @@ -569,7 +569,7 @@ class List<T> where ";
class List<T> where T : ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(null, result.Expression);
Assert.AreEqual(ExpressionContext.Constraints, result.Context);
Assert.AreEqual(CSharpExpressionContext.Constraints, result.Context);
}
[Test]
@ -579,7 +579,7 @@ class List<T> where T : "; @@ -579,7 +579,7 @@ class List<T> where T : ";
class List<T> where T : class, ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(null, result.Expression);
Assert.AreEqual(ExpressionContext.Constraints, result.Context);
Assert.AreEqual(CSharpExpressionContext.Constraints, result.Context);
}
[Test]
@ -591,7 +591,7 @@ class Main { @@ -591,7 +591,7 @@ class Main {
a = new MyType { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -603,7 +603,7 @@ class Main { @@ -603,7 +603,7 @@ class Main {
a = new MyType<TypeArgument[], int?> { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -615,7 +615,7 @@ class Main { @@ -615,7 +615,7 @@ class Main {
a = new global::MyNamespace.MyType { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -627,7 +627,7 @@ class Main { @@ -627,7 +627,7 @@ class Main {
a = new MyType(){ ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -639,7 +639,7 @@ class Main { @@ -639,7 +639,7 @@ class Main {
a = new MyType<TypeArgument[], int?> (){ ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -651,7 +651,7 @@ class Main { @@ -651,7 +651,7 @@ class Main {
a = new MyType(arg1, ')', arg3) { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -663,7 +663,7 @@ class Main { @@ -663,7 +663,7 @@ class Main {
a = new MyType { P1 = expr, ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -699,7 +699,7 @@ class Main { @@ -699,7 +699,7 @@ class Main {
a = new { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -711,7 +711,7 @@ class Main { @@ -711,7 +711,7 @@ class Main {
a = new { a.B, ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -723,7 +723,7 @@ class Main { @@ -723,7 +723,7 @@ class Main {
a = new SomeType { SomeProperty = { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -735,7 +735,7 @@ class Main { @@ -735,7 +735,7 @@ class Main {
a = new SomeType { SomeProperty = new SomeOtherType { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ObjectInitializer, result.Context);
Assert.AreEqual(CSharpExpressionContext.ObjectInitializer, result.Context);
}
[Test]
@ -801,7 +801,7 @@ class Main { @@ -801,7 +801,7 @@ class Main {
public int this[";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.ParameterType, result.Context);
Assert.AreEqual(CSharpExpressionContext.ParameterType, result.Context);
}
[Test]
@ -812,7 +812,7 @@ class Main { @@ -812,7 +812,7 @@ class Main {
public int this[int index] { ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual(ExpressionContext.PropertyDeclaration, result.Context);
Assert.AreEqual(CSharpExpressionContext.PropertyDeclaration, result.Context);
}
[Test]
@ -979,7 +979,7 @@ delegate void Test<T>("; @@ -979,7 +979,7 @@ delegate void Test<T>(";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.IsNull(result.Expression);
Assert.AreEqual(ExpressionContext.ParameterType, result.Context);
Assert.AreEqual(CSharpExpressionContext.ParameterType, result.Context);
}
[Test]
@ -990,7 +990,7 @@ delegate void Test<T>(ref "; @@ -990,7 +990,7 @@ delegate void Test<T>(ref ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.IsNull(result.Expression);
Assert.AreEqual(ExpressionContext.ParameterType, result.Context);
Assert.AreEqual(CSharpExpressionContext.ParameterType, result.Context);
}
[Test]
@ -1012,7 +1012,7 @@ delegate void Test<T>(ref T name) "; @@ -1012,7 +1012,7 @@ delegate void Test<T>(ref T name) ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("Test<T>(ref T name) ", result.Expression);
Assert.AreEqual(ExpressionContext.ConstraintsStart, result.Context);
Assert.AreEqual(CSharpExpressionContext.ConstraintsStart, result.Context);
}
[Test]
@ -1023,7 +1023,7 @@ delegate void Test<T>(ref T name) where "; @@ -1023,7 +1023,7 @@ delegate void Test<T>(ref T name) where ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("where ", result.Expression);
Assert.AreEqual(ExpressionContext.Constraints, result.Context);
Assert.AreEqual(CSharpExpressionContext.Constraints, result.Context);
}
[Test]
@ -1045,7 +1045,7 @@ void Test<T>("; @@ -1045,7 +1045,7 @@ void Test<T>(";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.IsNull(result.Expression);
Assert.AreEqual(ExpressionContext.FirstParameterType, result.Context);
Assert.AreEqual(CSharpExpressionContext.FirstParameterType, result.Context);
}
[Test]
@ -1056,7 +1056,7 @@ void Test<T>(ref "; @@ -1056,7 +1056,7 @@ void Test<T>(ref ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.IsNull(result.Expression);
Assert.AreEqual(ExpressionContext.ParameterType, result.Context);
Assert.AreEqual(CSharpExpressionContext.ParameterType, result.Context);
}
[Test]
@ -1078,7 +1078,7 @@ void Test<T>(ref T name) "; @@ -1078,7 +1078,7 @@ void Test<T>(ref T name) ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("Test<T>(ref T name) ", result.Expression);
Assert.AreEqual(ExpressionContext.ConstraintsStart, result.Context);
Assert.AreEqual(CSharpExpressionContext.ConstraintsStart, result.Context);
}
[Test]
@ -1089,7 +1089,7 @@ void Test<T>(ref T name) where "; @@ -1089,7 +1089,7 @@ void Test<T>(ref T name) where ";
ExpressionResult result = ef.FindExpression(program, program.Length);
Assert.AreEqual("where ", result.Expression);
Assert.AreEqual(ExpressionContext.Constraints, result.Context);
Assert.AreEqual(CSharpExpressionContext.Constraints, result.Context);
}
[Test]

19
src/Main/Base/Test/NRefactoryResolverTests.cs

@ -13,6 +13,7 @@ using System.Linq; @@ -13,6 +13,7 @@ using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Dom.CSharp;
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver;
using ICSharpCode.SharpDevelop.Project;
using NUnit.Framework;
@ -1951,13 +1952,13 @@ public class MyCollectionType : System.Collections.IEnumerable @@ -1951,13 +1952,13 @@ public class MyCollectionType : System.Collections.IEnumerable
[Test]
public void ObjectInitializerCtrlSpaceCompletion()
{
var results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 5, ExpressionContext.ObjectInitializer);
var results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 5, CSharpExpressionContext.ObjectInitializer);
Assert.AreEqual(new[] { "P1", "P2" }, (from IMember p in results orderby p.Name select p.Name).ToArray() );
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 9, ExpressionContext.ObjectInitializer);
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 9, CSharpExpressionContext.ObjectInitializer);
Assert.AreEqual(new[] { "X", "Y" }, (from IMember p in results orderby p.Name select p.Name).ToArray() );
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 13, ExpressionContext.ObjectInitializer);
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 13, CSharpExpressionContext.ObjectInitializer);
// collection type: expect system types
Assert.IsTrue(results.OfType<IClass>().Any((IClass c) => c.FullyQualifiedName == "System.Int32"));
Assert.IsTrue(results.OfType<IClass>().Any((IClass c) => c.FullyQualifiedName == "System.AppDomain"));
@ -1968,30 +1969,30 @@ public class MyCollectionType : System.Collections.IEnumerable @@ -1968,30 +1969,30 @@ public class MyCollectionType : System.Collections.IEnumerable
Assert.IsFalse(results.OfType<IField>().Any((IField f) => f.FullyQualifiedName == "MyCollectionType.ReadOnlyValueTypeField"));
Assert.IsFalse(results.OfType<IProperty>().Any((IProperty f) => f.FullyQualifiedName == "MyCollectionType.ReadOnlyValueTypeProperty"));
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 17, ExpressionContext.ObjectInitializer);
results = CtrlSpaceResolveCSharp(objectInitializerTestProgram, 17, CSharpExpressionContext.ObjectInitializer);
Assert.AreEqual(new[] { "X", "Y" }, (from IMember p in results orderby p.Name select p.Name).ToArray() );
}
[Test]
public void ObjectInitializerCompletion()
{
MemberResolveResult mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "P2", 5, 1, ExpressionContext.ObjectInitializer);
MemberResolveResult mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "P2", 5, 1, CSharpExpressionContext.ObjectInitializer);
Assert.IsNotNull(mrr);
Assert.AreEqual("Rectangle.P2", mrr.ResolvedMember.FullyQualifiedName);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "X", 9, 1, ExpressionContext.ObjectInitializer);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "X", 9, 1, CSharpExpressionContext.ObjectInitializer);
Assert.IsNotNull(mrr);
Assert.AreEqual("Point.X", mrr.ResolvedMember.FullyQualifiedName);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "Field", 13, 1, ExpressionContext.ObjectInitializer);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "Field", 13, 1, CSharpExpressionContext.ObjectInitializer);
Assert.IsNotNull(mrr);
Assert.AreEqual("MyCollectionType.Field", mrr.ResolvedMember.FullyQualifiedName);
LocalResolveResult lrr = (LocalResolveResult)Resolve(objectInitializerTestProgram, "r1", 13, 1, ExpressionContext.ObjectInitializer);
LocalResolveResult lrr = (LocalResolveResult)Resolve(objectInitializerTestProgram, "r1", 13, 1, CSharpExpressionContext.ObjectInitializer);
Assert.IsNotNull(lrr);
Assert.AreEqual("r1", lrr.Field.Name);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "X", 17, 1, ExpressionContext.ObjectInitializer);
mrr = (MemberResolveResult)Resolve(objectInitializerTestProgram, "X", 17, 1, CSharpExpressionContext.ObjectInitializer);
Assert.IsNotNull(mrr);
Assert.AreEqual("Point.X", mrr.ResolvedMember.FullyQualifiedName);
}

10
src/Main/Base/Test/VBExpressionFinderTests.cs

@ -151,7 +151,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter); @@ -151,7 +151,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter);
[Test]
public void ContextAfterDim()
{
ContextTest(program4, "Dim ", "Dim".Length, ExpressionContext.IdentifierExpected);
ContextTest(program4, "Dim ", "Dim".Length, ExpressionContext.MethodBody);
}
#endregion
@ -171,7 +171,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter); @@ -171,7 +171,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter);
[Test]
public void Underscore()
{
FindFull(program1, "der_score_field", "under_score_field", ExpressionContext.IdentifierExpected);
FindFull(program1, "der_score_field", "under_score_field", ExpressionContext.Default);
}
[Test]
@ -183,7 +183,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter); @@ -183,7 +183,7 @@ End Module", "(", 1, "", ExpressionContext.Parameter);
[Test]
public void LocalVariableDecl()
{
FindFull(program1, "ext", "text", ExpressionContext.IdentifierExpected);
FindFull(program1, "ext", "text", ExpressionContext.Default);
}
[Test]
@ -201,13 +201,13 @@ End Module", "(", 1, "", ExpressionContext.Parameter); @@ -201,13 +201,13 @@ End Module", "(", 1, "", ExpressionContext.Parameter);
[Test]
public void ClassName()
{
FindFull(program1, "ainClas", "MainClass", ExpressionContext.IdentifierExpected);
FindFull(program1, "ainClas", "MainClass", ExpressionContext.Default);
}
[Test]
public void SubName()
{
FindFull(program1, "omeMe", "SomeMethod", ExpressionContext.IdentifierExpected);
FindFull(program1, "omeMe", "SomeMethod", ExpressionContext.Default);
}
#region Old Tests

1
src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj

@ -64,6 +64,7 @@ @@ -64,6 +64,7 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Src\BusyManager.cs" />
<Compile Include="Src\CSharp\CSharpExpressionContext.cs" />
<Compile Include="Src\CSharp\OverloadResolution.cs" />
<Compile Include="Src\CSharp\TypeInference.cs" />
<Compile Include="Src\DomCache.cs" />

59
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/CSharpExpressionContext.cs

@ -0,0 +1,59 @@ @@ -0,0 +1,59 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision: 5529 $</version>
// </file>
using System;
using ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.SharpDevelop.Dom.CSharp
{
public static class CSharpExpressionContext
{
/// <summary>The context is the body of a property declaration.</summary>
/// <example>string Name { *expr* }</example>
public readonly static ExpressionContext PropertyDeclaration = new ExpressionContext.DefaultExpressionContext("PropertyDeclaration");
/// <summary>The context is the body of a property declaration inside an interface.</summary>
/// <example>string Name { *expr* }</example>
public readonly static ExpressionContext InterfacePropertyDeclaration = new ExpressionContext.DefaultExpressionContext("InterfacePropertyDeclaration");
/// <summary>The context is the body of a event declaration.</summary>
/// <example>event EventHandler NameChanged { *expr* }</example>
public readonly static ExpressionContext EventDeclaration = new ExpressionContext.DefaultExpressionContext("EventDeclaration");
/// <summary>The context is after the type parameters of a type/method declaration.
/// The only valid keyword is "where"</summary>
/// <example>class &lt;T&gt; *expr*</example>
public readonly static ExpressionContext ConstraintsStart = new ExpressionContext.DefaultExpressionContext("ConstraintsStart");
/// <summary>The context is after the 'where' of a constraints list.</summary>
/// <example>class &lt;T&gt; where *expr*</example>
public readonly static ExpressionContext Constraints = new ExpressionContext.NonStaticTypeExpressionContext("Constraints", false);
/// <summary>The context is the body of an interface declaration.</summary>
public readonly static ExpressionContext InterfaceDeclaration = new ExpressionContext.NonStaticTypeExpressionContext("InterfaceDeclaration", true);
/// <summary>Context expects "base" or "this".</summary>
/// <example>public ClassName() : *expr*</example>
public readonly static ExpressionContext BaseConstructorCall = new ExpressionContext.DefaultExpressionContext("BaseConstructorCall");
/// <summary>The first parameter</summary>
/// <example>void MethodName(*expr*)</example>
public readonly static ExpressionContext FirstParameterType = new ExpressionContext.NonStaticTypeExpressionContext("FirstParameterType", false);
/// <summary>Another parameter</summary>
/// <example>void MethodName(..., *expr*)</example>
public readonly static ExpressionContext ParameterType = new ExpressionContext.NonStaticTypeExpressionContext("ParameterType", false);
/// <summary>Context expects a fully qualified type name.</summary>
/// <example>using Alias = *expr*;</example>
public readonly static ExpressionContext FullyQualifiedType = new ExpressionContext.DefaultExpressionContext("FullyQualifiedType");
/// <summary>Context expects is a property name in an object initializer.</summary>
/// <example>new *type* [(args)] { *expr* = ... }</example>
public readonly static ExpressionContext ObjectInitializer = new ExpressionContext.DefaultExpressionContext("ObjectInitializer");
}
}

22
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/CSharp/ExpressionFinder.cs

@ -222,7 +222,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -222,7 +222,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
SetContext(ExpressionContext.InheritableType);
}
} else if (state == FrameState.Constraints) {
SetContext(ExpressionContext.Constraints);
SetContext(CSharpExpressionContext.Constraints);
} else if (state == FrameState.UsingNamespace) {
SetContext(ExpressionContext.Namespace);
} else {
@ -238,29 +238,29 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -238,29 +238,29 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
SetContext(ExpressionContext.IdentifierExpected);
break;
case FrameType.Interface:
SetContext(ExpressionContext.InterfaceDeclaration);
SetContext(CSharpExpressionContext.InterfaceDeclaration);
break;
case FrameType.Event:
SetContext(ExpressionContext.EventDeclaration);
SetContext(CSharpExpressionContext.EventDeclaration);
break;
case FrameType.Property:
if (parent != null && parent.type == FrameType.Interface) {
SetContext(ExpressionContext.InterfacePropertyDeclaration);
SetContext(CSharpExpressionContext.InterfacePropertyDeclaration);
} else {
SetContext(ExpressionContext.PropertyDeclaration);
SetContext(CSharpExpressionContext.PropertyDeclaration);
}
break;
case FrameType.Statements:
SetContext(ExpressionContext.MethodBody);
break;
case FrameType.ParameterList:
SetContext(ExpressionContext.ParameterType);
SetContext(CSharpExpressionContext.ParameterType);
break;
case FrameType.ObjectInitializer:
if (state == FrameState.ObjectInitializerValue) {
SetContext(ExpressionContext.Default);
} else {
SetContext(ExpressionContext.ObjectInitializer);
SetContext(CSharpExpressionContext.ObjectInitializer);
}
break;
case FrameType.AttributeSection:
@ -479,7 +479,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -479,7 +479,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
{
frame.type = FrameType.TypeParameterDecl;
frame.SetContext(ExpressionContext.IdentifierExpected);
frame.parent.SetContext(ExpressionContext.ConstraintsStart);
frame.parent.SetContext(CSharpExpressionContext.ConstraintsStart);
} else {
frame.SetContext(ExpressionContext.Type);
}
@ -588,7 +588,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -588,7 +588,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
break;
case Tokens.Assign:
if (frame.type == FrameType.Global) {
frame.SetContext(ExpressionContext.FullyQualifiedType);
frame.SetContext(CSharpExpressionContext.FullyQualifiedType);
break;
} else if (frame.type == FrameType.Enum) {
frame.SetContext(ExpressionContext.Default);
@ -609,7 +609,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -609,7 +609,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
}
case Tokens.Colon:
if (frame.state == FrameState.MethodDecl && lastToken == Tokens.CloseParenthesis) {
frame.SetContext(ExpressionContext.BaseConstructorCall);
frame.SetContext(CSharpExpressionContext.BaseConstructorCall);
frame.parenthesisChildType = FrameType.Expression;
} else {
if (frame.curlyChildType == FrameType.TypeDecl || frame.curlyChildType == FrameType.Interface || frame.curlyChildType == FrameType.Enum) {
@ -692,7 +692,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp @@ -692,7 +692,7 @@ namespace ICSharpCode.SharpDevelop.Dom.CSharp
|| frame.parent.state == FrameState.FieldDecl))
{
frame.type = FrameType.ParameterList;
frame.SetContext(ExpressionContext.FirstParameterType);
frame.SetContext(CSharpExpressionContext.FirstParameterType);
frame.parent.state = FrameState.MethodDecl;
frame.parent.curlyChildType = FrameType.Statements;
}

78
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ExpressionContext.cs

@ -59,67 +59,6 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -59,67 +59,6 @@ namespace ICSharpCode.SharpDevelop.Dom
}
#endregion
#region C# specific contexts (public static fields) * MOVE TO ANOTHER CLASS *
/// <summary>The context expects a new identifier</summary>
/// <example>class *expr* {}; string *expr*;</example>
public readonly static ExpressionContext IdentifierExpected = new DefaultExpressionContext("IdentifierExpected");
/// <summary>The context is outside of any type declaration, expecting a global-level keyword.</summary>
public readonly static ExpressionContext Global = new DefaultExpressionContext("Global");
/// <summary>The context is the body of a property declaration.</summary>
/// <example>string Name { *expr* }</example>
public readonly static ExpressionContext PropertyDeclaration = new DefaultExpressionContext("PropertyDeclaration");
/// <summary>The context is the body of a property declaration inside an interface.</summary>
/// <example>string Name { *expr* }</example>
public readonly static ExpressionContext InterfacePropertyDeclaration = new DefaultExpressionContext("InterfacePropertyDeclaration");
/// <summary>The context is the body of a event declaration.</summary>
/// <example>event EventHandler NameChanged { *expr* }</example>
public readonly static ExpressionContext EventDeclaration = new DefaultExpressionContext("EventDeclaration");
/// <summary>The context is the body of a method.</summary>
/// <example>void Main () { *expr* }</example>
public readonly static ExpressionContext MethodBody = new DefaultExpressionContext("MethodBody");
/// <summary>The context is after the type parameters of a type/method declaration.
/// The only valid keyword is "where"</summary>
/// <example>class &lt;T&gt; *expr*</example>
public readonly static ExpressionContext ConstraintsStart = new DefaultExpressionContext("ConstraintsStart");
/// <summary>The context is after the 'where' of a constraints list.</summary>
/// <example>class &lt;T&gt; where *expr*</example>
public readonly static ExpressionContext Constraints = new NonStaticTypeExpressionContext("Constraints", false);
/// <summary>The context is the body of a type declaration.</summary>
public readonly static ExpressionContext TypeDeclaration = new NonStaticTypeExpressionContext("TypeDeclaration", true);
/// <summary>The context is the body of an interface declaration.</summary>
public readonly static ExpressionContext InterfaceDeclaration = new NonStaticTypeExpressionContext("InterfaceDeclaration", true);
/// <summary>Context expects "base" or "this".</summary>
/// <example>public ClassName() : *expr*</example>
public readonly static ExpressionContext BaseConstructorCall = new DefaultExpressionContext("BaseConstructorCall");
/// <summary>The first parameter</summary>
/// <example>void MethodName(*expr*)</example>
public readonly static ExpressionContext FirstParameterType = new NonStaticTypeExpressionContext("FirstParameterType", false);
/// <summary>Another parameter</summary>
/// <example>void MethodName(..., *expr*)</example>
public readonly static ExpressionContext ParameterType = new NonStaticTypeExpressionContext("ParameterType", false);
/// <summary>Context expects a fully qualified type name.</summary>
/// <example>using Alias = *expr*;</example>
public readonly static ExpressionContext FullyQualifiedType = new DefaultExpressionContext("FullyQualifiedType");
/// <summary>Context expects is a property name in an object initializer.</summary>
/// <example>new *type* [(args)] { *expr* = ... }</example>
public readonly static ExpressionContext ObjectInitializer = new DefaultExpressionContext("ObjectInitializer");
#endregion
#region VB specific contexts (public static fields) * MOVE TO ANOTHER CLASS *
/// <summary>The context expects a new parameter declaration</summary>
/// <example>Function Test(*expr*, *expr*, ...)</example>
@ -185,10 +124,23 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -185,10 +124,23 @@ namespace ICSharpCode.SharpDevelop.Dom
/// <example>public event *expr*</example>
public readonly static ExpressionContext DelegateType = new ClassTypeExpressionContext(ClassType.Delegate);
/// <summary>The context expects a new identifier</summary>
/// <example>class *expr* {}; string *expr*;</example>
public readonly static ExpressionContext IdentifierExpected = new DefaultExpressionContext("IdentifierExpected");
/// <summary>The context is outside of any type declaration, expecting a global-level keyword.</summary>
public readonly static ExpressionContext Global = new DefaultExpressionContext("Global");
/// <summary>The context is the body of a type declaration.</summary>
public readonly static ExpressionContext TypeDeclaration = new ExpressionContext.NonStaticTypeExpressionContext("TypeDeclaration", true);
/// <summary>The context is the body of a method.</summary>
/// <example>void Main () { *expr* }</example>
public readonly static ExpressionContext MethodBody = new ExpressionContext.DefaultExpressionContext("MethodBody");
#endregion
#region DefaultExpressionContext
sealed class DefaultExpressionContext : ExpressionContext
internal sealed class DefaultExpressionContext : ExpressionContext
{
string name;
@ -500,7 +452,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -500,7 +452,7 @@ namespace ICSharpCode.SharpDevelop.Dom
#endregion
#region NonStaticTypeExpressionContext
sealed class NonStaticTypeExpressionContext : ExpressionContext
internal sealed class NonStaticTypeExpressionContext : ExpressionContext
{
string name;
bool allowVoid;

29
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryResolver.cs

@ -7,14 +7,15 @@ @@ -7,14 +7,15 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.IO;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors;
using ICSharpCode.SharpDevelop.Dom.CSharp;
using NR = ICSharpCode.NRefactory;
namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
@ -236,7 +237,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -236,7 +237,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
ResolveResult rr;
if (expressionResult.Context == ExpressionContext.Attribute) {
return ResolveAttribute(expr, new NR.Location(caretColumn, caretLine));
} else if (expressionResult.Context == ExpressionContext.ObjectInitializer && expr is IdentifierExpression) {
} else if (expressionResult.Context == CSharpExpressionContext.ObjectInitializer && expr is IdentifierExpression) {
bool isCollectionInitializer;
rr = ResolveObjectInitializer((expr as IdentifierExpression).Identifier, fileContent, out isCollectionInitializer);
if (!isCollectionInitializer || rr != null) {
@ -1145,7 +1146,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1145,7 +1146,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.TypeLevel);
AddCSharpPrimitiveTypes(result);
CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces);
} else if (context == ExpressionContext.InterfaceDeclaration) {
} else if (context == CSharpExpressionContext.InterfaceDeclaration) {
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.InterfaceLevel);
AddCSharpPrimitiveTypes(result);
CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces);
@ -1156,15 +1157,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1156,15 +1157,15 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces);
} else if (context == ExpressionContext.Global) {
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.GlobalLevel);
} else if (context == ExpressionContext.InterfacePropertyDeclaration) {
} else if (context == CSharpExpressionContext.InterfacePropertyDeclaration) {
result.Add(new KeywordEntry("get"));
result.Add(new KeywordEntry("set"));
} else if (context == ExpressionContext.BaseConstructorCall) {
} else if (context == CSharpExpressionContext.BaseConstructorCall) {
result.Add(new KeywordEntry("this"));
result.Add(new KeywordEntry("base"));
} else if (context == ExpressionContext.ConstraintsStart) {
} else if (context == CSharpExpressionContext.ConstraintsStart) {
result.Add(new KeywordEntry("where"));
} else if (context == ExpressionContext.Constraints) {
} else if (context == CSharpExpressionContext.Constraints) {
result.Add(new KeywordEntry("where"));
result.Add(new KeywordEntry("new"));
result.Add(new KeywordEntry("struct"));
@ -1175,24 +1176,24 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -1175,24 +1176,24 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
result.Add(new KeywordEntry("where")); // the inheritance list can be followed by constraints
AddCSharpPrimitiveTypes(result);
CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces);
} else if (context == ExpressionContext.PropertyDeclaration) {
} else if (context == CSharpExpressionContext.PropertyDeclaration) {
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.InPropertyDeclaration);
} else if (context == ExpressionContext.EventDeclaration) {
} else if (context == CSharpExpressionContext.EventDeclaration) {
AddCSharpKeywords(result, NR.Parser.CSharp.Tokens.InEventDeclaration);
} else if (context == ExpressionContext.FullyQualifiedType) {
} else if (context == CSharpExpressionContext.FullyQualifiedType) {
cu.ProjectContent.AddNamespaceContents(result, "", languageProperties, true);
} else if (context == ExpressionContext.ParameterType || context == ExpressionContext.FirstParameterType) {
} else if (context == CSharpExpressionContext.ParameterType || context == CSharpExpressionContext.FirstParameterType) {
result.Add(new KeywordEntry("ref"));
result.Add(new KeywordEntry("out"));
result.Add(new KeywordEntry("params"));
if (context == ExpressionContext.FirstParameterType && languageProperties.SupportsExtensionMethods) {
if (context == CSharpExpressionContext.FirstParameterType && languageProperties.SupportsExtensionMethods) {
if (callingMember != null && callingMember.IsStatic) {
result.Add(new KeywordEntry("this"));
}
}
AddCSharpPrimitiveTypes(result);
CtrlSpaceInternal(result, fileContent, showEntriesFromAllNamespaces);
} else if (context == ExpressionContext.ObjectInitializer) {
} else if (context == CSharpExpressionContext.ObjectInitializer) {
bool isCollectionInitializer;
result.AddRange(ObjectInitializerCtrlSpace(fileContent, out isCollectionInitializer));
if (isCollectionInitializer) {

6
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/VBNet/VBNetExpressionFinder.cs

@ -77,9 +77,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet @@ -77,9 +77,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
p.Advance();
}
if (p.IsIdentifierExpected)
context = ExpressionContext.IdentifierExpected;
BitArray expectedSet;
try {
@ -93,7 +90,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet @@ -93,7 +90,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
int lastExpressionStartOffset = LocationToOffset(block.lastExpressionStart);
if (lastExpressionStartOffset < 0)
return new ExpressionResult(null, DomRegion.Empty, context, expectedSet);
@ -133,8 +129,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet @@ -133,8 +129,6 @@ namespace ICSharpCode.SharpDevelop.Dom.VBNet
switch (block.context) {
case Context.Global:
return ExpressionContext.Global;
case Context.IdentifierExpected:
return ExpressionContext.IdentifierExpected;
case Context.TypeDeclaration:
return ExpressionContext.TypeDeclaration;
case Context.Type:

Loading…
Cancel
Save