use of com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement 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.JSPackageStatement in project intellij-plugins by JetBrains.
the class CreateJSSubclassIntention method invoke.
@Override
public void invoke(@NotNull final Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final JSClass jsClass = PsiTreeUtil.getParentOfType(element, JSClass.class);
if (jsClass == null)
return;
final PsiElement parent = jsClass.getParent();
if (!(parent instanceof JSPackageStatement))
return;
final JSPackageStatement jsPackageStatement = (JSPackageStatement) parent;
final String defaultTemplateName = ActionScriptCreateClassOrInterfaceFix.ACTION_SCRIPT_CLASS_WITH_SUPERS_TEMPLATE_NAME;
final String className;
final String packageName;
final String templateName;
final PsiDirectory targetDirectory;
final Collection<String> interfaces;
final Map<String, Object> templateAttributes;
final JSClass superClass;
if (ApplicationManager.getApplication().isUnitTestMode()) {
className = suggestSubclassName(jsClass.getName());
packageName = "foo";
templateName = defaultTemplateName;
targetDirectory = WriteAction.compute(() -> ActionScriptCreateClassOrInterfaceFix.findOrCreateDirectory(packageName, jsPackageStatement));
interfaces = jsClass.isInterface() ? Collections.singletonList(jsClass.getQualifiedName()) : Collections.emptyList();
templateAttributes = Collections.emptyMap();
superClass = jsClass.isInterface() ? null : jsClass;
} else {
CreateClassParameters p = ActionScriptCreateClassOrInterfaceFix.createAndShow(defaultTemplateName, jsClass, suggestSubclassName(jsClass.getName()), true, jsPackageStatement.getQualifiedName(), jsClass, JSBundle.message("new.actionscript.class.dialog.title"), () -> ActionScriptCreateClassOrInterfaceFix.getApplicableTemplates(ActionScriptCreateClassOrInterfaceFix.ACTIONSCRIPT_TEMPLATES_EXTENSIONS, project));
if (p == null)
return;
className = p.getClassName();
packageName = p.getPackageName();
templateName = p.getTemplateName();
targetDirectory = p.getTargetDirectory();
superClass = ActionScriptCreateClassOrInterfaceFix.calcClass(p.getSuperclassFqn(), element);
interfaces = p.getInterfacesFqns();
templateAttributes = new HashMap<>(p.getTemplateAttributes());
}
JSClass createdClass = ActionScriptCreateClassOrInterfaceFix.createClass(templateName, className, packageName, superClass, interfaces, targetDirectory, getTitle(jsClass), true, templateAttributes, aClass -> {
if (aClass != null && !aClass.isInterface() && (jsClass.isInterface() || !interfaces.isEmpty())) {
new MyImplementMethodsHandler(aClass).execute();
}
});
if (createdClass != null) {
createdClass.navigate(true);
}
}
use of com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement in project intellij-plugins by JetBrains.
the class ActionScriptImportHandler method _resolveTypeName.
// TODO _str should be JSReferenceExpression for caching!
@Nullable
private JSImportedElementResolveResult _resolveTypeName(@Nullable final String _name, @NotNull PsiElement context) {
String name = _name;
if (name == null)
return null;
JSResolveUtil.GenericSignature genericSignature = JSResolveUtil.extractGenericSignature(name);
if (genericSignature != null) {
name = genericSignature.elementType;
}
final Ref<JSImportedElementResolveResult> resultRef = new Ref<>();
final String name1 = name;
JSResolveUtil.walkOverStructure(context, context1 -> {
JSImportedElementResolveResult resolved = null;
if (context1 instanceof XmlBackedJSClassImpl) {
XmlTag rootTag = ((XmlBackedJSClassImpl) context1).getParent();
if (rootTag != null && name1.equals(rootTag.getLocalName())) {
final XmlElementDescriptor descriptor = rootTag.getDescriptor();
PsiElement element = descriptor != null ? descriptor.getDeclaration() : null;
if (element instanceof XmlFile) {
element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
}
final String s = element instanceof JSClass ? ((JSClass) element).getQualifiedName() : rootTag.getLocalName();
resolved = new JSImportedElementResolveResult(s);
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
}
} else if (context1 instanceof JSQualifiedNamedElement) {
if (context1 instanceof JSClass && name1.equals(context1.getName())) {
resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) context1).getQualifiedName());
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
if (resolved == null && context1.getParent() instanceof JSFile) {
final String qName = ((JSQualifiedNamedElement) context1).getQualifiedName();
final String packageName = qName == null ? "" : context1 instanceof JSPackageStatement ? qName + "." : qName.substring(0, qName.lastIndexOf('.') + 1);
if (packageName.length() != 0) {
final PsiElement byQName = JSClassResolver.findClassFromNamespace(packageName + name1, context1);
if (byQName instanceof JSQualifiedNamedElement) {
resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) byQName).getQualifiedName());
}
}
}
}
} else {
resolved = resolveTypeNameUsingImports(name1, context1);
PsiElement contextOfContext;
if (resolved == null && context1 instanceof JSFile && (contextOfContext = context1.getContext()) != null) {
XmlBackedJSClassImpl clazz = contextOfContext instanceof XmlElement ? (XmlBackedJSClassImpl) XmlBackedJSClassImpl.getContainingComponent((XmlElement) contextOfContext) : null;
if (clazz != null) {
SinkResolveProcessor r = new SinkResolveProcessor(name1, new ResolveResultSink(null, name1));
r.setForceImportsForPlace(true);
boolean b = clazz.doImportFromScripts(r, clazz);
if (!b) {
PsiElement resultFromProcessor = r.getResult();
JSQualifiedNamedElement clazzFromComponent = resultFromProcessor instanceof JSQualifiedNamedElement ? (JSQualifiedNamedElement) resultFromProcessor : null;
if (clazzFromComponent != null) {
resolved = new JSImportedElementResolveResult(clazzFromComponent.getQualifiedName(), clazz, null);
}
}
}
}
}
if (resolved != null) {
resultRef.set(resolved);
return false;
}
if (context1 instanceof JSPackageStatement)
return false;
return true;
});
JSImportedElementResolveResult result = resultRef.get();
if (genericSignature != null && result != null) {
// TODO: more than one type parameter
StringBuilder genericSignatureBuffer = new StringBuilder();
genericSignatureBuffer.append(".<");
genericSignatureBuffer.append(resolveTypeName(genericSignature.genericType, context).getQualifiedName());
genericSignatureBuffer.append(">");
result = result.appendSignature(genericSignatureBuffer.toString());
}
return result;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement in project intellij-plugins by JetBrains.
the class ActionScriptReferenceExpressionResolver method resolve.
@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
if (myReferencedName == null)
return ResolveResult.EMPTY_ARRAY;
PsiElement currentParent = JSResolveUtil.getTopReferenceParent(myParent);
if (JSResolveUtil.isSelfReference(currentParent, myRef)) {
if (!(currentParent instanceof JSPackageStatement) || myParent == currentParent) {
return new ResolveResult[] { new JSResolveResult(currentParent) };
}
}
if (isConditionalVariableReference(currentParent, myRef)) {
if (ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
// do not red highlight conditional compiler definitions in 3rd party library/SDK source code
return new ResolveResult[] { new JSResolveResult(myRef) };
} else {
return resolveConditionalCompilationVariable(myRef);
}
}
if (myRef.isAttributeReference()) {
return dummyResult(myRef);
}
if (JSCommonTypeNames.ANY_TYPE.equals(myReferencedName)) {
if (currentParent instanceof JSImportStatement && myQualifier instanceof JSReferenceExpression)
return ((JSReferenceExpression) myQualifier).multiResolve(false);
if (myParent instanceof JSE4XNamespaceReference)
return dummyResult(myRef);
}
// nonqualified items in implements list in mxml
if (myParent instanceof JSReferenceListMember && myParent.getParent().getNode().getElementType() == JSStubElementTypes.IMPLEMENTS_LIST && myRef.getQualifier() == null && myContainingFile instanceof JSFile && XmlBackedJSClassImpl.isImplementsAttribute((JSFile) myContainingFile)) {
PsiElement byQName = ActionScriptClassResolver.findClassByQNameStatic(myRef.getText(), myRef);
// for some reason Flex compiler allows to implement non-public interface in default package, so let's not check access type here
if (byQName != null)
return new ResolveResult[] { new JSResolveResult(byQName) };
return ResolveResult.EMPTY_ARRAY;
}
SinkResolveProcessor<ResolveResultSink> localProcessor;
if (myLocalResolve) {
final PsiElement topParent = JSResolveUtil.getTopReferenceParent(myParent);
localProcessor = new SinkResolveProcessor<ResolveResultSink>(myReferencedName, myRef, new ResolveResultSink(myRef, myReferencedName)) {
@Override
public boolean needPackages() {
if (myParent instanceof JSReferenceExpression && topParent instanceof JSImportStatement) {
return true;
}
return super.needPackages();
}
};
localProcessor.setToProcessHierarchy(true);
JSReferenceExpressionImpl.doProcessLocalDeclarations(myRef, myQualifier, localProcessor, true, false, null);
PsiElement jsElement = localProcessor.getResult();
if (myQualifier instanceof JSThisExpression && localProcessor.processingEncounteredAnyTypeAccess() && // this is from ecma script closure, proceed it in JavaScript way
jsElement != null) {
localProcessor.getResults().clear();
jsElement = null;
}
if (myQualifier == null) {
final JSReferenceExpression namespaceReference = JSReferenceExpressionImpl.getNamespaceReference(myRef);
ResolveResult[] resolveResultsAsConditionalCompilationVariable = null;
if (namespaceReference != null && (namespaceReference == myRef || namespaceReference.resolve() == namespaceReference)) {
if (jsElement == null && ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
// do not red highlight conditional compiler definitions in 3rd party library/SDK source code
return new ResolveResult[] { new JSResolveResult(myRef) };
}
resolveResultsAsConditionalCompilationVariable = resolveConditionalCompilationVariable(myRef);
}
if (resolveResultsAsConditionalCompilationVariable != null && resolveResultsAsConditionalCompilationVariable.length > 0 && (jsElement == null || resolveResultsAsConditionalCompilationVariable[0].isValidResult())) {
return resolveResultsAsConditionalCompilationVariable;
}
}
if (jsElement != null || localProcessor.isEncounteredDynamicClasses() && myQualifier == null || !localProcessor.processingEncounteredAnyTypeAccess() && !localProcessor.isEncounteredDynamicClasses()) {
return localProcessor.getResultsAsResolveResults();
}
} else {
final QualifiedItemProcessor<ResolveResultSink> processor = new QualifiedItemProcessor<>(new ResolveResultSink(myRef, myReferencedName), myContainingFile);
processor.setTypeContext(JSResolveUtil.isExprInTypeContext(myRef));
JSTypeEvaluator.evaluateTypes(myQualifier, myContainingFile, processor);
if (processor.resolved == QualifiedItemProcessor.TypeResolveState.PrefixUnknown) {
return dummyResult(myRef);
}
if (processor.resolved == QualifiedItemProcessor.TypeResolveState.Resolved || processor.resolved == QualifiedItemProcessor.TypeResolveState.Undefined || processor.getResult() != null) {
return processor.getResultsAsResolveResults();
} else {
localProcessor = processor;
}
}
ResolveResult[] results = resolveFromIndices(localProcessor);
if (results.length == 0 && localProcessor.isEncounteredXmlLiteral()) {
return dummyResult(myRef);
}
return results;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement in project intellij-plugins by JetBrains.
the class FlashRunConfiguration method getRefactoringElementListener.
@Override
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
if (!myRunnerParameters.isOverrideMainClass()) {
return null;
}
final Module module = ModuleManager.getInstance(getProject()).findModuleByName(myRunnerParameters.getModuleName());
if (!(element instanceof PsiDirectoryContainer) && !(element instanceof JSPackage) && !(element instanceof JSPackageStatement) && (module == null || !module.equals(ModuleUtilCore.findModuleForPsiElement(element)))) {
return null;
}
final String currentPackage = StringUtil.getPackageName(myRunnerParameters.getOverriddenMainClass());
if ((element instanceof PsiDirectoryContainer || element instanceof JSPackage || element instanceof JSPackageStatement) && Comparing.strEqual(FlexRefactoringListenerProvider.getPackageName(element), currentPackage)) {
return new FlexRunConfigRefactoringListener.PackageRefactoringListener(this);
}
if (element instanceof PsiDirectory && containsClass(module, ((PsiDirectory) element), myRunnerParameters.getOverriddenMainClass())) {
return new FlexRunConfigRefactoringListener.PsiDirectoryRefactoringListener(this);
}
final JSClass jsClass = FlexRefactoringListenerProvider.getJSClass(element);
if (jsClass != null && Comparing.strEqual(jsClass.getQualifiedName(), myRunnerParameters.getOverriddenMainClass())) {
return new FlexRunConfigRefactoringListener.JSClassRefactoringListener(this);
}
return null;
}
Aggregations