use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner in project intellij-plugins by JetBrains.
the class FlexMoveMembersTest method performAction.
private void performAction(String sourceClassName, final String targetClassName, final String visibility, final String[] memberNames) throws Exception {
final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4).getClassResolver();
final JSClass sourceClass = (JSClass) resolver.findClassByQName(sourceClassName, ActionScriptMoveMembersDialog.getScope(myProject));
assertNotNull("Class " + sourceClassName + " not found", sourceClass);
JSClass targetClass = (JSClass) resolver.findClassByQName(targetClassName, ActionScriptMoveMembersDialog.getScope(myProject));
assertNotNull("Class " + targetClassName + " not found", targetClass);
final List<JSMemberInfo> memberInfos = new ArrayList<>();
JSMemberInfo.extractStaticMembers(sourceClass, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {
@Override
public boolean includeMember(JSAttributeListOwner member) {
return memberNames.length == 0 || ArrayUtil.contains(member.getName(), memberNames);
}
});
JSMemberInfo.sortByOffset(memberInfos);
for (JSMemberInfo memberInfo : memberInfos) {
memberInfo.setChecked(true);
}
new JSMoveMembersProcessor(myProject, null, sourceClass, ActionScriptMoveMembersDialog.getScope(myProject), new JSMoveMembersOptions() {
@Override
public JSAttributeListOwner[] getSelectedMembers() {
final JSMemberInfo[] selected = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.alwaysTrue());
JSAttributeListOwner[] result = new JSAttributeListOwner[selected.length];
for (int i = 0; i < result.length; i++) {
result[i] = selected[i].getMember();
}
return result;
}
@Override
public String getTargetClassName() {
return targetClassName;
}
@Override
public String getMemberVisibility() {
return visibility;
}
}).run();
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
FileDocumentManager.getInstance().saveAllDocuments();
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner in project intellij-plugins by JetBrains.
the class FlexPullUpTest method getMemberInfos.
public static List<JSMemberInfo> getMemberInfos(final String[] members, JSClass clazz, boolean makeAbstract) {
final List<JSMemberInfo> memberInfos = new ArrayList<>();
JSMemberInfo.extractClassMembers(clazz, memberInfos, new MemberInfoBase.Filter<JSAttributeListOwner>() {
@Override
public boolean includeMember(JSAttributeListOwner member) {
return ArrayUtil.contains(member.getName(), members);
}
});
//assertTrue("Nothing to process", !memberInfos.isEmpty());
for (JSMemberInfo memberInfo : memberInfos) {
memberInfo.setChecked(true);
if (makeAbstract) {
memberInfo.setToAbstract(true);
}
}
JSMemberInfo.sortByOffset(memberInfos);
return memberInfos;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner in project intellij-plugins by JetBrains.
the class FlashUmlVisibilityManager method getVisibilityLevel.
public VisibilityLevel getVisibilityLevel(Object element) {
if (element instanceof JSAttributeListOwner) {
JSAttributeList attributeList = ((JSAttributeListOwner) element).getAttributeList();
JSAttributeList.AccessType accessType = attributeList != null ? attributeList.getAccessType() : JSUtils.getImplicitAccessType((PsiElement) element);
return predefinedLevels.get(ArrayUtil.indexOf(JSVisibilityUtil.ACCESS_TYPES, accessType));
}
return null;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner in project intellij-plugins by JetBrains.
the class FlexMoveClassProcessor method detectConflicts.
private MultiMap<PsiElement, String> detectConflicts(UsageInfo[] usages) {
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
final Collection<PsiElement> filesToMove = Arrays.asList(myElementsToMove);
JSVisibilityUtil.Options options = new JSVisibilityUtil.Options();
for (PsiElement file : filesToMove) {
options.overridePackage(file, myTargetPackage);
}
for (UsageInfo usage : usages) {
final PsiElement element = usage.getElement();
if (!(element instanceof JSReferenceExpression)) {
continue;
}
if (CommonRefactoringUtil.isAncestor(element, filesToMove)) {
continue;
}
JSReferenceExpression refExpr = (JSReferenceExpression) element;
final PsiElement resolved = refExpr.resolve();
if (!(resolved instanceof JSQualifiedNamedElement)) {
continue;
}
PsiElement containingClass = null;
if (resolved instanceof JSFunction && ((JSFunction) resolved).isConstructor() && myElements.contains(containingClass = resolved.getParent()) || myElements.contains(resolved)) {
JSRefactoringConflictsUtil.checkAccessibility((JSAttributeListOwner) resolved, (JSClass) containingClass, null, refExpr, conflicts, true, options);
}
}
for (PsiElement fileToMove : filesToMove) {
JSRefactoringConflictsUtil.checkOutgoingReferencesAccessibility(fileToMove, filesToMove, null, true, conflicts, Conditions.alwaysTrue(), options);
}
//JSRefactoringConflictsUtil.analyzeModuleConflicts(myProject, myElements, usages, myTargetDirectory, conflicts);
return conflicts;
}
use of com.intellij.lang.javascript.psi.ecmal4.JSAttributeListOwner in project intellij-plugins by JetBrains.
the class FlexMoveInnerClassProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
try {
ActionScriptCreateClassOrInterfaceFix.createClass(myClassName, myPackageName, myTargetDirectory, false);
} catch (Exception e) {
Messages.showErrorDialog(myProject, e.getMessage(), getCommandName());
return;
}
final PsiFile sourceFile = myElement.getContainingFile();
Collection<String> importsInTargetFile = new HashSet<>();
Collection<String> namespacesInTargetFile = new HashSet<>();
List<FormatFixer> formatters = new ArrayList<>();
//JSRefactoringUtil.addRemovalFormatters(mySourceClass, myMembersToMove, Condition.TRUE, Condition.TRUE, postponedFormatters);
JSClass targetClass = myElement instanceof JSClass ? (JSClass) myElement : null;
JSRefactoringUtil.fixOutgoingReferences(myElement, importsInTargetFile, namespacesInTargetFile, Collections.singletonList(((JSAttributeListOwner) myElement)), targetClass, false, false);
myElement.setName(myClassName);
Collection<UsageInfo> usagesToProcess = new ArrayList<>(Arrays.asList(usages));
for (Iterator<UsageInfo> i = usagesToProcess.iterator(); i.hasNext(); ) {
UsageInfo usage = i.next();
PsiElement element;
if (usage instanceof NonCodeUsageInfo || (element = usage.getElement()) == null || !PsiTreeUtil.isAncestor(myElement, element, false)) {
continue;
}
if (element instanceof JSReferenceExpression) {
((JSReferenceExpression) element).bindToElement(myElement);
} else if (element instanceof PsiNamedElement) {
((PsiNamedElement) element).setName(myClassName);
} else {
continue;
}
i.remove();
}
final PsiElement clazz = ActionScriptClassResolver.findClassByQNameStatic(StringUtil.getQualifiedName(myPackageName, myClassName), GlobalSearchScope.projectScope(myProject));
PsiElement toInsert = myElement instanceof JSVariable ? JSRefactoringUtil.getVarStatementCopy((JSVariable) myElement) : myElement.copy();
final PsiElement inserted = clazz.replace(toInsert);
PsiFile insertedContainingFile = inserted.getContainingFile();
JSQualifiedNamedElement newClass = inserted instanceof JSVarStatement ? ((JSVarStatement) inserted).getVariables()[0] : (JSQualifiedNamedElement) inserted;
SmartPsiElementPointer<JSQualifiedNamedElement> newClassPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(newClass);
JSRefactoringUtil.handleDocCommentAndFormat(inserted, formatters);
JSRefactoringUtil.deleteWithNoPostponedFormatting(myElement);
if (myPackageName.length() > 0) {
for (UsageInfo usage : usagesToProcess) {
if (usage instanceof NonCodeUsageInfo || usage.getFile() != sourceFile)
continue;
final PsiElement element = usage.getElement();
if (element == null)
continue;
ImportUtils.doImport(element, StringUtil.getQualifiedName(myPackageName, myClassName), true);
}
}
JSRefactoringUtil.postProcess(sourceFile, newClass, Collections.singletonList(sourceFile), importsInTargetFile, namespacesInTargetFile, formatters, true, false);
boolean makePublic = false;
newClass = newClassPointer.getElement();
List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for (UsageInfo usage : usagesToProcess) {
if (usage instanceof NonCodeUsageInfo) {
nonCodeUsages.add((NonCodeUsageInfo) usage);
} else {
JSReferenceExpression refExpr = (JSReferenceExpression) usage.getElement();
if (refExpr == null) {
continue;
}
makePublic |= JSPsiImplUtils.getQNameForMove(refExpr, newClass) != null;
refExpr.bindToElement(newClass);
}
}
JSChangeVisibilityUtil.setVisibility((JSAttributeListOwner) newClass, makePublic ? JSAttributeList.AccessType.PUBLIC : JSAttributeList.AccessType.PACKAGE_LOCAL);
myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
if (myMoveCallback != null) {
myMoveCallback.refactoringCompleted();
}
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, insertedContainingFile.getVirtualFile(), newClass.getTextOffset());
FileEditorManager.getInstance(myProject).openTextEditor(descriptor, true);
}
Aggregations