-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd7951e
commit 4fe4ac2
Showing
21 changed files
with
531 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/kdb/inside/brains/psi/impl/QSymbolElementImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.kdb.inside.brains.psi.impl; | ||
|
||
import com.intellij.lang.ASTNode; | ||
import com.intellij.navigation.ItemPresentation; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.util.IncorrectOperationException; | ||
import icons.KdbIcons; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.kdb.inside.brains.psi.QPsiUtil; | ||
import org.kdb.inside.brains.psi.QSymbol; | ||
|
||
import java.util.Optional; | ||
|
||
public class QSymbolElementImpl extends QPsiElementImpl implements QSymbol { | ||
public QSymbolElementImpl(ASTNode node) { | ||
super(node); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return getText().substring(1); | ||
} | ||
|
||
@Override | ||
public @Nullable String getQualifiedName() { | ||
return getName(); | ||
} | ||
|
||
@Override | ||
public ItemPresentation getPresentation() { | ||
return new VariablePresentation(this, KdbIcons.Node.Symbol); | ||
} | ||
|
||
@Override | ||
public int getTextOffset() { | ||
return super.getTextOffset() + 1; | ||
} | ||
|
||
@Override | ||
public @Nullable PsiElement getNameIdentifier() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public PsiElement setName(@NotNull String newName) throws IncorrectOperationException { | ||
Optional.ofNullable(QPsiUtil.createSymbol(getProject(), newName.charAt(0) == '`' ? newName : "`" + newName)) | ||
.map(QSymbol::getFirstChild) | ||
.map(PsiElement::getNode) | ||
.ifPresent(newKeyNode -> { | ||
final ASTNode keyNode = getNode().getFirstChildNode(); | ||
getNode().replaceChild(keyNode, newKeyNode); | ||
}); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/org/kdb/inside/brains/psi/impl/VariablePresentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.kdb.inside.brains.psi.impl; | ||
|
||
import com.intellij.navigation.ItemPresentation; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.PsiQualifiedNamedElement; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
class VariablePresentation implements ItemPresentation { | ||
private final Icon icon; | ||
private final PsiQualifiedNamedElement element; | ||
|
||
public VariablePresentation(PsiQualifiedNamedElement element, Icon icon) { | ||
this.element = element; | ||
this.icon = icon; | ||
} | ||
|
||
@Override | ||
public @Nullable Icon getIcon(boolean unused) { | ||
return icon; | ||
} | ||
|
||
@Override | ||
public @Nullable String getPresentableText() { | ||
return element.getQualifiedName(); | ||
} | ||
|
||
@Override | ||
public @Nullable String getLocationString() { | ||
final PsiFile containingFile = element.getContainingFile(); | ||
return containingFile == null ? "" : containingFile.getName(); | ||
} | ||
} |
Oops, something went wrong.