本文整理汇总了Java中com.intellij.lang.javascript.psi.JSLiteralExpression类的典型用法代码示例。如果您正苦于以下问题:Java JSLiteralExpression类的具体用法?Java JSLiteralExpression怎么用?Java JSLiteralExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSLiteralExpression类属于com.intellij.lang.javascript.psi包,在下文中一共展示了JSLiteralExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getImportedStyleSheetFile
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
/**
* Visits the containing file of the specified element to find a require to a style sheet file
*
* @param cssReferencingElement starting point for finding an imported style sheet file
* @return the PSI file for the first imported style sheet file
*/
public static StylesheetFile getImportedStyleSheetFile(PsiElement cssReferencingElement) {
final Ref<StylesheetFile> file = new Ref<>();
cssReferencingElement.getContainingFile().accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (file.get() != null) {
return;
}
if (element instanceof JSLiteralExpression) {
if (resolveStyleSheetFile(element, file)) return;
}
if(element instanceof ES6FromClause) {
if (resolveStyleSheetFile(element, file)) return;
}
super.visitElement(element);
}
});
return file.get();
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:26,代码来源:CssModulesUtil.java
示例2: getCssClassNamesImportOrRequireDeclaration
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
/**
* Gets the import/require declaration that a string literal belongs to, e.g 'normal' ->
* 'const styles = require("./foo.css")' or 'import styles from "./foo.css"' based on <code>styles['normal']</code>
*
* @param classNameLiteral a string literal that is potentially a CSS class name
* @return the JS variable that is a potential require of a style sheet file, or <code>null</code> if the PSI structure doesn't match
*/
public static PsiElement getCssClassNamesImportOrRequireDeclaration(JSLiteralExpression classNameLiteral) {
final JSIndexedPropertyAccessExpression expression = PsiTreeUtil.getParentOfType(classNameLiteral, JSIndexedPropertyAccessExpression.class);
if (expression != null) {
// string literal is part of "var['string literal']", e.g. "styles['normal']"
if (expression.getQualifier() != null) {
final PsiReference psiReference = expression.getQualifier().getReference();
if (psiReference != null) {
final PsiElement varReference = psiReference.resolve();
if (varReference instanceof JSVariable) {
return varReference;
}
if(varReference instanceof ES6ImportedBinding) {
return varReference.getParent();
}
}
}
}
return null;
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:27,代码来源:CssModulesUtil.java
示例3: resolveStyleSheetFile
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
/**
* Resolves the style sheet PSI file that backs a require("./stylesheet.css").
*
* @param cssFileNameLiteralParent parent element to a file name string literal that points to a style sheet file
* @return the matching style sheet PSI file, or <code>null</code> if the file can't be resolved
*/
public static StylesheetFile resolveStyleSheetFile(PsiElement cssFileNameLiteralParent) {
final Ref<StylesheetFile> stylesheetFileRef = new Ref<>();
cssFileNameLiteralParent.accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (stylesheetFileRef.get() != null) {
return;
}
if (element instanceof JSLiteralExpression) {
if (resolveStyleSheetFile(element, stylesheetFileRef)) return;
}
if(element instanceof ES6FromClause) {
if (resolveStyleSheetFile(element, stylesheetFileRef)) return;
}
super.visitElement(element);
}
});
return stylesheetFileRef.get();
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:26,代码来源:CssModulesUtil.java
示例4: attachSnippets
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
private void attachSnippets(@NotNull PsiElement sourceElement, @NotNull List<PsiElement> targets) {
PsiElement parent = sourceElement.getParent();
if(!(parent instanceof JSLiteralExpression)) {
return;
}
Object value = ((JSLiteralExpression) parent).getValue();
if(!(value instanceof String) || StringUtils.isBlank((String) value) || !((String) value).startsWith("{s")) {
return;
}
String name = ExtJsUtil.getAttributeTagValueFromSmartyString("s", "name", (String) value);
if(name == null) {
return;
}
String namespace = ExtJsUtil.getNamespaceFromStringLiteral((JSLiteralExpression) parent);
if(namespace == null) {
return;
}
targets.addAll(SnippetUtil.getSnippetNameTargets(parent.getProject(), namespace, name));
}
开发者ID:Haehnchen,项目名称:idea-php-shopware-plugin,代码行数:24,代码来源:ExtJsGoToDeclarationHandler.java
示例5: literalInProperty
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
private static PsiElementPattern.Capture<JSLiteralExpression> literalInProperty(final String propertyName) {
return PlatformPatterns.psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
if (element instanceof JSLiteralExpression) {
final JSLiteralExpression literal = (JSLiteralExpression)element;
if (literal.isQuotedLiteral()) {
final PsiElement parent = literal.getParent();
if (parent instanceof JSProperty && propertyName.equals(((JSProperty)parent).getName())) {
return EmberIndexUtil.hasEmberJS(literal.getProject());
}
}
}
return false;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}));
}
开发者ID:kristianmandrup,项目名称:emberjs-plugin,代码行数:23,代码来源:EmberJSReferencesContributor.java
示例6: parseValue
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@RequiredReadAction
@Override
@SuppressWarnings("unchecked")
public T parseValue(@NotNull Class type, @NotNull Type genericType, @NotNull PsiElement value) throws JomBadValueExpressionException
{
if(value instanceof JSLiteralExpression)
{
IElementType elementType = PsiUtilCore.getElementType(value.getFirstChild());
if(elementType == JSTokenTypes.NUMERIC_LITERAL)
{
try
{
return (T) myParseMethodValue.getValue().invoke(null, value.getText());
}
catch(Exception e)
{
throw new JomBadValueExpressionException(e);
}
}
}
throw new JomBadValueExpressionException();
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:24,代码来源:JomNullableNumberValue.java
示例7: parseValue
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@RequiredReadAction
@Override
public Boolean parseValue(@NotNull Class type, @NotNull Type genericType, @NotNull PsiElement value) throws JomBadValueExpressionException
{
if(value instanceof JSLiteralExpression)
{
IElementType elementType = PsiUtilCore.getElementType(value.getFirstChild());
if(elementType == JSTokenTypes.TRUE_KEYWORD)
{
return Boolean.TRUE;
}
else if(elementType == JSTokenTypes.FALSE_KEYWORD)
{
return Boolean.FALSE;
}
}
throw new JomBadValueExpressionException();
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:19,代码来源:JomBooleanValue.java
示例8: visitJSBinaryExpression
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
super.visitJSBinaryExpression(expression);
if (!(expression.getROperand() != null)) {
return;
}
if (!ComparisonUtils.isComparison(expression)) {
return;
}
final JSExpression lhs = expression.getLOperand();
final JSExpression rhs = expression.getROperand();
if (lhs instanceof JSLiteralExpression ||
!(rhs instanceof JSLiteralExpression)) {
return;
}
registerError(expression);
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:17,代码来源:ConstantOnRHSOfComparisonJSInspection.java
示例9: visitJSBinaryExpression
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
super.visitJSBinaryExpression(expression);
if (!(expression.getROperand() != null)) {
return;
}
if (!ComparisonUtils.isComparison(expression)) {
return;
}
final JSExpression lhs = expression.getLOperand();
final JSExpression rhs = expression.getROperand();
if (!(lhs instanceof JSLiteralExpression) ||
rhs instanceof JSLiteralExpression) {
return;
}
registerError(expression);
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:17,代码来源:ConstantOnLHSOfComparisonJSInspection.java
示例10: getLiteralNumber
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
public static BigInteger getLiteralNumber(JSLiteralExpression expression) {
String expressionText = expression.getText();
int radix = 10;
if (expressionText == null || expressionText.length() == 0) {
return new BigInteger(new byte[] { 0 });
}
if (expressionText.charAt(0) == '0') {
if (expressionText.length() > 2 && Character.toUpperCase(expressionText.charAt(1)) == 'X') {
expressionText = expressionText.substring(2);
radix = 16;
} else if (octalPattern.matcher(expressionText).matches()) {
radix = 8;
}
}
return new BigInteger(expressionText, radix);
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:20,代码来源:NumberUtil.java
示例11: processIntention
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override
public void processIntention(@NotNull PsiElement element)
throws IncorrectOperationException {
final JSBinaryExpression expression = (JSBinaryExpression) element;
final JSExpression lhs = expression.getLOperand();
final JSExpression rhs = expression.getROperand();
assert (lhs instanceof JSLiteralExpression && rhs instanceof JSLiteralExpression);
final JSLiteralExpression leftLiteral = (JSLiteralExpression) lhs;
final JSLiteralExpression rightLiteral = (JSLiteralExpression) rhs;
String lhsText = lhs.getText();
String rhsText = rhs.getText();
final String newExpression;
if (StringUtil.isSimpleQuoteStringLiteral(leftLiteral) &&
StringUtil.isDoubleQuoteStringLiteral(rightLiteral)) {
rhsText = JSDoubleToSingleQuotedStringIntention.changeQuotes(rhsText);
} else if (StringUtil.isDoubleQuoteStringLiteral(leftLiteral) &&
StringUtil.isSimpleQuoteStringLiteral(rightLiteral)) {
rhsText = JSSingleToDoubleQuotedStringIntention.changeQuotes(rhsText);
}
newExpression = lhsText.substring(0, lhsText.length() - 1) + rhsText.substring(1);
JSElementFactory.replaceExpression(expression, newExpression);
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:27,代码来源:JSJoinConcatenatedStringLiteralsIntention.java
示例12: isPowerOfTwo
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
public static boolean isPowerOfTwo(JSExpression expression) {
if (!(expression instanceof JSLiteralExpression)) {
return false;
}
final String value = expression.getText();
long intValue;
try {
intValue = Integer.decode(value).longValue();
} catch (NumberFormatException e) {
return false;
}
if (intValue <= 0) {
return false;
}
while ((intValue & 1) == 0) {
intValue >>= 1;
}
return (intValue == 1);
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:22,代码来源:ShiftUtils.java
示例13: isIntLiteral
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
public static boolean isIntLiteral(JSExpression expression) {
if (!(expression instanceof JSLiteralExpression)) {
return false;
}
if (!(expression instanceof JSLiteralExpression)) {
return false;
}
final String value = expression.getText();
try {
Integer.decode(value);
return true;
} catch (NumberFormatException e) {
return false;
}
}
开发者ID:consulo,项目名称:consulo-javascript,代码行数:18,代码来源:ShiftUtils.java
示例14: isAcceptable
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override
public boolean isAcceptable(Object element, @Nullable PsiElement context) {
if (element instanceof JSLiteralExpression && context != null && context.getContainingFile() instanceof JSFile) {
final ASTNode value = ((JSLiteralExpression) element).getNode().getFirstChildNode();
return value != null && value.getElementType() == JSTokenTypes.STRING_LITERAL;
}
return false;
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:9,代码来源:CssModulesUtil.java
示例15: registerReferenceProviders
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(CssModulesUtil.STRING_PATTERN, new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final PsiElement cssClassNamesImportOrRequire = CssModulesUtil.getCssClassNamesImportOrRequireDeclaration((JSLiteralExpression) element);
if (cssClassNamesImportOrRequire != null) {
final String literalClass = "." + StringUtils.stripStart(StringUtils.stripEnd(element.getText(), "\"'"), "\"'");
final Ref<StylesheetFile> referencedStyleSheet = new Ref<>();
final CssClass cssClass = CssModulesUtil.getCssClass(cssClassNamesImportOrRequire, literalClass, referencedStyleSheet);
if (cssClass != null) {
return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) {
@Nullable
@Override
public PsiElement resolve() {
return cssClass;
}
@NotNull
@Override
public Object[] getVariants() {
return new Object[0];
}
}};
} else {
if (referencedStyleSheet.get() != null) {
final TextRange rangeInElement = TextRange.from(1, element.getTextLength() - 2); // minus string quotes
return new PsiReference[]{new CssModulesUnknownClassPsiReference(element, rangeInElement, referencedStyleSheet.get())};
}
}
}
return new PsiReference[0];
}
});
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:38,代码来源:CssModulesIndexedStylesVarPsiReferenceContributor.java
示例16: shouldSkipAutopopup
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@NotNull
@Override
public ThreeState shouldSkipAutopopup(@NotNull PsiElement contextElement, @NotNull PsiFile psiFile, int offset) {
if (contextElement.getParent() instanceof JSLiteralExpression) {
final PsiElement cssClassNamesImportOrRequire = CssModulesUtil.getCssClassNamesImportOrRequireDeclaration((JSLiteralExpression) contextElement.getParent());
if (cssClassNamesImportOrRequire != null) {
final StylesheetFile stylesheetFile = CssModulesUtil.resolveStyleSheetFile(cssClassNamesImportOrRequire);
if (stylesheetFile != null) {
return ThreeState.NO;
}
}
}
return ThreeState.UNSURE;
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:15,代码来源:CssModulesClassNameCompletionConfidence.java
示例17: annotate
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
PsiElement elementToAnnotate = null;
if (psiElement instanceof XmlAttributeValue) {
if (CssModulesUtil.STYLE_NAME_FILTER.isAcceptable(psiElement, psiElement)) {
elementToAnnotate = psiElement;
}
} else if (psiElement instanceof JSLiteralExpression) {
elementToAnnotate = psiElement;
}
if (elementToAnnotate != null) {
for (PsiReference psiReference : psiElement.getReferences()) {
if (psiReference instanceof CssModulesUnknownClassPsiReference) {
final TextRange rangeInElement = psiReference.getRangeInElement();
if (rangeInElement.isEmpty()) {
continue;
}
int start = psiElement.getTextRange().getStartOffset() + rangeInElement.getStartOffset();
int length = rangeInElement.getLength();
final TextRange textRange = TextRange.from(start, length);
if (!textRange.isEmpty()) {
final String message = "Unknown class name \"" + rangeInElement.substring(psiElement.getText()) + "\"";
annotationHolder.createErrorAnnotation(textRange, message);
}
}
}
}
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:29,代码来源:CssModulesClassAnnotator.java
示例18: getIntentionElement
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
private PsiElement getIntentionElement(@NotNull PsiElement element) {
PsiElement intentionElement;
if (element instanceof XmlToken) {
intentionElement = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class);
} else {
intentionElement = PsiTreeUtil.getParentOfType(element, JSLiteralExpression.class);
if (intentionElement == null) {
intentionElement = PsiTreeUtil.getPrevSiblingOfType(element, JSLiteralExpression.class);
}
}
return intentionElement;
}
开发者ID:jimkyndemeyer,项目名称:react-css-modules-intellij-plugin,代码行数:13,代码来源:CssModulesCreateClassIntention.java
示例19: getSnippetPattern
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
/**
* String must start with "{s"
*/
private PsiElementPattern.Capture<PsiElement> getSnippetPattern() {
return PlatformPatterns.psiElement()
.withParent(PlatformPatterns.psiElement(JSLiteralExpression.class)
.with(new PatternCondition<JSLiteralExpression>("Snippet Start") {
@Override
public boolean accepts(@NotNull JSLiteralExpression jsLiteralExpression, ProcessingContext processingContext) {
Object value = jsLiteralExpression.getValue();
return value instanceof String && (((String) value).startsWith("{s"));
}
}));
}
开发者ID:Haehnchen,项目名称:idea-php-shopware-plugin,代码行数:15,代码来源:ShopwareJavaScriptCompletion.java
示例20: getNamespaceFromStringLiteral
import com.intellij.lang.javascript.psi.JSLiteralExpression; //导入依赖的package包/类
/**
* {header: '{s name=swag-last-registrations/date}{/s}'}
*/
@Nullable
public static String getNamespaceFromStringLiteral(@NotNull JSLiteralExpression element) {
Object contents = element.getValue();
if(!(contents instanceof String) || StringUtils.isBlank((String) contents)) {
return null;
}
String namespace = getAttributeTagValueFromSmartyString("s", "namespace", (String) contents);
if(namespace != null) {
return namespace;
}
return getSnippetNamespaceFromFile(element.getContainingFile());
}
开发者ID:Haehnchen,项目名称:idea-php-shopware-plugin,代码行数:18,代码来源:ExtJsUtil.java
注:本文中的com.intellij.lang.javascript.psi.JSLiteralExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论