-
Notifications
You must be signed in to change notification settings - Fork 13
fix compatibility with IDEA 2016.1 and above #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,10 @@ | |
|
|
||
| import com.chrisfolger.needsmoredojo.core.amd.CompletionCallback; | ||
| import com.chrisfolger.needsmoredojo.core.amd.importing.InvalidDefineException; | ||
| import com.chrisfolger.needsmoredojo.core.settings.DojoSettings; | ||
| import com.intellij.lang.javascript.psi.*; | ||
| import com.intellij.openapi.components.ServiceManager; | ||
| import com.intellij.openapi.project.Project; | ||
| import com.intellij.psi.PsiElement; | ||
| import com.intellij.psi.PsiElementVisitor; | ||
| import com.intellij.psi.PsiFile; | ||
|
|
@@ -183,8 +186,8 @@ public void run(Object[] result) { | |
| if(parent instanceof JSCallExpression) | ||
| { | ||
| JSCallExpression statement = (JSCallExpression) parent; | ||
| if(statement.getMethodExpression() != null && (statement.getMethodExpression().getText().equals("define") | ||
| || statement.getMethodExpression().getText().equals("require"))) | ||
| if(statement.getMethodExpression() != null && | ||
| isValidImportBlockName(statement.getMethodExpression().getText(), element.getProject())) | ||
| { | ||
| return getDefineStatementItemsFromArguments(statement.getArguments(), statement); | ||
| } | ||
|
|
@@ -238,7 +241,7 @@ public Set<JSCallExpression> getAllImportBlocks(PsiFile file) | |
| public void visitJSCallExpression(JSCallExpression expression) | ||
| { | ||
| if(expression != null && expression.getMethodExpression() != null && | ||
| (expression.getMethodExpression().getText().equals("define") || expression.getMethodExpression().getText().equals("require"))) | ||
| isValidImportBlockName(expression.getMethodExpression().getText(), file.getProject())) | ||
| { | ||
| listOfDefinesOrRequiresToVisit.add(expression); | ||
| } | ||
|
|
@@ -250,4 +253,15 @@ public void visitJSCallExpression(JSCallExpression expression) | |
|
|
||
| return listOfDefinesOrRequiresToVisit; | ||
| } | ||
|
|
||
| private Boolean isValidImportBlockName(String name, Project project) { | ||
| DojoSettings settings = ServiceManager.getService(project, DojoSettings.class); | ||
| String[] defineBlockNames = settings.getImportBlockNames().split(","); | ||
| for (String defineBlockName:defineBlockNames) { | ||
| if (name.equals(defineBlockName)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also line#47 be changed to |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ private void displayDuplicateMessage(String parameter, Project project) | |
|
|
||
| public void createImport(String module, String quoteCharacter, String parameter, JSArrayLiteralExpression imports, JSParameterList parameters) | ||
| { | ||
| for(JSParameter element : parameters.getParameters()) | ||
| for(JSParameter element : parameters.getParameterVariables()) | ||
| { | ||
| if(element.getName().equals(parameter)) | ||
| { | ||
|
|
@@ -37,7 +37,7 @@ public void createImport(String module, String quoteCharacter, String parameter, | |
| } | ||
| } | ||
|
|
||
| if(imports.getChildren().length == 0) | ||
| if(imports.getExpressions().length == 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the benefit of using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem that when adding an import (Ctrl+Shift+O, 2), the import was added in the wrong location, usually outside of the JavaScript import array. Using |
||
| { | ||
| // how to insert | ||
| /* | ||
|
|
@@ -80,7 +80,7 @@ else if(defineText.contains("\n")) | |
| else | ||
| { | ||
| String formatString = quoteCharacter + "%s" + quoteCharacter + ","; | ||
| JSUtil.addStatementBeforeElement(imports, imports.getChildren()[0], String.format(formatString, module), "\n"); | ||
| JSUtil.addStatementBeforeElement(imports, imports.getExpressions()[0], String.format(formatString, module), "\n"); | ||
| if(parameters.getChildren().length > 0) | ||
| { | ||
| JSUtil.addStatementBeforeElement(parameters, parameters.getChildren()[0], parameter + ",", " "); | ||
|
|
@@ -99,9 +99,9 @@ public void createImport(String module, String quoteCharacter, JSArrayLiteralExp | |
|
|
||
| // if the parameter would cause a duplicate, then assume it is a module with a different path but the same name | ||
| // as an existing imported module. | ||
| for (int i = 0; i < parameters.getParameters().length; i++) | ||
| for (int i = 0; i < parameters.getParameterVariables().length; i++) | ||
| { | ||
| JSParameter existingParameter = parameters.getParameters()[i]; | ||
| JSParameter existingParameter = parameters.getParameterVariables()[i]; | ||
| if(existingParameter != null && existingParameter.getText().equals(parameter)) | ||
| { | ||
| String existingAbsolutePath = NameResolver.getModuleAndPathWithoutPluginResourceId(imports.getExpressions()[i].getText().replaceAll("'", "").replaceAll("\"", "")); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ public void doSwap(PsiElement source, Editor editor, AMDPsiUtil.Direction direct | |
|
|
||
| int sourceIndex = PsiUtil.getIndexInParent(defines[0]); | ||
| int destinationIndex = PsiUtil.getIndexInParent(defines[1]); | ||
| JSParameter[] parameterList = items.getFunction().getParameters(); | ||
| JSParameter[] parameterList = items.getFunction().getParameterVariables(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also src/com/chrisfolger/needsmoredojo/core/amd/define/NearestAMDImportLocator.java still use the old And src/com/chrisfolger/needsmoredojo/core/amd/importing/ImportUpdater.java still use the old
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a lot of cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TomDevs, thank you fro your reply. You may be right, replacing the minimum possible, but there was a problem reported here: #181 (comment) that was handled by replacing |
||
|
|
||
| if(sourceIndex >= parameterList.length || destinationIndex >= parameterList.length) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#181 suggests moving the file to resources/META-INF/plugin.xml and updating resources/META-INF/MANIFEST.MF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this file location particularly matters, but if this becomes a problem I'll happily move it.