@Override public boolean areElementsEquivalent(PsiElement element1, PsiElement element2) { ProgressIndicatorProvider .checkCanceled(); // We hope this method is being called often enough to cancel daemon // processes smoothly if (element1 == element2) return true; if (element1 == null || element2 == null) { return false; } return element1.equals(element2) || element1.isEquivalentTo(element2) || element2.isEquivalentTo(element1); }
private static void fixPossibleNameCollisionsForFieldRenaming( PsiField field, String newName, PsiElement replacedOccurence) throws IncorrectOperationException { if (!(replacedOccurence instanceof PsiReferenceExpression)) return; PsiElement elem = ((PsiReferenceExpression) replacedOccurence).resolve(); if (elem == null || elem == field || elem.isEquivalentTo(field)) { // If reference is unresolved, then field is not hidden by anyone... return; } if (elem instanceof PsiLocalVariable || elem instanceof PsiParameter || (elem instanceof PsiField && elem != replacedOccurence)) { qualifyMember(field, replacedOccurence, newName); } }
/** * Computes indentation of PsiClass, PsiMethod and PsiField elements after formatting * * @param element PsiClass or PsiMethod or PsiField * @return indentation size */ private int getIndentSpecial(@NotNull PsiElement element) { assert (element instanceof PsiClass || element instanceof PsiField || element instanceof PsiMethod); int indentSize = mySettings.getIndentSize(JavaFileType.INSTANCE); boolean doNotIndentTopLevelClassMembers = mySettings.getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS; int indent = 0; PsiClass top = PsiUtil.getTopLevelClass(element); while (top != null && !element.isEquivalentTo(top)) { if (doNotIndentTopLevelClassMembers && element.getParent().isEquivalentTo(top)) { break; } element = element.getParent(); indent += indentSize; } return indent; }
public void addCompletions( @NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { PsiElement stringLiteralExpression = parameters.getPosition().getParent(); Project project = stringLiteralExpression.getProject(); if (!SilexProjectComponent.isEnabled(project)) { return; } if (!(stringLiteralExpression instanceof StringLiteralExpression)) { return; } PsiElement arrayKeyElement = stringLiteralExpression.getParent(); PsiElement element = arrayKeyElement.getParent(); if (element instanceof ArrayHashElement) { if (!arrayKeyElement.isEquivalentTo(element.getFirstChild())) { return; } element = element.getParent(); } if (!(element instanceof ArrayCreationExpression)) { return; } PsiElement parameterList = element.getParent(); if (!(parameterList instanceof ParameterList)) { return; } PsiElement[] params = ((ParameterList) parameterList).getParameters(); if (!(params.length > 1 && params[1].isEquivalentTo(element))) { return; } PsiElement methodReference = parameterList.getParent(); if (!(methodReference instanceof MethodReference)) { return; } String methodReferenceName = ((MethodReference) methodReference).getName(); if ((methodReferenceName == null) || !(methodReferenceName.equals("register"))) { return; } Container container = Utils.findContainerForMethodReference((MethodReference) methodReference); if (container == null) { return; } for (Parameter parameter : container.getParameters().values()) { resultSet.addElement(new ParameterLookupElement(parameter)); } resultSet.stopHere(); }