use of com.intellij.psi.PsiReferenceExpression in project oxy-template-support-plugin by mutant-industries.
the class LiteralJsMacroReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiLiteralExpression.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) element;
PsiMethodCallExpression callExpression;
PsiNewExpression newMacroCallExpression;
if (!(literalExpression.getValue() instanceof String)) {
return PsiReference.EMPTY_ARRAY;
}
if ((newMacroCallExpression = PsiTreeUtil.getParentOfType(literalExpression, PsiNewExpressionImpl.class)) != null && newMacroCallExpression.getClassReference() != null) {
if (MacroCall.class.getName().equals(newMacroCallExpression.getClassReference().getQualifiedName())) {
return new MacroReferenceSet(literalExpression).getAllReferences();
}
} else if ((callExpression = PsiTreeUtil.getParentOfType(literalExpression, PsiMethodCallExpression.class)) != null) {
PsiExpression[] parameters = callExpression.getArgumentList().getExpressions();
PsiReferenceExpression expression = callExpression.getMethodExpression();
String callText = expression.getText();
if (// TODO type check...
callText.contains("ageUpdater.update")) {
if (parameters.length > 0 && literalExpression.isEquivalentTo(parameters[0])) {
// TODO template path reference
} else if (parameters.length > 1 && literalExpression.isEquivalentTo(parameters[1])) {
return new MacroReferenceSet(literalExpression).getAllReferences();
}
}
}
return PsiReference.EMPTY_ARRAY;
}
});
}
use of com.intellij.psi.PsiReferenceExpression in project Just-Another-Android-App by athkalia.
the class AndroidLogDetector method visitMethod.
@Override
public void visitMethod(@Nonnull JavaContext javaContext, JavaElementVisitor visitor, @Nonnull PsiMethodCallExpression call, PsiMethod method) {
PsiReferenceExpression methodExpression = call.getMethodExpression();
String fullyQualifiedMethodName = methodExpression.getQualifiedName();
if (fullyQualifiedMethodName.startsWith("android.util.Log.")) {
javaContext.report(ISSUE, javaContext.getLocation(methodExpression), ISSUE.getBriefDescription(TextFormat.TEXT));
}
}
use of com.intellij.psi.PsiReferenceExpression in project timber by JakeWharton.
the class WrongTimberUsageDetector method visitMethod.
@Override
public void visitMethod(JavaContext context, JavaElementVisitor visitor, PsiMethodCallExpression call, PsiMethod method) {
PsiReferenceExpression methodExpression = call.getMethodExpression();
String fullyQualifiedMethodName = methodExpression.getQualifiedName();
if ("java.lang.String.format".equals(fullyQualifiedMethodName)) {
checkNestedStringFormat(context, call);
return;
}
if (fullyQualifiedMethodName.startsWith("timber.log.Timber.tag")) {
checkTagLength(context, call);
return;
}
if (fullyQualifiedMethodName.startsWith("android.util.Log.")) {
context.report(ISSUE_LOG, methodExpression, context.getLocation(methodExpression), "Using 'Log' instead of 'Timber'");
return;
}
// Handles Timber.X(..) and Timber.tag(..).X(..) where X in (v|d|i|w|e|wtf).
if (fullyQualifiedMethodName.startsWith("timber.log.Timber.")) {
checkMethodArguments(context, call);
checkFormatArguments(context, call);
checkExceptionLogging(context, call);
return;
}
}
use of com.intellij.psi.PsiReferenceExpression in project android by JetBrains.
the class AndroidColorAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
String tagName = tag.getName();
if ((ResourceType.COLOR.getName().equals(tagName) || ResourceType.DRAWABLE.getName().equals(tagName) || ResourceType.MIPMAP.getName().equals(tagName))) {
DomElement domElement = DomManager.getDomManager(element.getProject()).getDomElement(tag);
if (domElement instanceof ResourceElement || ApplicationManager.getApplication().isUnitTestMode()) {
String value = tag.getValue().getText().trim();
annotateXml(element, holder, value);
}
} else if (TAG_ITEM.equals(tagName)) {
XmlTagValue value = tag.getValue();
String text = value.getText();
annotateXml(element, holder, text);
}
} else if (element instanceof XmlAttributeValue) {
XmlAttributeValue v = (XmlAttributeValue) element;
String value = v.getValue();
if (value == null || value.isEmpty()) {
return;
}
annotateXml(element, holder, value);
} else if (element instanceof PsiReferenceExpression) {
ResourceReferenceType referenceType = AndroidPsiUtils.getResourceReferenceType(element);
if (referenceType != ResourceReferenceType.NONE) {
// (isResourceReference will return true for both "R.drawable.foo" and the foo literal leaf in the
// same expression, which would result in both elements getting annotated and the icon showing up
// in the gutter twice. Instead we only count the outer one.
ResourceType type = AndroidPsiUtils.getResourceType(element);
if (type == ResourceType.COLOR || type == ResourceType.DRAWABLE || type == ResourceType.MIPMAP) {
String name = AndroidPsiUtils.getResourceName(element);
annotateResourceReference(type, holder, element, name, referenceType == ResourceReferenceType.FRAMEWORK);
}
}
}
}
use of com.intellij.psi.PsiReferenceExpression in project android by JetBrains.
the class AndroidJavaCompletionContributor method fillCompletionVariants.
@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull final CompletionResultSet resultSet) {
super.fillCompletionVariants(parameters, resultSet);
final PsiElement position = parameters.getPosition();
final AndroidFacet facet = AndroidFacet.getInstance(position);
if (facet == null) {
return;
}
if (AndroidMavenUtil.isMavenizedModule(facet.getModule())) {
resultSet.runRemainingContributors(parameters, new Consumer<CompletionResult>() {
@Override
public void consume(CompletionResult result) {
final Object obj = result.getLookupElement().getObject();
if (obj instanceof PsiClass) {
final String qName = ((PsiClass) obj).getQualifiedName();
if (qName != null && !isAllowedInAndroid(qName)) {
return;
}
}
resultSet.passResult(result);
}
});
}
// Filter out private resources when completing R.type.name expressions, if any
if (position.getParent() instanceof PsiReferenceExpression) {
PsiReferenceExpression ref = (PsiReferenceExpression) position.getParent();
if (ref.getQualifierExpression() != null && ref.getQualifierExpression() instanceof PsiReferenceExpression) {
PsiReferenceExpression ref2 = (PsiReferenceExpression) ref.getQualifierExpression();
if (ref2.getQualifierExpression() instanceof PsiReferenceExpression) {
PsiReferenceExpression ref3 = (PsiReferenceExpression) ref2.getQualifierExpression();
if (ref3.getQualifierExpression() == null && R_CLASS.equals(ref3.getReferenceName())) {
filterPrivateResources(parameters, resultSet, facet);
}
}
}
}
}
Aggregations