use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class NewFlexComponentUmlAction method createElement.
@Nullable
@Override
public Object createElement(final DiagramDataModel<Object> model, final CreateClassParameters params, final AnActionEvent event) {
final Ref<JSClass> clazz = new Ref<>();
CommandProcessor.getInstance().executeCommand(params.getTargetDirectory().getProject(), () -> {
try {
ActionScriptCreateClassOrInterfaceFix.createClass(params.getTemplateName(), params.getClassName(), params.getPackageName(), getSuperClass(params), params.getInterfacesFqns(), params.getTargetDirectory(), getActionName(), true, new HashMap<>(params.getTemplateAttributes()), jsClass -> {
CreateFlexComponentFix.fixParentComponent(jsClass, params.getSuperclassFqn());
clazz.set(jsClass);
});
} catch (Exception e) {
throw new IncorrectOperationException(e);
}
}, JSBundle.message(FlexBundle.message("new.flex.component.command.name")), null);
return clazz.get();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlImplementationsProvider method getElements.
public Object[] getElements(Object element, Project project) {
JSClass clazz = (JSClass) element;
final Collection<PsiElement> inheritors = Collections.synchronizedSet(new THashSet<PsiElement>());
final Processor<JSClass> p = aClass -> {
final PsiElement navigationElement = aClass.getNavigationElement();
inheritors.add(navigationElement instanceof JSClass ? navigationElement : aClass);
return true;
};
JSClassSearch.searchClassInheritors(clazz, true).forEach(p);
if (clazz.isInterface()) {
JSClassSearch.searchInterfaceImplementations(clazz, true).forEach(p);
}
return inheritors.toArray(new PsiElement[inheritors.size()]);
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlEdgeCreationPolicy method acceptTarget.
public boolean acceptTarget(@NotNull final DiagramNode<Object> target) {
if (!(target.getIdentifyingElement() instanceof JSClass))
return false;
final JSClass clazz = (JSClass) target.getIdentifyingElement();
JSAttributeList attributeList = clazz.getAttributeList();
if (attributeList != null && attributeList.hasModifier(JSAttributeList.ModifierType.FINAL))
return false;
return true;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class FlashUmlElementManager method findInDataContext.
public PsiElement findInDataContext(DataContext context) {
PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
if (isAcceptableAsNode(element)) {
return element;
}
// if caret stands on a member or whitespace, show diagram for the enclosing class
final Editor editor = LangDataKeys.EDITOR.getData(context);
if (editor != null) {
final PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
if (file != null) {
PsiElement elementAtOffset = file.findElementAt(editor.getCaretModel().getOffset());
final PsiNamedElement enclosing = PsiTreeUtil.getParentOfType(elementAtOffset, JSClass.class, JSFile.class, XmlFile.class);
if (enclosing instanceof JSClass) {
element = enclosing;
} else if (enclosing instanceof JSFile) {
final XmlBackedJSClass clazz = JSResolveUtil.getXmlBackedClass((JSFile) enclosing);
if (clazz != null) {
return clazz;
}
JSElement qualified = JSPsiImplUtils.findQualifiedElement((JSFile) enclosing);
if (qualified instanceof JSClass) {
return qualified;
}
}
if (enclosing instanceof XmlFile && JavaScriptSupportLoader.isFlexMxmFile((PsiFile) enclosing)) {
return XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) enclosing);
}
}
}
// handle PsiPackage (invoked when 'View as packages' mode is selected)
Project project = CommonDataKeys.PROJECT.getData(context);
if (project != null) {
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
if (file != null) {
PsiDirectory directory = PsiManager.getInstance(project).findDirectory(file);
if (directory != null && isAcceptableAsNode(directory)) {
return directory;
}
}
}
return element;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSClass in project intellij-plugins by JetBrains.
the class InjectedPsiVisitor method visit.
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<Shred> places) {
// will be called 2 - first for {demandSelectedTO.journalist.nom} and second for {demandSelectedTO.journalist.prenom}
if (visited) {
return;
}
visited = true;
assert places.size() == 1;
assert places.get(0).getHost() == host;
JSFile jsFile = (JSFile) injectedPsi;
JSSourceElement[] statements = jsFile.getStatements();
if (statements.length == 0 && (valueWriter = checkCompilerDirective(jsFile)) != null) {
return;
}
assert statements.length == 1;
final JSExpression expr = ((JSExpressionStatement) statements[0]).getExpression();
// <s:Image source="@Embed(source='/Users/develar/Pictures/iChat Ico
if (!(expr instanceof JSCallExpression)) {
valueWriter = InjectedASWriter.IGNORE;
return;
}
JSCallExpression expression = (JSCallExpression) expr;
JSExpression[] arguments = expression.getArguments();
if (arguments.length != 1) {
logUnsupported();
return;
}
if (arguments[0] instanceof JSArrayLiteralExpression) {
if (isUnexpected(JSCommonTypeNames.ARRAY_CLASS_NAME)) {
return;
}
JSArrayLiteralExpression arrayLiteralExpression = (JSArrayLiteralExpression) arguments[0];
JSExpression[] expressions = arrayLiteralExpression.getExpressions();
if (expressions.length == 0) {
valueWriter = InjectedASWriter.IGNORE;
return;
}
// create ExpressionBinding only if expressions contains non-primitive values
for (JSExpression itemExpression : expressions) {
if (!(itemExpression instanceof JSLiteralExpression)) {
binding = new ExpressionBinding(arrayLiteralExpression);
return;
}
}
valueWriter = new InjectedArrayOfPrimitivesWriter(arrayLiteralExpression);
} else if (arguments[0] instanceof JSReferenceExpression && arguments[0].getChildren().length == 0) {
// if propertyName="{CustomSkin}", so, write class, otherwise, it is binding
JSReferenceExpression referenceExpression = (JSReferenceExpression) arguments[0];
PsiElement element = referenceExpression.resolve();
if (element == null) {
invalidPropertyException = new InvalidPropertyException(expression, "unresolved.variable.or.type", referenceExpression.getReferencedName());
} else if (element instanceof JSClass) {
if (isExpectedObjectOrAnyType() || AsCommonTypeNames.CLASS.equals(expectedType)) {
valueWriter = new ClassValueWriter(((JSClass) element));
} else {
invalidPropertyException = new InvalidPropertyException(expression, "implicit.coercion", "Class", expectedType);
}
} else if (element instanceof JSVariable) {
binding = new VariableBinding(((JSVariable) element));
} else if (element instanceof JSFunction) {
binding = new ExpressionBinding(((JSFunction) element));
} else {
binding = new MxmlObjectBinding(referenceExpression.getReferencedName(), JSCommonTypeNames.ARRAY_CLASS_NAME.equals(expectedType));
}
} else {
binding = new ExpressionBinding(arguments[0]);
}
}
Aggregations