use of com.intellij.lang.javascript.psi.impl.JSLiteralExpressionImpl in project intellij-plugins by JetBrains.
the class FlexPropertyReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
PsiElement parent = element.getParent();
JSReferenceExpression invokedMethod = JSUtils.getMethodNameIfInsideCall(parent);
List<PsiReference> result = new ArrayList<>();
if (invokedMethod != null) {
String invokedMethodName;
boolean justResourceBundleRef = false;
PsiElement qualifier;
if ((ourMethodsWithPropertyReferences.contains(invokedMethodName = (invokedMethod.getReferencedName())) || (justResourceBundleRef = "getResourceBundle".equals(invokedMethodName))) && ((qualifier = invokedMethod.getQualifier()) instanceof JSReferenceExpression || (qualifier instanceof JSCallExpression && ((JSCallExpression) qualifier).getMethodExpression() instanceof JSReferenceExpression))) {
final JSExpression[] args = ((JSArgumentList) parent).getArguments();
boolean propertyRef = false;
boolean bundleRef = false;
if (justResourceBundleRef) {
bundleRef = args.length > 1 && args[1] == element;
} else {
propertyRef = args.length > 1 && args[1] == element;
bundleRef = args.length > 0 && args[0] == element;
if (bundleRef && args.length == 1) {
// ResourceBundle.getString deprecated, without bundle name
bundleRef = false;
propertyRef = true;
}
}
boolean isSoft = true;
if (propertyRef || bundleRef) {
PsiElement resolved = invokedMethod.resolve();
if (resolved instanceof JSFunction) {
PsiElement parentClass = JSResolveUtil.findParent(resolved);
if (parentClass instanceof JSClass) {
String name = ((JSClass) parentClass).getName();
isSoft = name == null || (name.indexOf("ResourceManager") == -1 && name.indexOf("ResourceBundle") == -1);
}
}
}
if (propertyRef) {
FlexPropertiesSupport.PropertyReferenceInfoProvider<JSLiteralExpressionImpl> provider = isSoft ? ourSoftPropertyInfoProvider : ourPropertyInfoProvider;
if (args.length > 1 && !isSoft) {
JSExpression bundleExpression = args[0];
if (bundleExpression instanceof JSReferenceExpression) {
PsiElement resolved = ((JSReferenceExpression) bundleExpression).resolve();
if (resolved instanceof JSVariable) {
bundleExpression = ((JSVariable) resolved).getInitializer();
}
}
if (bundleExpression instanceof JSLiteralExpression) {
final Object expressionValue = ((JSLiteralExpression) bundleExpression).getValue();
if (expressionValue instanceof String) {
provider = new FlexPropertiesSupport.PropertyReferenceInfoProvider<JSLiteralExpressionImpl>() {
public TextRange getReferenceRange(JSLiteralExpressionImpl element) {
return getValueRange(element);
}
public String getBundleName(JSLiteralExpressionImpl element) {
return (String) expressionValue;
}
public boolean isSoft(JSLiteralExpressionImpl element) {
return false;
}
};
}
}
}
Collections.addAll(result, FlexPropertiesSupport.getPropertyReferences((JSLiteralExpressionImpl) element, provider));
} else if (bundleRef) {
PsiReference[] reference = FlexPropertiesSupport.getResourceBundleReference((JSLiteralExpressionImpl) element, isSoft ? ourSoftBundleInfoProvider : ourBundleInfoProvider);
Collections.addAll(result, reference);
}
}
}
return result.toArray(new PsiReference[result.size()]);
}
use of com.intellij.lang.javascript.psi.impl.JSLiteralExpressionImpl in project intellij-plugins by JetBrains.
the class Angular2Injector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
final Project project = context.getProject();
if (!AngularIndexUtil.hasAngularJS2(project))
return;
final PsiElement parent = context.getParent();
if (context instanceof JSLiteralExpressionImpl && ((JSLiteralExpressionImpl) context).isQuotedLiteral()) {
if (injectIntoDirectiveProperty(registrar, context, parent, "template", Angular2HTMLLanguage.INSTANCE))
return;
if (injectIntoEmbeddedLiteral(registrar, context, parent))
return;
if (parent instanceof JSArrayLiteralExpression) {
final JSProperty property = ObjectUtils.tryCast(parent.getParent(), JSProperty.class);
if (injectIntoDirectiveProperty(registrar, context, property, "styles", CSSLanguage.INSTANCE))
return;
}
if (parent instanceof JSProperty && parent.getParent() instanceof JSObjectLiteralExpression) {
injectIntoDirectiveProperty(registrar, context, parent.getParent().getParent(), "host", AngularJSLanguage.INSTANCE);
}
return;
}
if (context instanceof XmlAttributeValueImpl && parent instanceof XmlAttribute) {
final int length = context.getTextLength();
final String name = ((XmlAttribute) parent).getName();
if (isInjectableAttribute(project, length, name)) {
registrar.startInjecting(AngularJSLanguage.INSTANCE).addPlace(null, null, (PsiLanguageInjectionHost) context, ElementManipulators.getValueTextRange(context)).doneInjecting();
}
}
}
Aggregations