use of com.intellij.lang.javascript.psi.JSExpression in project intellij-plugins by JetBrains.
the class AngularJSDirectiveRenameProcessor method renameElement.
@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
final boolean isAngular2 = DirectiveUtil.isAngular2Directive(element);
final PsiNamedElement directive = (PsiNamedElement) element;
final String attributeName = isAngular2 ? newName : DirectiveUtil.getAttributeName(newName);
for (UsageInfo usage : usages) {
RenameUtil.rename(usage, attributeName);
}
if (isAngular2) {
final JSProperty selector = AngularJS2IndexingHandler.getSelector(element.getParent());
final JSExpression value = selector != null ? selector.getValue() : null;
if (value != null) {
if (value.getText().contains("["))
newName = "[" + newName + "]";
ElementManipulators.getManipulator(value).handleContentChange(value, newName);
}
} else {
directive.setName(DirectiveUtil.attributeToDirective(element, newName));
}
if (listener != null) {
listener.elementRenamed(element);
}
}
use of com.intellij.lang.javascript.psi.JSExpression in project intellij-plugins by JetBrains.
the class JstdGenerateNewTestAction method buildGenerator.
@Nullable
private static Runnable buildGenerator(@NotNull JstdTestFileStructure fileStructure, @NotNull GenerateActionContext context) {
int caretOffset = context.getDocumentCaretOffset();
JstdTestCaseStructure jstdTestCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
if (jstdTestCaseStructure != null) {
JSObjectLiteralExpression testsObjectLiteral = jstdTestCaseStructure.getTestsObjectsLiteral();
if (testsObjectLiteral != null) {
return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
} else {
if (jstdTestCaseStructure.getTestCount() == 0) {
JSCallExpression callExpression = jstdTestCaseStructure.getEnclosingCallExpression();
JSArgumentList argumentList = callExpression.getArgumentList();
JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
if (arguments.length == 1 && arguments[0] != null) {
return new TestGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
}
}
}
} else {
for (JstdTestCaseStructure testCaseStructure : fileStructure.getTestCaseStructures()) {
JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
}
}
}
return null;
}
use of com.intellij.lang.javascript.psi.JSExpression in project intellij-plugins by JetBrains.
the class JstdTestFileStructure method postProcess.
void postProcess() {
myNameByPsiElementMap = Collections.emptyMap();
myPrototypeBasedTestElements = Collections.emptyMap();
if (myTestCaseStructures.isEmpty()) {
return;
}
int totalCount = 0;
int prototypeBasedTestCount = 0;
for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
totalCount += testCaseStructure.getTestCount() + 1;
for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
if (testStructure.getWholeLeftDefExpr() != null) {
prototypeBasedTestCount++;
}
}
}
myNameByPsiElementMap = new IdentityHashMap<>(totalCount);
if (prototypeBasedTestCount > 0) {
myPrototypeBasedTestElements = new IdentityHashMap<>(prototypeBasedTestCount);
}
for (JstdTestCaseStructure testCaseStructure : myTestCaseStructures) {
JSExpression testCaseMethodExpr = testCaseStructure.getEnclosingCallExpression().getMethodExpression();
if (testCaseMethodExpr != null) {
myNameByPsiElementMap.put(testCaseMethodExpr, testCaseStructure.getName());
}
for (JstdTestStructure testStructure : testCaseStructure.getTestStructures()) {
PsiElement anchor = testStructure.getTestMethodNameDeclaration();
myNameByPsiElementMap.put(anchor, testStructure.getName());
JSDefinitionExpression wholeLeftDefExpr = testStructure.getWholeLeftDefExpr();
if (wholeLeftDefExpr != null) {
myPrototypeBasedTestElements.put(wholeLeftDefExpr, null);
}
}
}
}
Aggregations