use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class ActionScriptSmartCompletionContributor method getEventsMap.
public static Map<String, String> getEventsMap(JSClass clazzToProcess) {
if (clazzToProcess == null)
return Collections.emptyMap();
final Map<String, String> eventsMap = new THashMap<>();
class EventsDataCollector extends ResolveProcessor implements ActionScriptResolveUtil.MetaDataProcessor {
public EventsDataCollector() {
super(null);
setToProcessHierarchy(true);
setToProcessMembers(false);
setTypeContext(true);
setLocalResolve(true);
}
@Override
public boolean process(@NotNull final JSAttribute jsAttribute) {
if ("Event".equals(jsAttribute.getName())) {
final JSAttributeNameValuePair eventAttr = jsAttribute.getValueByName("name");
JSAttributeNameValuePair typeAttr = jsAttribute.getValueByName("type");
if (eventAttr != null && typeAttr != null) {
final String simpleValue = eventAttr.getSimpleValue();
if (simpleValue != null) {
eventsMap.put(simpleValue, typeAttr.getSimpleValue());
}
}
}
return true;
}
@Override
public boolean handleOtherElement(final PsiElement el, final PsiElement context, final Ref<PsiElement> continuePassElement) {
return true;
}
@Override
public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
if (element instanceof JSClass) {
ActionScriptResolveUtil.processMetaAttributesForClass(element, this, true);
}
return true;
}
}
final EventsDataCollector eventsDataCollector = new EventsDataCollector();
if (clazzToProcess instanceof XmlBackedJSClassImpl) {
XmlFile file = (XmlFile) clazzToProcess.getParent().getContainingFile();
if (file != null && JavaScriptSupportLoader.isFlexMxmFile(file)) {
final XmlDocument xmlDocument = file.getDocument();
final XmlTag rootTag = xmlDocument == null ? null : xmlDocument.getRootTag();
final XmlTag[] tags = rootTag == null ? XmlTag.EMPTY : MxmlJSClass.findLanguageSubTags(rootTag, FlexPredefinedTagNames.METADATA);
JSResolveUtil.JSInjectedFilesVisitor injectedFilesVisitor = new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(JSFile file) {
for (PsiElement element : file.getChildren()) {
if (element instanceof JSAttributeList) {
ActionScriptResolveUtil.processAttributeList(eventsDataCollector, null, (JSAttributeList) element, true, true);
}
}
}
};
for (XmlTag tag : tags) {
JSResolveUtil.processInjectedFileForTag(tag, injectedFilesVisitor);
}
}
}
clazzToProcess.processDeclarations(eventsDataCollector, ResolveState.initial(), clazzToProcess, clazzToProcess);
return eventsMap;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class JSImplicitlyInternalDeclarationInspection method process.
private static void process(final JSNamedElement node, final ProblemsHolder holder) {
if (!DialectDetector.isActionScript(node))
return;
JSFunction fun = PsiTreeUtil.getParentOfType(node, JSFunction.class);
if (fun != null)
return;
ASTNode nameIdentifier = node.findNameIdentifier();
if (nameIdentifier == null)
return;
JSClass clazz = JSResolveUtil.getClassOfContext(node);
if (clazz == null) {
PsiElement parent = JSResolveUtil.findParent(node);
if (!(parent instanceof JSPackageStatement))
return;
}
JSAttributeList attributeList = ((JSAttributeListOwner) node).getAttributeList();
JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : null;
if (accessType == JSAttributeList.AccessType.PACKAGE_LOCAL && attributeList.findAccessTypeElement() == null && attributeList.getNamespaceElement() == null && !JSResolveUtil.isConstructorFunction(node)) {
holder.registerProblem(nameIdentifier.getPsi(), FlexBundle.message("js.implicitly.internal.declaration.problem"), new LocalQuickFix() {
@NotNull
@Override
public String getFamilyName() {
return FlexBundle.message("js.implicitly.internal.declaration.problem.add.internal.fix");
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement anchor = descriptor.getPsiElement();
JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) anchor.getParent(), JSAttributeList.AccessType.PACKAGE_LOCAL);
}
});
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class ActionScriptImplementedMethodProcessor method collectVisibleFunctions.
@NotNull
private JSFunctionCollector collectVisibleFunctions() {
return JSFunctionCollector.collectAllVisibleClassFunctions(myJsClass, null, jsFunction -> {
final JSAttributeList attributeList = jsFunction.getAttributeList();
if (!JSInheritanceUtil.canHaveSuperMember(attributeList)) {
return false;
}
PsiElement parentClass = JSResolveUtil.findParent(jsFunction);
if (attributeList.getAccessType() != JSAttributeList.AccessType.PUBLIC && myJsClass != parentClass) {
return false;
}
return true;
});
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList in project intellij-plugins by JetBrains.
the class ActionScriptCreateConstructorFix method applyFix.
@Override
protected void applyFix(final Project project, final PsiElement psiElement, PsiFile file, Editor editor) {
final AtomicInteger count = new AtomicInteger();
ReferencesSearch.search(myClass, myClass.getUseScope()).forEach(psiReference -> !isClassInstantiation(psiReference) || count.incrementAndGet() < 2);
int usages = count.get();
if (usages < 2) {
usages += JSInheritanceUtil.findSuperConstructorCalls(myClass).size();
}
if (usages < 2) {
final Collection<String> toImport = new ArrayList<>();
for (JSExpression argument : myNode.getArguments()) {
String type = JSResolveUtil.getQualifiedExpressionType(argument, argument.getContainingFile());
if (StringUtil.isNotEmpty(type) && ImportUtils.needsImport(myClass, StringUtil.getPackageName(type))) {
toImport.add(type);
}
}
WriteAction.run(() -> {
if (!toImport.isEmpty()) {
FormatFixer formatFixer = ImportUtils.insertImportStatements(myClass, toImport);
if (formatFixer != null) {
formatFixer.fixFormat();
}
}
super.applyFix(project, psiElement, myClass.getContainingFile(), getEditor(myClass.getProject(), myClass.getContainingFile()));
});
} else {
String text = "function " + myClass.getName() + "(){}";
JSFunction fakeFunction = (JSFunction) JSChangeUtil.createStatementFromText(project, text, JavaScriptSupportLoader.ECMA_SCRIPT_L4).getPsi();
new ChangeSignatureFix(fakeFunction, myNode.getArgumentList()) {
@Override
protected Pair<Boolean, List<JSParameterInfo>> handleCall(@NotNull JSFunction function, JSExpression[] arguments, boolean dummy) {
List<JSParameterInfo> parameterInfos = super.handleCall(function, arguments, dummy).second;
// always show dialog
return Pair.create(true, parameterInfos);
}
@Override
protected JSChangeSignatureDialog createDialog(PsiElement context, final List<JSParameterInfo> paramInfos) {
JSMethodDescriptor descriptor = new JSMethodDescriptor(myFunction.getElement(), true) {
@Override
public List<JSParameterInfo> getParameters() {
return paramInfos;
}
};
return new MyDialog(descriptor, context);
}
@Override
protected JSChangeSignatureProcessor createProcessor(List<JSParameterInfo> paramInfos, JSAttributeList attributeList, @NotNull JSFunction function) {
return new MyProcessor(function, attributeList != null ? attributeList.getAccessType() : JSAttributeList.AccessType.PACKAGE_LOCAL, myClass.getName(), "", paramInfos.toArray(new JSParameterInfo[paramInfos.size()]), Collections.emptySet());
}
}.invoke(project, editor, file);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeList 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;
}
Aggregations