Skip to content

Commit 5115584

Browse files
committed
add fixed-buffer array parsing support
1 parent f13a9b1 commit 5115584

File tree

12 files changed

+1523
-1680
lines changed

12 files changed

+1523
-1680
lines changed

csharp-psi-api/src/main/java/consulo/csharp/lang/psi/CSharpFieldDeclaration.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
package consulo.csharp.lang.psi;
1818

1919
import consulo.dotnet.psi.DotNetFieldDeclaration;
20+
import jakarta.annotation.Nullable;
2021

2122
/**
2223
* @author VISTALL
2324
* @since 15.01.14
2425
*/
25-
public interface CSharpFieldDeclaration extends DotNetFieldDeclaration, CSharpNamedElement
26-
{
26+
public interface CSharpFieldDeclaration extends DotNetFieldDeclaration, CSharpNamedElement {
27+
@Nullable
28+
default CSharpFixedSizeBufferInitializer getFixedSizeBufferInitializer() {
29+
return null;
30+
}
2731
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2013-2025 consulo.io
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package consulo.csharp.lang.psi;
18+
19+
import consulo.annotation.access.RequiredReadAction;
20+
import consulo.dotnet.psi.DotNetElement;
21+
import consulo.dotnet.psi.DotNetExpression;
22+
import jakarta.annotation.Nullable;
23+
24+
/**
25+
* @author VISTALL
26+
* @since 2025-10-19
27+
*/
28+
public interface CSharpFixedSizeBufferInitializer extends DotNetElement {
29+
@Nullable
30+
@RequiredReadAction
31+
DotNetExpression getInitializer();
32+
}

csharp-psi-api/src/main/java/consulo/csharp/lang/psi/CSharpModifier.java

Lines changed: 67 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,89 +28,80 @@
2828
* @author VISTALL
2929
* @since 06.01.14.
3030
*/
31-
public enum CSharpModifier implements DotNetModifier
32-
{
33-
PUBLIC,
34-
PRIVATE,
35-
PROTECTED,
36-
STATIC,
37-
SEALED,
38-
READONLY,
39-
UNSAFE,
40-
PARAMS,
41-
THIS,
42-
ABSTRACT,
43-
PARTIAL,
44-
INTERNAL,
45-
REF,
46-
NEW,
47-
OVERRIDE,
48-
VIRTUAL,
49-
OUT,
50-
ASYNC,
51-
IN,
52-
EXTERN,
53-
INTERFACE_ABSTRACT, // dummy modifier
54-
OPTIONAL; // dummy modifier
31+
public enum CSharpModifier implements DotNetModifier {
32+
PUBLIC,
33+
PRIVATE,
34+
PROTECTED,
35+
STATIC,
36+
SEALED,
37+
READONLY,
38+
UNSAFE,
39+
PARAMS,
40+
THIS,
41+
ABSTRACT,
42+
PARTIAL,
43+
INTERNAL,
44+
REF,
45+
NEW,
46+
OVERRIDE,
47+
VIRTUAL,
48+
OUT,
49+
ASYNC,
50+
IN,
51+
EXTERN,
52+
INTERFACE_ABSTRACT, // dummy modifier
53+
OPTIONAL, // dummy modifier
54+
FIXED;
5555

56-
public static final CSharpModifier[] EMPTY_ARRAY = new CSharpModifier[0];
56+
public static final CSharpModifier[] EMPTY_ARRAY = new CSharpModifier[0];
5757

58-
public static ArrayFactory<CSharpModifier> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new CSharpModifier[count];
58+
public static ArrayFactory<CSharpModifier> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new CSharpModifier[count];
5959

60-
private static Map<DotNetModifier, CSharpModifier> ourReplaceMap = new HashMap<DotNetModifier, CSharpModifier>()
61-
{
62-
{
63-
put(DotNetModifier.STATIC, CSharpModifier.STATIC);
64-
put(DotNetModifier.PRIVATE, CSharpModifier.PRIVATE);
65-
put(DotNetModifier.PUBLIC, CSharpModifier.PUBLIC);
66-
put(DotNetModifier.PROTECTED, CSharpModifier.PROTECTED);
67-
put(DotNetModifier.INTERNAL, CSharpModifier.INTERNAL);
68-
put(DotNetModifier.ABSTRACT, CSharpModifier.ABSTRACT);
69-
put(DotNetModifier.SEALED, CSharpModifier.SEALED);
70-
put(DotNetModifier.COVARIANT, CSharpModifier.OUT);
71-
put(DotNetModifier.CONTRAVARIANT, CSharpModifier.IN);
72-
}
73-
};
60+
private static Map<DotNetModifier, CSharpModifier> ourReplaceMap = new HashMap<>() {
61+
{
62+
put(DotNetModifier.STATIC, CSharpModifier.STATIC);
63+
put(DotNetModifier.PRIVATE, CSharpModifier.PRIVATE);
64+
put(DotNetModifier.PUBLIC, CSharpModifier.PUBLIC);
65+
put(DotNetModifier.PROTECTED, CSharpModifier.PROTECTED);
66+
put(DotNetModifier.INTERNAL, CSharpModifier.INTERNAL);
67+
put(DotNetModifier.ABSTRACT, CSharpModifier.ABSTRACT);
68+
put(DotNetModifier.SEALED, CSharpModifier.SEALED);
69+
put(DotNetModifier.COVARIANT, CSharpModifier.OUT);
70+
put(DotNetModifier.CONTRAVARIANT, CSharpModifier.IN);
71+
}
72+
};
7473

75-
private int myMask;
74+
private int myMask;
7675

77-
CSharpModifier()
78-
{
79-
myMask = 1 << ordinal();
80-
}
76+
CSharpModifier() {
77+
myMask = 1 << ordinal();
78+
}
8179

82-
public int mask()
83-
{
84-
return myMask;
85-
}
80+
public int mask() {
81+
return myMask;
82+
}
8683

87-
@Override
88-
public String toString()
89-
{
90-
return getPresentableText();
91-
}
84+
@Override
85+
public String toString() {
86+
return getPresentableText();
87+
}
9288

93-
@Override
94-
public String getPresentableText()
95-
{
96-
return name().toLowerCase(Locale.US);
97-
}
89+
@Override
90+
public String getPresentableText() {
91+
return name().toLowerCase(Locale.US);
92+
}
9893

99-
@Nonnull
100-
public static CSharpModifier as(DotNetModifier modifierWithMask)
101-
{
102-
if(modifierWithMask instanceof CSharpModifier)
103-
{
104-
return (CSharpModifier) modifierWithMask;
105-
}
106-
else
107-
{
108-
CSharpModifier cSharpModifier = ourReplaceMap.get(modifierWithMask);
109-
if(cSharpModifier != null)
110-
{
111-
return cSharpModifier;
112-
}
113-
throw new IllegalArgumentException(modifierWithMask + " is cant be casted to CSharpModifier");
114-
}
115-
}
94+
@Nonnull
95+
public static CSharpModifier as(DotNetModifier modifierWithMask) {
96+
if (modifierWithMask instanceof CSharpModifier) {
97+
return (CSharpModifier) modifierWithMask;
98+
}
99+
else {
100+
CSharpModifier cSharpModifier = ourReplaceMap.get(modifierWithMask);
101+
if (cSharpModifier != null) {
102+
return cSharpModifier;
103+
}
104+
throw new IllegalArgumentException(modifierWithMask + " is cant be casted to CSharpModifier");
105+
}
106+
}
116107
}

0 commit comments

Comments
 (0)