@Override @Nullable public LeafElement createLeaf(@NotNull final IElementType type, @NotNull CharSequence text) { if (type == PropertiesTokenTypes.KEY_CHARACTERS) { return new PropertyKeyImpl(type, text); } if (type == PropertiesTokenTypes.VALUE_CHARACTERS) { return new PropertyValueImpl(type, text); } if (type == PropertiesTokenTypes.END_OF_LINE_COMMENT) { return new PsiCommentImpl(type, text); } return new LeafPsiElement(type, text); }
@Nullable public Character getKeyValueDelimiter() { final PsiElement delimiter = findChildByType(PropertiesTokenTypes.KEY_VALUE_SEPARATOR); if (delimiter == null) { return null; } String separatorText = delimiter.getText(); if (separatorText.isEmpty()) { return null; } separatorText = separatorText.trim(); if (separatorText.isEmpty()) { separatorText = " "; } LOG.assertTrue(separatorText.length() == 1, "\"" + separatorText + "\""); return separatorText.charAt(0); }
public void advance() { final IElementType tokenType = getDelegate().getTokenType(); if (tokenType == PropertiesTokenTypes.KEY_CHARACTERS) { scanWordsInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_FOREIGN_LANGUAGES | UsageSearchContext.IN_PLAIN_TEXT, false, false); } else if (PropertiesTokenTypes.COMMENTS.contains(tokenType)) { scanWordsInToken(UsageSearchContext.IN_COMMENTS | UsageSearchContext.IN_PLAIN_TEXT, false, false); advanceTodoItemCountsInToken(); } else { scanWordsInToken(UsageSearchContext.IN_CODE | UsageSearchContext.IN_FOREIGN_LANGUAGES | UsageSearchContext.IN_PLAIN_TEXT, false, false); } getDelegate().advance(); }
private static void handleEnterInPropertiesFile(final Editor editor, final Document document, final PsiElement psiAtOffset, int caretOffset) { String text = document.getText(); String line = text.substring(0, caretOffset); int i = line.lastIndexOf('\n'); if (i > 0) { line = line.substring(i); } final String toInsert; if (PropertiesUtil.isUnescapedBackSlashAtTheEnd(line)) { toInsert = "\n "; } else { final IElementType elementType = psiAtOffset == null ? null : psiAtOffset.getNode().getElementType(); if (elementType == PropertiesTokenTypes.VALUE_CHARACTERS) { toInsert = "\\\n "; } else if (elementType == PropertiesTokenTypes.END_OF_LINE_COMMENT && "#!".indexOf(document.getText().charAt(caretOffset)) == -1) { toInsert = "\n#"; } else { toInsert = "\n"; } } document.insertString(caretOffset, toInsert); caretOffset+=toInsert.length(); editor.getCaretModel().moveToOffset(caretOffset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); }
public void replaceKeyValueDelimiterWithDefault() { PropertyImpl property = (PropertyImpl)PropertiesElementFactory.createProperty(getProject(), "yyy", "xxx"); final ASTNode oldDelimiter = getNode().findChildByType(PropertiesTokenTypes.KEY_VALUE_SEPARATOR); LOG.assertTrue(oldDelimiter != null); final ASTNode newDelimiter = property.getNode().findChildByType(PropertiesTokenTypes.KEY_VALUE_SEPARATOR); LOG.assertTrue(newDelimiter != null); getNode().replaceChild(oldDelimiter, newDelimiter); }
public PropertiesHighlightingLexer() { super(new PropertiesLexer()); registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, PropertiesTokenTypes.VALUE_CHARACTERS, true, "#!=:"), new IElementType[]{PropertiesTokenTypes.VALUE_CHARACTERS}, IElementType.EMPTY_ARRAY); registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, PropertiesTokenTypes.KEY_CHARACTERS, true, "#!=: "), new IElementType[]{PropertiesTokenTypes.KEY_CHARACTERS}, IElementType.EMPTY_ARRAY); }
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PropertiesTokenTypes.VALUE_CHARACTERS), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (!DGMUtil.isInDGMFile(element)) return PsiReference.EMPTY_ARRAY; IProperty parent = (IProperty)element.getParent(); if (!"extensionClasses".equals(parent.getName())) { return PsiReference.EMPTY_ARRAY; } ArrayList<PsiReference> result = new ArrayList<PsiReference>(); String text = element.getText(); int i = 0; while ((i = skipWhiteSpace(i, text)) < text.length()) { int end = findWhiteSpaceOrComma(i, text); if (end <= text.length()) { JavaClassReferenceSet set = new JavaClassReferenceSet(text.substring(i, end), element, i, true, myProvider); ContainerUtil.addAll(result, set.getAllReferences()); } i = end; i = skipWhiteSpace(i, text); if (i == text.length()) break; if (text.charAt(i) == ',') i++; i = skipWhiteSpace(i, text); } return result.toArray(new PsiReference[result.size()]); } }); }
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { CndReferenceProvider cndReferenceProvider = new CndReferenceProvider(); registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), cndReferenceProvider); //Java registrar.registerReferenceProvider(PlatformPatterns.psiElement(CndTypes.SUPER_TYPE), cndReferenceProvider); //Cnd super types registrar.registerReferenceProvider(PlatformPatterns.psiElement(CndTypes.EXTENSION), cndReferenceProvider); //Cnd extends types registrar.registerReferenceProvider(PlatformPatterns.psiElement(CndTypes.SUB_NODE_TYPE), cndReferenceProvider); //Cnd subnode types registrar.registerReferenceProvider(PlatformPatterns.psiElement(CndTypes.SUB_NODE_DEFAULT_TYPE), cndReferenceProvider); //Cnd subnode default type registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlElementType.XML_ATTRIBUTE_VALUE), cndReferenceProvider); //XML registrar.registerReferenceProvider(PlatformPatterns.psiElement(PropertiesTokenTypes.KEY_CHARACTERS), cndReferenceProvider); //Properties }
@Nullable public LeafElement createLeaf(final IElementType type, CharSequence text) { if (type == PropertiesTokenTypes.VALUE_CHARACTERS) { return new PropertyValueImpl(type, text); } if (type == PropertiesTokenTypes.END_OF_LINE_COMMENT) { return new PsiCommentImpl(type, text); } return new LeafPsiElement(type, text); }
@Override public void registerReferenceProviders(PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(PlatformPatterns.psiElement(PropertiesTokenTypes.VALUE_CHARACTERS), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { if (!DGMUtil.isInDGMFile(element)) return PsiReference.EMPTY_ARRAY; IProperty parent = (IProperty)element.getParent(); if (!"extensionClasses".equals(parent.getName())) { return PsiReference.EMPTY_ARRAY; } ArrayList<PsiReference> result = new ArrayList<PsiReference>(); String text = element.getText(); int i = 0; while ((i = skipWhiteSpace(i, text)) < text.length()) { int end = findWhiteSpaceOrComma(i, text); if (end <= text.length()) { JavaClassReferenceSet set = new JavaClassReferenceSet(text.substring(i, end), element, i, true, myProvider); ContainerUtil.addAll(result, set.getAllReferences()); } i = end; i = skipWhiteSpace(i, text); if (i == text.length()) break; if (text.charAt(i) == ',') i++; i = skipWhiteSpace(i, text); } return result.toArray(new PsiReference[result.size()]); } }); }
@Nullable public ASTNode getKeyNode() { return getNode().findChildByType(PropertiesTokenTypes.KEY_CHARACTERS); }
@Nullable public ASTNode getValueNode() { return getNode().findChildByType(PropertiesTokenTypes.VALUE_CHARACTERS); }
public PropertiesValueHighlightingLexer() { super(new DummyLexer(PropertiesTokenTypes.VALUE_CHARACTERS)); registerSelfStoppingLayer(new StringLiteralLexer(StringLiteralLexer.NO_QUOTE_CHAR, PropertiesTokenTypes.VALUE_CHARACTERS, true, "#!=:"), new IElementType[]{PropertiesTokenTypes.VALUE_CHARACTERS}, IElementType.EMPTY_ARRAY); }