Skip to content

Commit ae4d051

Browse files
committed
Add .editorconfig and convert tabs to spaces
1 parent 97af395 commit ae4d051

File tree

173 files changed

+7924
-7847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+7924
-7847
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
end_of_line = lf
9+
charset = utf-8
10+
insert_final_newline = true

src/main/java/org/nette/latte/LatteFileType.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,43 @@
1212
import org.nette.latte.syntaxHighlighter.LatteEditorHighlighter;
1313
import org.jetbrains.annotations.NotNull;
1414
import org.jetbrains.annotations.Nullable;
15+
1516
import javax.swing.*;
1617

1718
public class LatteFileType extends LanguageFileType {
18-
public static final LatteFileType INSTANCE = new LatteFileType();
19-
20-
private LatteFileType() {
21-
super(LatteLanguage.INSTANCE);
22-
23-
FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() {
24-
public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
25-
return new LatteEditorHighlighter(project, virtualFile,colors);
26-
}
27-
});
28-
}
29-
30-
@NotNull
31-
@Override
32-
public String getName() {
33-
return "Latte";
34-
}
35-
36-
@NotNull
37-
@Override
38-
public String getDescription() {
39-
return "Latte template files";
40-
}
41-
42-
@NotNull
43-
@Override
44-
public String getDefaultExtension() {
45-
return "latte";
46-
}
47-
48-
@Nullable
49-
@Override
50-
public Icon getIcon() {
51-
return LatteIcons.FILE;
52-
}
19+
public static final LatteFileType INSTANCE = new LatteFileType();
20+
21+
private LatteFileType() {
22+
super(LatteLanguage.INSTANCE);
23+
24+
FileTypeEditorHighlighterProviders.INSTANCE.addExplicitExtension(this, new EditorHighlighterProvider() {
25+
public EditorHighlighter getEditorHighlighter(@Nullable Project project, @NotNull FileType fileType, @Nullable VirtualFile virtualFile, @NotNull EditorColorsScheme colors) {
26+
return new LatteEditorHighlighter(project, virtualFile, colors);
27+
}
28+
});
29+
}
30+
31+
@NotNull
32+
@Override
33+
public String getName() {
34+
return "Latte";
35+
}
36+
37+
@NotNull
38+
@Override
39+
public String getDescription() {
40+
return "Latte template files";
41+
}
42+
43+
@NotNull
44+
@Override
45+
public String getDefaultExtension() {
46+
return "latte";
47+
}
48+
49+
@Nullable
50+
@Override
51+
public Icon getIcon() {
52+
return LatteIcons.FILE;
53+
}
5354
}

src/main/java/org/nette/latte/LatteLanguage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.intellij.lang.Language;
44

55
public class LatteLanguage extends Language {
6-
public static final LatteLanguage INSTANCE = new LatteLanguage();
6+
public static final LatteLanguage INSTANCE = new LatteLanguage();
77

8-
private LatteLanguage() {
9-
super("Latte");
10-
}
8+
private LatteLanguage() {
9+
super("Latte");
10+
}
1111
}

src/main/java/org/nette/latte/annotator/LatteAnnotator.java

Lines changed: 124 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -20,128 +20,128 @@
2020
* Annotator is mostly used to check semantic rules which can not be easily checked during parsing.
2121
*/
2222
public class LatteAnnotator implements Annotator {
23-
@Override
24-
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
25-
if (element instanceof LatteMacroClassic) {
26-
checkMacroClassic((LatteMacroClassic) element, holder);
27-
28-
} else if (element instanceof LatteNetteAttr) {
29-
checkNetteAttr((LatteNetteAttr) element, holder);
30-
31-
} else if (element instanceof LeafPsiElement && element.getParent().getLastChild() instanceof PsiErrorElement) {
32-
LeafPsiElement leaf = (LeafPsiElement) element;
33-
if (leaf.getElementType() == LatteTypes.T_MACRO_OPEN_TAG_OPEN || leaf.getElementType() == LatteTypes.T_MACRO_CLOSE_TAG_OPEN) {
34-
createErrorAnnotation(holder, "Malformed tag. Missing closing }");
35-
}
36-
}
37-
}
38-
39-
private void checkNetteAttr(@NotNull LatteNetteAttr element, @NotNull AnnotationHolder holder) {
40-
PsiElement attrName = element.getAttrName();
41-
String tagName = attrName.getText();
42-
boolean prefixed = false;
43-
44-
if (tagName.startsWith("n:inner-")) {
45-
prefixed = true;
46-
tagName = tagName.substring(8);
47-
} else if (tagName.startsWith("n:tag-")) {
48-
prefixed = true;
49-
tagName = tagName.substring(6);
50-
} else {
51-
tagName = tagName.substring(2);
52-
}
53-
54-
Project project = element.getProject();
55-
LatteTagSettings macro = LatteConfiguration.getInstance(project).getTag(tagName);
56-
if (macro == null || macro.getType() == LatteTagSettings.Type.UNPAIRED) {
57-
AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "Unknown attribute tag " + attrName.getText())
58-
.range(attrName)
59-
.withFix(new AddCustomPairMacro(tagName));
60-
if (!prefixed) {
61-
builder = builder.withFix(new AddCustomAttrOnlyMacro(tagName));
62-
}
63-
builder.create();
64-
65-
} else if (prefixed && macro.getType() != LatteTagSettings.Type.PAIR && macro.getType() != LatteTagSettings.Type.AUTO_EMPTY) {
66-
createErrorAnnotation(holder, attrName, "Attribute tag n:" + tagName + " can not be used with prefix.");
67-
}
68-
}
69-
70-
private void checkMacroClassic(@NotNull LatteMacroClassic element, @NotNull AnnotationHolder holder) {
71-
LatteMacroTag openTag = element.getOpenTag();
72-
LatteMacroTag closeTag = element.getCloseTag();
73-
74-
String openTagName = openTag.getMacroName();
75-
LatteTagSettings macro = LatteConfiguration.getInstance(element.getProject()).getTag(openTagName);
76-
if (macro == null || macro.getType() == LatteTagSettings.Type.ATTR_ONLY) {
77-
boolean isOk = false;
78-
LatteMacroContent content = openTag.getMacroContent();
79-
if (content != null) {
80-
LattePhpContent phpContent = content.getFirstPhpContent();
81-
if (phpContent != null && phpContent.getFirstChild() instanceof LattePhpVariable) {
82-
isOk = true;
83-
}
84-
}
85-
86-
if (!isOk) {
87-
if (macro != null) {
88-
createErrorAnnotation(holder, openTag, "Can not use n:" + openTagName + " attribute as normal tag");
89-
if (closeTag != null) {
90-
createErrorAnnotation(holder, closeTag, "Tag n:" + openTagName + " can not be used as pair tag");
91-
}
92-
93-
} else {
94-
AnnotationBuilder annotation = holder.newAnnotation(HighlightSeverity.ERROR, "Unknown tag {" + openTagName + "}").range(openTag);
95-
annotation = annotation.withFix(new AddCustomPairMacro(openTagName));
96-
annotation = annotation.withFix(new AddCustomUnpairedMacro(openTagName));
97-
annotation.create();
98-
}
99-
}
100-
}
101-
102-
String closeTagName = closeTag != null ? closeTag.getMacroName() : null;
103-
if (closeTagName != null && !closeTagName.isEmpty() && !closeTagName.equals(openTagName)) {
104-
createErrorAnnotation(holder, closeTag, "Unexpected {/" + closeTagName + "}, expected {/" + openTagName + "}");
105-
}
106-
107-
if (
108-
macro != null
109-
&& closeTag == null
110-
&& ((element instanceof LattePairMacro && macro.getType() == LatteTagSettings.Type.AUTO_EMPTY) || macro.getType() == LatteTagSettings.Type.PAIR)
111-
) {
112-
final int[] unclosed = {0};
113-
openTag.getParent().acceptChildren(new PsiRecursiveElementWalkingVisitor() {
114-
@Override
115-
public void visitElement(@NotNull PsiElement element) {
116-
if (element instanceof LattePairMacro) {
117-
LatteMacroTag tag = ((LattePairMacro) element).getOpenTag();
118-
if (tag.getMacroName().equals("block") && ((LattePairMacro) element).getCloseTag() == null) {
119-
unclosed[0]++;
120-
} else {
121-
super.visitElement(element);
122-
}
123-
124-
} else {
125-
super.visitElement(element);
126-
}
127-
}
128-
});
129-
//PsiElement el = PsiTreeUtil.getChildOfAnyType(openTag.getParent(), LattePairMacro.class);
130-
if (!macro.isTagBlock() || unclosed[0] > 0) {
131-
createErrorAnnotation(holder, openTag, "Unclosed tag " + openTagName);
132-
}
133-
}
134-
}
135-
136-
private void createErrorAnnotation(final @NotNull AnnotationHolder holder, final @NotNull String message) {
137-
holder.newAnnotation(HighlightSeverity.ERROR, message).create();
138-
}
139-
140-
private void createErrorAnnotation(
141-
final @NotNull AnnotationHolder holder,
142-
final @NotNull PsiElement element,
143-
final @NotNull String message
144-
) {
145-
holder.newAnnotation(HighlightSeverity.ERROR, message).range(element).create();
146-
}
23+
@Override
24+
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
25+
if (element instanceof LatteMacroClassic) {
26+
checkMacroClassic((LatteMacroClassic) element, holder);
27+
28+
} else if (element instanceof LatteNetteAttr) {
29+
checkNetteAttr((LatteNetteAttr) element, holder);
30+
31+
} else if (element instanceof LeafPsiElement && element.getParent().getLastChild() instanceof PsiErrorElement) {
32+
LeafPsiElement leaf = (LeafPsiElement) element;
33+
if (leaf.getElementType() == LatteTypes.T_MACRO_OPEN_TAG_OPEN || leaf.getElementType() == LatteTypes.T_MACRO_CLOSE_TAG_OPEN) {
34+
createErrorAnnotation(holder, "Malformed tag. Missing closing }");
35+
}
36+
}
37+
}
38+
39+
private void checkNetteAttr(@NotNull LatteNetteAttr element, @NotNull AnnotationHolder holder) {
40+
PsiElement attrName = element.getAttrName();
41+
String tagName = attrName.getText();
42+
boolean prefixed = false;
43+
44+
if (tagName.startsWith("n:inner-")) {
45+
prefixed = true;
46+
tagName = tagName.substring(8);
47+
} else if (tagName.startsWith("n:tag-")) {
48+
prefixed = true;
49+
tagName = tagName.substring(6);
50+
} else {
51+
tagName = tagName.substring(2);
52+
}
53+
54+
Project project = element.getProject();
55+
LatteTagSettings macro = LatteConfiguration.getInstance(project).getTag(tagName);
56+
if (macro == null || macro.getType() == LatteTagSettings.Type.UNPAIRED) {
57+
AnnotationBuilder builder = holder.newAnnotation(HighlightSeverity.ERROR, "Unknown attribute tag " + attrName.getText())
58+
.range(attrName)
59+
.withFix(new AddCustomPairMacro(tagName));
60+
if (!prefixed) {
61+
builder = builder.withFix(new AddCustomAttrOnlyMacro(tagName));
62+
}
63+
builder.create();
64+
65+
} else if (prefixed && macro.getType() != LatteTagSettings.Type.PAIR && macro.getType() != LatteTagSettings.Type.AUTO_EMPTY) {
66+
createErrorAnnotation(holder, attrName, "Attribute tag n:" + tagName + " can not be used with prefix.");
67+
}
68+
}
69+
70+
private void checkMacroClassic(@NotNull LatteMacroClassic element, @NotNull AnnotationHolder holder) {
71+
LatteMacroTag openTag = element.getOpenTag();
72+
LatteMacroTag closeTag = element.getCloseTag();
73+
74+
String openTagName = openTag.getMacroName();
75+
LatteTagSettings macro = LatteConfiguration.getInstance(element.getProject()).getTag(openTagName);
76+
if (macro == null || macro.getType() == LatteTagSettings.Type.ATTR_ONLY) {
77+
boolean isOk = false;
78+
LatteMacroContent content = openTag.getMacroContent();
79+
if (content != null) {
80+
LattePhpContent phpContent = content.getFirstPhpContent();
81+
if (phpContent != null && phpContent.getFirstChild() instanceof LattePhpVariable) {
82+
isOk = true;
83+
}
84+
}
85+
86+
if (!isOk) {
87+
if (macro != null) {
88+
createErrorAnnotation(holder, openTag, "Can not use n:" + openTagName + " attribute as normal tag");
89+
if (closeTag != null) {
90+
createErrorAnnotation(holder, closeTag, "Tag n:" + openTagName + " can not be used as pair tag");
91+
}
92+
93+
} else {
94+
AnnotationBuilder annotation = holder.newAnnotation(HighlightSeverity.ERROR, "Unknown tag {" + openTagName + "}").range(openTag);
95+
annotation = annotation.withFix(new AddCustomPairMacro(openTagName));
96+
annotation = annotation.withFix(new AddCustomUnpairedMacro(openTagName));
97+
annotation.create();
98+
}
99+
}
100+
}
101+
102+
String closeTagName = closeTag != null ? closeTag.getMacroName() : null;
103+
if (closeTagName != null && !closeTagName.isEmpty() && !closeTagName.equals(openTagName)) {
104+
createErrorAnnotation(holder, closeTag, "Unexpected {/" + closeTagName + "}, expected {/" + openTagName + "}");
105+
}
106+
107+
if (
108+
macro != null
109+
&& closeTag == null
110+
&& ((element instanceof LattePairMacro && macro.getType() == LatteTagSettings.Type.AUTO_EMPTY) || macro.getType() == LatteTagSettings.Type.PAIR)
111+
) {
112+
final int[] unclosed = {0};
113+
openTag.getParent().acceptChildren(new PsiRecursiveElementWalkingVisitor() {
114+
@Override
115+
public void visitElement(@NotNull PsiElement element) {
116+
if (element instanceof LattePairMacro) {
117+
LatteMacroTag tag = ((LattePairMacro) element).getOpenTag();
118+
if (tag.getMacroName().equals("block") && ((LattePairMacro) element).getCloseTag() == null) {
119+
unclosed[0]++;
120+
} else {
121+
super.visitElement(element);
122+
}
123+
124+
} else {
125+
super.visitElement(element);
126+
}
127+
}
128+
});
129+
//PsiElement el = PsiTreeUtil.getChildOfAnyType(openTag.getParent(), LattePairMacro.class);
130+
if (!macro.isTagBlock() || unclosed[0] > 0) {
131+
createErrorAnnotation(holder, openTag, "Unclosed tag " + openTagName);
132+
}
133+
}
134+
}
135+
136+
private void createErrorAnnotation(final @NotNull AnnotationHolder holder, final @NotNull String message) {
137+
holder.newAnnotation(HighlightSeverity.ERROR, message).create();
138+
}
139+
140+
private void createErrorAnnotation(
141+
final @NotNull AnnotationHolder holder,
142+
final @NotNull PsiElement element,
143+
final @NotNull String message
144+
) {
145+
holder.newAnnotation(HighlightSeverity.ERROR, message).range(element).create();
146+
}
147147
}

src/main/java/org/nette/latte/codeStyle/LatteCodeStyleSettings.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.intellij.psi.codeStyle.*;
44

55
public class LatteCodeStyleSettings extends CustomCodeStyleSettings {
6-
public static boolean SPACE_AROUND_CONCATENATION = true;
6+
public static boolean SPACE_AROUND_CONCATENATION = true;
77

8-
public LatteCodeStyleSettings(CodeStyleSettings settings) {
9-
super("LatteCodeStyleSettings", settings);
10-
}
8+
public LatteCodeStyleSettings(CodeStyleSettings settings) {
9+
super("LatteCodeStyleSettings", settings);
10+
}
1111
}

0 commit comments

Comments
 (0)