mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
some PSI for template languages in python-psi-api; common superinterface for string literals in Python code and templates
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.templateLanguages.psi;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A function call in a template file.
|
||||
*
|
||||
* @author yole
|
||||
*/
|
||||
public interface TemplateFunctionCall extends PsiElement {
|
||||
@Nullable
|
||||
PsiElement getCallee();
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.templateLanguages.psi;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.psi.StringLiteralExpression;
|
||||
|
||||
/**
|
||||
* A string literal in a template file.
|
||||
*
|
||||
* @author yole
|
||||
*/
|
||||
public interface TemplateStringLiteral extends PsiElement, StringLiteralExpression {
|
||||
TextRange getStringValueTextRange();
|
||||
}
|
||||
@@ -6,9 +6,7 @@ import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PyStringLiteralExpression extends PyLiteralExpression, PsiLanguageInjectionHost {
|
||||
String getStringValue();
|
||||
|
||||
public interface PyStringLiteralExpression extends PyLiteralExpression, StringLiteralExpression, PsiLanguageInjectionHost {
|
||||
List<TextRange> getStringValueTextRanges();
|
||||
|
||||
List<ASTNode> getStringNodes();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
/**
|
||||
* A generic string literal interface (used both in Python code and template files).
|
||||
*
|
||||
* @author yole
|
||||
*/
|
||||
public interface StringLiteralExpression extends PsiElement {
|
||||
String getStringValue();
|
||||
TextRange getStringValueTextRange();
|
||||
}
|
||||
@@ -167,6 +167,18 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRange getStringValueTextRange() {
|
||||
List<TextRange> allRanges = getStringValueTextRanges();
|
||||
if (allRanges.size() == 1) {
|
||||
return allRanges.get(0);
|
||||
}
|
||||
if (allRanges.size() > 1) {
|
||||
return new TextRange(allRanges.get(0).getStartOffset(), allRanges.get(allRanges.size()-1).getEndOffset());
|
||||
}
|
||||
return new TextRange(0, getTextLength());
|
||||
}
|
||||
|
||||
private static boolean iterateCharacterRanges(TextRangeConsumer consumer, String undecoded, int off, boolean raw, boolean unicode) {
|
||||
if (raw) {
|
||||
return iterateRawCharacterRanges(consumer, undecoded, off, unicode);
|
||||
|
||||
Reference in New Issue
Block a user