Skip to content

Commit

Permalink
Merge pull request #49 from nette-intellij/mn-compatibility-issues-1-0-0
Browse files Browse the repository at this point in the history
Mn compatibility issues 1 0 0
  • Loading branch information
mesour authored Feb 17, 2020
2 parents 2ee96ab + 3f4d050 commit 86b2631
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/gen
/out

.DS_Store

/src/com/jantvrdik/intellij/latte/lexer/LatteMacroContentLexer.java
/src/com/jantvrdik/intellij/latte/lexer/LatteMacroLexer.java
/src/com/jantvrdik/intellij/latte/lexer/LatteTopLexer.java
Expand Down
Binary file modified latte-plugin.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.jantvrdik.intellij.latte</id>
<name>Latte</name>
<version>1.0.0</version>
<version>1.0.1</version>
<vendor>Jan Tvrdík</vendor>

<description><![CDATA[
Expand All @@ -18,6 +18,11 @@
]]></description>

<change-notes><![CDATA[
<p>1.0.1</p>
<ul>
<li>Fixed compatibility issues</li>
<li>Fixed structure view (added n:tags and images)</li>
</ul>
<p>1.0.0</p>
<ul>
<li>added support for PHP content</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.jantvrdik.intellij.latte.psi.LatteTypes;
import com.jantvrdik.intellij.latte.utils.LatteUtil;
import com.jetbrains.php.completion.insert.PhpInsertHandlerUtil;
import com.jetbrains.php.completion.insert.PhpReturnKeywordInsertHandler;
import com.jetbrains.php.lang.psi.elements.impl.PhpUseImpl;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -39,10 +38,8 @@ public void handleInsert(@NotNull InsertionContext context, @NotNull LookupEleme
if (notInUse) {
if (!LatteUtil.isStringAtCaret(editor, "(")) {
this.insertParenthesesCodeStyleAware(editor);
possiblyInsertTrailingSemicolon(context);
} else if (LatteUtil.isStringAtCaret(editor, "()")) {
editor.getCaretModel().moveCaretRelatively(2, 0, false, false, true);
possiblyInsertTrailingSemicolon(context);
} else {
editor.getCaretModel().moveCaretRelatively(1, 0, false, false, true);
showParameterInfo(editor);
Expand All @@ -51,10 +48,6 @@ public void handleInsert(@NotNull InsertionContext context, @NotNull LookupEleme
}
}

private static void possiblyInsertTrailingSemicolon(@NotNull InsertionContext context) {
PhpReturnKeywordInsertHandler.insertSemicolonAtCaret(context, true);
}

private void insertParenthesesCodeStyleAware(@NotNull Editor editor) {
PhpInsertHandlerUtil.insertStringAtCaret(editor, "()");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private void attachTemplateTypeCompletions(@NotNull CompletionResultSet result,
if (!field.isConstant() && field.getModifier().isPublic()) {
PhpLookupElement lookupItem = getPhpLookupElement(field, "$" + field.getName());
lookupItem.handler = PhpVariableInsertHandler.getInstance();
lookupItem.icon = PhpIcons.PROPERTY_ICON;
lookupItem.bold = true;
result.addElement(lookupItem);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
package com.jantvrdik.intellij.latte.editor;

import com.intellij.ide.structureView.StructureView;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewModel;
import com.intellij.ide.structureView.StructureViewModelBase;
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
import com.intellij.ide.structureView.impl.StructureViewComposite;
import com.intellij.ide.structureView.impl.TemplateLanguageStructureViewBuilder;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class LatteStructureViewFactory implements PsiStructureViewFactory{

@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new TemplateLanguageStructureViewBuilder(psiFile) {
return new TreeBasedStructureViewBuilder() {
@NotNull
@Override
protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
StructureView mainView = (new TreeBasedStructureViewBuilder() {
@NotNull
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new StructureViewModelBase(psiFile, editor, new LatteStructureViewTreeElement(psiFile));
}
}).createStructureView(fileEditor, mainFile.getProject());
return new StructureViewComposite.StructureViewDescriptor("Latte", mainView, mainFile.getFileType().getIcon());
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new LatteStructureViewModel(psiFile);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jantvrdik.intellij.latte.editor;

import com.intellij.ide.structureView.*;
import com.intellij.ide.util.treeView.smartTree.Sorter;
import com.intellij.psi.PsiFile;
import com.jantvrdik.intellij.latte.psi.LatteFile;
import org.jetbrains.annotations.NotNull;

public class LatteStructureViewModel extends StructureViewModelBase implements StructureViewModel.ElementInfoProvider {
public LatteStructureViewModel(PsiFile psiFile) {
super(psiFile, new LatteStructureViewTreeElement(psiFile));
}

@NotNull
public Sorter[] getSorters() {
return new Sorter[]{Sorter.ALPHA_SORTER};
}

@Override
public boolean isAlwaysShowsPlus(StructureViewTreeElement element) {
return false;
}

@Override
public boolean isAlwaysLeaf(StructureViewTreeElement element) {
return element instanceof LatteFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.structureView.impl.common.PsiTreeElementBase;
import com.intellij.psi.PsiElement;
import com.jantvrdik.intellij.latte.icons.LatteIcons;
import com.jantvrdik.intellij.latte.psi.LatteAutoClosedBlock;
import com.jantvrdik.intellij.latte.psi.LatteFile;
import com.jantvrdik.intellij.latte.psi.LatteMacroClassic;
import com.jantvrdik.intellij.latte.psi.LatteNetteAttr;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.regex.Matcher;
Expand All @@ -28,13 +31,26 @@ public Collection<StructureViewTreeElement> getChildrenBase() {
return elements;
}
for (PsiElement el : getElement().getChildren()) {
if (el instanceof LatteMacroClassic || el instanceof LatteAutoClosedBlock) {
if (el instanceof LatteMacroClassic || el instanceof LatteAutoClosedBlock || el instanceof LatteNetteAttr) {
elements.add(new LatteStructureViewTreeElement(el));
}
}
return elements;
}

@Override
public Icon getIcon(boolean open) {
PsiElement element = getElement();
if (element instanceof LatteMacroClassic || element instanceof LatteAutoClosedBlock) {
return LatteIcons.MACRO;
} else if (element instanceof LatteNetteAttr) {
return LatteIcons.N_TAG;
} else if (element instanceof LatteFile) {
return LatteIcons.FILE;
}
return super.getIcon(open);
}

@Nullable
@Override
public String getPresentableText() {
Expand All @@ -52,6 +68,8 @@ public String getPresentableText() {

}
return presentableText;
} else if (element instanceof LatteNetteAttr) {
return ((LatteNetteAttr) element).getAttrName().getText();
} else if (element instanceof LatteFile) {
return ((LatteFile) element).getName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static LattePhpType detectVariableTypeFromTemplateType(@NotNull PsiElemen
for (PhpClass phpClass : classes) {
for (Field field : phpClass.getFields()) {
if (!field.isConstant() && field.getModifier().isPublic() && variableName.equals(field.getName())) {
return new LattePhpType(field.getName(), field.getType().toString(), field.getType().isNullable());
return new LattePhpType(field.getName(), field.getType().toString(), LattePhpUtil.isNullable(field.getType()));
}
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public static LattePhpType getReturnType(@NotNull LattePhpMethod element) {

for (Method phpMethod : first.getMethods()) {
if (phpMethod.getName().equals(name)) {
return new LattePhpType(phpMethod.getType().toString(), phpMethod.getType().isNullable());
return new LattePhpType(phpMethod.getType().toString(), LattePhpUtil.isNullable(phpMethod.getType()));
}
}
return null;
Expand All @@ -250,7 +250,7 @@ private static LattePhpType getPropertyType(@NotNull Project project, @NotNull L

for (Field field : first.getFields()) {
if (field.getName().equals(LattePhpUtil.normalizePhpVariable(elementName))) {
return new LattePhpType(field.getType().toString(), field.getType().isNullable());
return new LattePhpType(field.getType().toString(), LattePhpUtil.isNullable(field.getType()));
}
}
return null;
Expand Down
20 changes: 10 additions & 10 deletions src/com/jantvrdik/intellij/latte/utils/LattePhpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.jantvrdik.intellij.latte.psi.elements.BaseLattePhpElement;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.*;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -43,8 +44,7 @@ public static String normalizePhpVariable(String name) {
return name.startsWith("$") ? name.substring(1) : name;
}

public static boolean isReferenceTo(@NotNull PhpClass originalClass, @NotNull ResolveResult[] results, @NotNull PsiElement element, @NotNull String name)
{
public static boolean isReferenceTo(@NotNull PhpClass originalClass, @NotNull ResolveResult[] results, @NotNull PsiElement element, @NotNull String name) {
for (ResolveResult result : results) {
if (!(result.getElement() instanceof BaseLattePhpElement)) {
continue;
Expand All @@ -66,13 +66,15 @@ public static boolean isReferenceTo(@NotNull PhpClass originalClass, @NotNull Re
return false;
}

public static boolean isReferenceFor(@NotNull PhpClass originalClass, @NotNull PhpClass targetClass)
{
public static boolean isNullable(@NotNull PhpType type) {
return false;
}

public static boolean isReferenceFor(@NotNull PhpClass originalClass, @NotNull PhpClass targetClass) {
return isReferenceFor(originalClass.getFQN(), targetClass);
}

public static boolean isReferenceFor(@NotNull String originalClass, @NotNull PhpClass targetClass)
{
public static boolean isReferenceFor(@NotNull String originalClass, @NotNull PhpClass targetClass) {
originalClass = normalizeClassName(originalClass);
if (originalClass.equals(targetClass.getFQN())) {
return true;
Expand All @@ -87,8 +89,7 @@ public static boolean isReferenceFor(@NotNull String originalClass, @NotNull Php
return false;
}

public static List<Field> getFieldsForPhpElement(@NotNull BaseLattePhpElement psiElement)
{
public static List<Field> getFieldsForPhpElement(@NotNull BaseLattePhpElement psiElement) {
List<Field> out = new ArrayList<Field>();
LattePhpType phpType = psiElement.getPhpType();
String name = psiElement.getPhpElementName();
Expand Down Expand Up @@ -120,8 +121,7 @@ public static List<Field> getFieldsForPhpElement(@NotNull BaseLattePhpElement ps
return fields;
}

public static List<Method> getMethodsForPhpElement(@NotNull LattePhpMethod psiElement)
{
public static List<Method> getMethodsForPhpElement(@NotNull LattePhpMethod psiElement) {
List<Method> out = new ArrayList<Method>();
Collection<PhpClass> phpClasses = psiElement.getPhpType().getPhpClasses(psiElement.getProject());
if (phpClasses != null && phpClasses.size() > 0) {
Expand Down

0 comments on commit 86b2631

Please sign in to comment.