use of com.intellij.lang.javascript.psi.JSProperty in project intellij-plugins by JetBrains.
the class JstdStructureTest method matchTest.
private static void matchTest(@NotNull MarkedTestStructure markedTestStructure, @NotNull JstdTestStructure testStructure) {
Assert.assertEquals("Build test name is not equal to the marked one", markedTestStructure.getName(), testStructure.getName());
String testName = testStructure.getName();
JSProperty markedJsProperty = markedTestStructure.getPropertyPsiElement();
if (markedJsProperty != null) {
matchPsiElement(testName, "property", markedJsProperty, testStructure.getJsProperty());
} else {
matchPsiElement(testName, "declaration", markedTestStructure.getDeclarationPsiElement(), testStructure.getTestMethodNameDeclaration());
matchPsiElement(testName, "body", markedTestStructure.getBodyPsiElement(), testStructure.getTestMethodBody());
}
}
use of com.intellij.lang.javascript.psi.JSProperty 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.JSProperty in project intellij-plugins by JetBrains.
the class KarmaBasePathFinder method buildBasePath.
@Nullable
private static String buildBasePath(@NotNull JSFile jsFile) {
final Ref<String> basePathRef = Ref.create(null);
JSElementVisitor visitor = new JSElementVisitor() {
@Override
public void visitJSProperty(JSProperty property) {
String name = JsPsiUtils.getPropertyName(property);
if (BASE_PATH_VAR_NAME.equals(name)) {
JSLiteralExpression value = ObjectUtils.tryCast(property.getValue(), JSLiteralExpression.class);
if (value != null && value.isQuotedLiteral()) {
basePathRef.set(StringUtil.unquoteString(value.getText()));
}
}
}
@Override
public void visitElement(PsiElement element) {
ProgressIndicatorProvider.checkCanceled();
if (basePathRef.isNull()) {
element.acceptChildren(this);
}
}
};
visitor.visitJSFile(jsFile);
return basePathRef.get();
}
use of com.intellij.lang.javascript.psi.JSProperty in project oxy-template-support-plugin by mutant-industries.
the class InnerJsTypeEvaluator method addTypeFromAmdModuleReference.
@Override
protected boolean addTypeFromAmdModuleReference(@NotNull JSParameter parameter) {
JSProperty macro;
JSType type;
// macro first parameter
if ((macro = checkMacroFirstParameter(parameter)) != null) {
addType(getMacroFirstParameterType(macro));
return true;
} else // function parameter
if ((type = parameter.getJSType()) != null) {
type.accept(new SimplifiedClassNameResolver(myContext.targetFile));
}
return super.addTypeFromAmdModuleReference(parameter);
}
use of com.intellij.lang.javascript.psi.JSProperty in project oxy-template-support-plugin by mutant-industries.
the class OxyTemplateHelper method getUsedJsMacros.
@NotNull
public static Map<PsiElement, JSElement> getUsedJsMacros(@NotNull PsiFile psiFile) {
final Map<PsiElement, JSElement> usedMacros = new HashMap<>();
new MacroNameVisitor() {
@Override
public void visitMacroName(@NotNull MacroName macroName) {
PsiElement reference;
if (macroName.getReference() != null && (reference = macroName.getReference().resolve()) != null && OxyTemplateIndexUtil.getJsMacroNameReferences(macroName.getName(), macroName.getProject()).size() > 0) {
usedMacros.put(macroName, (JSElement) reference);
}
}
}.visitFile(psiFile);
new JSRecursiveWalkingElementVisitor() {
@Override
public void visitJSCallExpression(@NotNull JSCallExpression node) {
if (node.getFirstChild() instanceof JSReferenceExpression) {
JSReferenceExpression referenceExpression = (JSReferenceExpression) node.getFirstChild();
PsiElement reference;
if (referenceExpression.getReference() != null && (reference = referenceExpression.getReference().resolve()) != null && reference instanceof JSProperty && OxyTemplateIndexUtil.isMacro(reference)) {
usedMacros.put(referenceExpression, (JSElement) reference);
}
}
super.visitJSCallExpression(node);
}
}.visitFile(psiFile.getViewProvider().getPsi(OxyTemplateInnerJs.INSTANCE));
return usedMacros;
}
Aggregations