From d45aee329ca3d942b43842343e7ed07e7ff2983a Mon Sep 17 00:00:00 2001 From: "michael.schramm" Date: Thu, 30 Oct 2014 18:48:01 +0100 Subject: [PATCH] reformat everything to have a better readability --- .../fileTemplates/j2ee/Spec Class.php.ft | 13 +- .../plugins/commons/php/ProjectComponent.java | 82 +-- .../commons/php/StateComponentInterface.java | 2 +- .../commons/php/action/DirectoryAction.java | 66 +- .../commons/php/action/PhpClassAction.java | 137 ++-- .../completion/GenericCompletionProvider.java | 30 +- ...nericMethodArgumentCompletionProvider.java | 50 +- .../completion/YamlCompletionProvider.java | 14 +- .../completion/YamlElementPatternHelper.java | 694 +++++++++--------- .../GenericMethodParameterInspection.java | 84 +-- .../code/inspection/PhpClassInspection.java | 26 +- .../code/locator/GenericObjectLocator.java | 8 +- .../code/locator/ObjectLocatorInterface.java | 2 +- .../type/GenericMethodCallTypeProvider.java | 56 +- .../php/code/type/GenericTypeProvider.java | 71 +- .../commons/php/composer/Composer.java | 92 ++- .../commons/php/composer/Configuration.java | 20 +- .../plugins/commons/php/composer/File.java | 40 +- .../plugins/commons/php/composer/Package.java | 28 +- .../plugins/commons/php/composer/Require.java | 26 +- .../converter/ConfigurationConverter.java | 21 +- .../composer/converter/PackageConverter.java | 8 +- .../composer/converter/RequireConverter.java | 25 +- .../plugins/commons/php/psi/PsiTreeUtils.java | 124 ++-- .../php/psi/element/MethodDecorator.java | 100 ++- .../php/psi/element/PhpClassDecorator.java | 60 +- .../php/psi/element/PluginIconProvider.java | 34 +- .../php/psi/element/PsiElementDecorator.java | 34 +- .../exceptions/InvalidArgumentException.java | 6 +- .../InvalidMethodArgumentsException.java | 6 +- .../InvalidMethodCallException.java | 6 +- .../exceptions/MissingElementException.java | 6 +- .../psi/exceptions/PhpPluginException.java | 6 +- .../php/psi/lookup/SimpleTextLookup.java | 18 +- .../psi/reference/ArrayElementReference.java | 153 ++-- .../php/psi/reference/PhpClassReference.java | 153 ++-- .../php/psi/reference/PhpMethodReference.java | 90 +-- .../commons/php/utils/FileFactory.java | 189 +++-- .../commons/php/utils/PhpClassUtils.java | 48 +- .../commons/php/utils/PhpStringUtils.java | 12 +- .../php/utils/annotation/DependsOnPlugin.java | 2 +- .../php/utils/annotation/PluginAction.java | 2 +- .../php/utils/annotation/RequireMethod.java | 2 +- .../plugins/php/phpspec/PhpSpecProject.java | 32 +- .../actions/CreateSpecForClassAction.java | 83 +-- .../plugins/php/phpspec/actions/PhpSpec.java | 4 - .../phpspec/actions/PhpSpecSwitchContext.java | 98 +-- .../code/SpecCompletionContributor.java | 8 +- .../phpspec/code/SpecCompletionProvider.java | 24 +- .../provider/WrappedObjectTypeProvider.java | 40 +- .../php/phpspec/command/AbstractCommand.java | 81 +- .../php/phpspec/command/CommandInterface.java | 26 +- .../plugins/php/phpspec/command/Describe.java | 58 +- .../plugins/php/phpspec/command/Executor.java | 190 +++-- .../plugins/php/phpspec/command/Locator.java | 88 +-- .../php/phpspec/command/PhpSpecCommand.java | 10 +- .../plugins/php/phpspec/config/PhpSpec.java | 14 +- .../php/phpspec/core/PhpSpecClass.java | 54 +- .../phpspec/core/PhpSpecClassDecorator.java | 24 +- .../phpspec/core/PhpSpecDescribedClass.java | 47 +- .../php/phpspec/core/PhpSpecIconProvider.java | 47 +- .../php/phpspec/core/PhpSpecIcons.java | 11 +- .../php/phpspec/core/PhpSpecLineMarker.java | 22 +- .../php/phpspec/core/PhpSpecTypeProvider.java | 46 +- .../inspection/PhpSpecClassInspection.java | 64 +- .../actions/GenerateSpecForClassFix.java | 58 +- .../phpspec/core/services/FileFactory.java | 6 +- .../phpspec/core/services/PhpSpecFactory.java | 38 +- .../phpspec/core/services/PhpSpecLocator.java | 93 ++- .../PhpSpecStaticCompletionProvider.java | 76 +- .../phpspec/core/services/PsiTreeUtils.java | 6 +- 71 files changed, 1967 insertions(+), 2027 deletions(-) diff --git a/resources/fileTemplates/j2ee/Spec Class.php.ft b/resources/fileTemplates/j2ee/Spec Class.php.ft index 71305f0..01f3cc4 100644 --- a/resources/fileTemplates/j2ee/Spec Class.php.ft +++ b/resources/fileTemplates/j2ee/Spec Class.php.ft @@ -1,6 +1,4 @@ shouldHaveType('${IMPLEMENTATION}'); + } +} diff --git a/src/pl/projectspace/idea/plugins/commons/php/ProjectComponent.java b/src/pl/projectspace/idea/plugins/commons/php/ProjectComponent.java index cb55d39..8364d55 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/ProjectComponent.java +++ b/src/pl/projectspace/idea/plugins/commons/php/ProjectComponent.java @@ -10,45 +10,45 @@ */ public class ProjectComponent implements com.intellij.openapi.components.ProjectComponent { - protected final Project project; - protected final PhpIndex index; - - public ProjectComponent(Project project, PhpIndex index) { - this.project = project; - this.index = index; - } - - @Override - public void projectOpened() { - } - - @Override - public void projectClosed() { - } - - @Override - public void initComponent() { - } - - @Override - public void disposeComponent() { - } - - @NotNull - @Override - public String getComponentName() { - return null; - } - - public PhpIndex getIndex() { - return index; - } - - public T getService(@NotNull Class service) { - return (T) ServiceManager.getService(project, service); - } - - public Project getProject() { - return project; - } + protected final Project project; + protected final PhpIndex index; + + public ProjectComponent(Project project, PhpIndex index) { + this.project = project; + this.index = index; + } + + @Override + public void projectOpened() { + } + + @Override + public void projectClosed() { + } + + @Override + public void initComponent() { + } + + @Override + public void disposeComponent() { + } + + @NotNull + @Override + public String getComponentName() { + return null; + } + + public PhpIndex getIndex() { + return index; + } + + public T getService(@NotNull Class service) { + return (T) ServiceManager.getService(project, service); + } + + public Project getProject() { + return project; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/StateComponentInterface.java b/src/pl/projectspace/idea/plugins/commons/php/StateComponentInterface.java index 86d63d0..d6ebde5 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/StateComponentInterface.java +++ b/src/pl/projectspace/idea/plugins/commons/php/StateComponentInterface.java @@ -2,6 +2,6 @@ public interface StateComponentInterface { - public boolean isEnabled(); + public boolean isEnabled(); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/action/DirectoryAction.java b/src/pl/projectspace/idea/plugins/commons/php/action/DirectoryAction.java index a40e47a..2c9fa9e 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/action/DirectoryAction.java +++ b/src/pl/projectspace/idea/plugins/commons/php/action/DirectoryAction.java @@ -13,51 +13,51 @@ */ public abstract class DirectoryAction extends AnAction { - protected Project project; + protected Project project; - @Override - public void actionPerformed(AnActionEvent anActionEvent) { - project = anActionEvent.getProject(); + @Override + public void actionPerformed(AnActionEvent anActionEvent) { + project = anActionEvent.getProject(); - DialogWrapper dialog = (DialogWrapper) getDialog(); - dialog.show(); + DialogWrapper dialog = (DialogWrapper) getDialog(); + dialog.show(); - if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { - onOk(dialog); - } - } + if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { + onOk(dialog); + } + } - protected String getRelativeDirectory() { - PsiDirectory selected = getSelectedDirectory(); + protected String getRelativeDirectory() { + PsiDirectory selected = getSelectedDirectory(); - if (selected == null) { + if (selected == null) { - } + } - return getSelectedDirectory().getVirtualFile().getPath().replace(project.getBasePath(), ""); - } + return getSelectedDirectory().getVirtualFile().getPath().replace(project.getBasePath(), ""); + } - protected PsiDirectory getSelectedDirectory() { - ProjectView view = ProjectView.getInstance(project); - PsiDirectory[] selected = view.getCurrentProjectViewPane().getSelectedDirectories(); + protected PsiDirectory getSelectedDirectory() { + ProjectView view = ProjectView.getInstance(project); + PsiDirectory[] selected = view.getCurrentProjectViewPane().getSelectedDirectories(); - if (selected.length == 0) { - Object[] elements = view.getCurrentProjectViewPane().getSelectedElements(); - for (Object element : elements) { - if (element instanceof PsiFile) { - return ((PsiFile) element).getContainingDirectory(); - } - } - return null; - } + if (selected.length == 0) { + Object[] elements = view.getCurrentProjectViewPane().getSelectedElements(); + for (Object element : elements) { + if (element instanceof PsiFile) { + return ((PsiFile) element).getContainingDirectory(); + } + } + return null; + } - return selected[0]; - } + return selected[0]; + } - protected abstract DialogWrapper getDialog(); + protected abstract DialogWrapper getDialog(); - protected abstract String getActionDirectory(); + protected abstract String getActionDirectory(); - protected abstract void onOk(DialogWrapper dialog); + protected abstract void onOk(DialogWrapper dialog); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/action/PhpClassAction.java b/src/pl/projectspace/idea/plugins/commons/php/action/PhpClassAction.java index c8b44ad..971ff0e 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/action/PhpClassAction.java +++ b/src/pl/projectspace/idea/plugins/commons/php/action/PhpClassAction.java @@ -6,12 +6,9 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.components.BaseComponent; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.util.Condition; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; -import com.jetbrains.php.lang.psi.PhpFile; -import com.jetbrains.php.lang.psi.PhpPsiUtil; import com.jetbrains.php.lang.psi.elements.PhpClass; import pl.projectspace.idea.plugins.commons.php.StateComponentInterface; import pl.projectspace.idea.plugins.commons.php.utils.annotation.PluginAction; @@ -21,72 +18,72 @@ */ public abstract class PhpClassAction extends AnAction { - @Override - public void update(AnActionEvent e) { - final PhpClass phpClass = getPhpClassFromContext(e); - - boolean isAvailable = isAvailable(phpClass); - - e.getPresentation().setEnabled( - isAvailable - ); - - e.getPresentation().setVisible( - isAvailable - ); - - String label = getLabel(phpClass); - - if (label != null) { - e.getPresentation().setText(label); - } - } - - public void actionPerformed(final AnActionEvent e) { - final PhpClass phpClass = getPhpClassFromContext(e); - perform(phpClass); - } - - /** - * Base check if current perform is available - depending on plugin state. - * - * @param phpClass - * @return - */ - protected boolean isAvailable(final PhpClass phpClass) { - PluginAction annotation = this.getClass().getAnnotation(PluginAction.class); - - BaseComponent component = phpClass.getProject().getComponent(annotation.value()); - if (component instanceof StateComponentInterface) { - return ((StateComponentInterface) component).isEnabled(); - } - - return false; - } - - protected PhpClass getPhpClassFromContext(AnActionEvent e) { - PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); - Editor editor = e.getData(PlatformDataKeys.EDITOR); - - if (psiFile == null || editor == null) { - return null; - } - - int offset = editor.getCaretModel().getOffset(); - PsiElement elementAt = psiFile.findElementAt(offset); - - return PsiTreeUtil.getParentOfType(elementAt, PhpClass.class); - } - - protected String getLabel(PhpClass phpClass) { - return null; - } - - /** - * Perform perform - * - * @param phpClass - */ - protected abstract void perform(final PhpClass phpClass); + @Override + public void update(AnActionEvent e) { + final PhpClass phpClass = getPhpClassFromContext(e); + + boolean isAvailable = isAvailable(phpClass); + + e.getPresentation().setEnabled( + isAvailable + ); + + e.getPresentation().setVisible( + isAvailable + ); + + String label = getLabel(phpClass); + + if (label != null) { + e.getPresentation().setText(label); + } + } + + public void actionPerformed(final AnActionEvent e) { + final PhpClass phpClass = getPhpClassFromContext(e); + perform(phpClass); + } + + /** + * Base check if current perform is available - depending on plugin state. + * + * @param phpClass + * @return + */ + protected boolean isAvailable(final PhpClass phpClass) { + PluginAction annotation = this.getClass().getAnnotation(PluginAction.class); + + BaseComponent component = phpClass.getProject().getComponent(annotation.value()); + if (component instanceof StateComponentInterface) { + return ((StateComponentInterface) component).isEnabled(); + } + + return false; + } + + protected PhpClass getPhpClassFromContext(AnActionEvent e) { + PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE); + Editor editor = e.getData(PlatformDataKeys.EDITOR); + + if (psiFile == null || editor == null) { + return null; + } + + int offset = editor.getCaretModel().getOffset(); + PsiElement elementAt = psiFile.findElementAt(offset); + + return PsiTreeUtil.getParentOfType(elementAt, PhpClass.class); + } + + protected String getLabel(PhpClass phpClass) { + return null; + } + + /** + * Perform perform + * + * @param phpClass + */ + protected abstract void perform(final PhpClass phpClass); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericCompletionProvider.java b/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericCompletionProvider.java index 09eea80..b1201f6 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericCompletionProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericCompletionProvider.java @@ -13,25 +13,25 @@ public abstract class GenericCompletionProvider extends CompletionProvider { - public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { - if (!isEnabled(parameters.getPosition())) { - return; - } + public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { + if (!isEnabled(parameters.getPosition())) { + return; + } - addCompletionsFor(parameters, context, resultSet); - } + addCompletionsFor(parameters, context, resultSet); + } - protected boolean isEnabled(PsiElement element) { - DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); + protected boolean isEnabled(PsiElement element) { + DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); - BaseComponent component = element.getProject().getComponent(annotation.value()); - if (component instanceof StateComponentInterface) { - return ((StateComponentInterface) component).isEnabled(); - } + BaseComponent component = element.getProject().getComponent(annotation.value()); + if (component instanceof StateComponentInterface) { + return ((StateComponentInterface) component).isEnabled(); + } - return false; - } + return false; + } - protected abstract void addCompletionsFor(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet); + protected abstract void addCompletionsFor(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericMethodArgumentCompletionProvider.java b/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericMethodArgumentCompletionProvider.java index 7cdc8f8..8d6b68b 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericMethodArgumentCompletionProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/completion/GenericMethodArgumentCompletionProvider.java @@ -21,29 +21,29 @@ */ public abstract class GenericMethodArgumentCompletionProvider extends CompletionProvider { - @Override - protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { - MethodReference method = PsiTreeUtil.getParentOfType(parameters.getPosition(), MethodReference.class); - if (method == null || !isEnabled(method)) { - return; - } - - RequireMethod methodAnnotation = this.getClass().getAnnotation(RequireMethod.class); - if (methodAnnotation != null && !methodAnnotation.value().equalsIgnoreCase(method.getName())) { - return; - } - - for (String item : getCompletions(method)) { - completionResultSet.addElement(new SimpleTextLookup(item)); - } - } - - protected boolean isEnabled(PsiElement element) { - DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); - BaseComponent component = element.getProject().getComponent(annotation.value()); - - return ((StateComponentInterface) component).isEnabled(); - } - - protected abstract List getCompletions(MethodReference method); + @Override + protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { + MethodReference method = PsiTreeUtil.getParentOfType(parameters.getPosition(), MethodReference.class); + if (method == null || !isEnabled(method)) { + return; + } + + RequireMethod methodAnnotation = this.getClass().getAnnotation(RequireMethod.class); + if (methodAnnotation != null && !methodAnnotation.value().equalsIgnoreCase(method.getName())) { + return; + } + + for (String item : getCompletions(method)) { + completionResultSet.addElement(new SimpleTextLookup(item)); + } + } + + protected boolean isEnabled(PsiElement element) { + DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); + BaseComponent component = element.getProject().getComponent(annotation.value()); + + return ((StateComponentInterface) component).isEnabled(); + } + + protected abstract List getCompletions(MethodReference method); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlCompletionProvider.java b/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlCompletionProvider.java index b91ac87..b9b1e12 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlCompletionProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlCompletionProvider.java @@ -14,13 +14,13 @@ */ public class YamlCompletionProvider extends CompletionProvider { - private ArrayList lookupElements; + private ArrayList lookupElements; - YamlCompletionProvider(ArrayList lookups) { - lookupElements = lookups; - } + YamlCompletionProvider(ArrayList lookups) { + lookupElements = lookups; + } - public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { - resultSet.addAllElements(lookupElements); - } + public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { + resultSet.addAllElements(lookupElements); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlElementPatternHelper.java b/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlElementPatternHelper.java index ec98dcf..10d7ae9 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlElementPatternHelper.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/completion/YamlElementPatternHelper.java @@ -17,374 +17,374 @@ */ public class YamlElementPatternHelper { - /** - * auto complete on - *

- * keyName: refer| - * - * @param keyName - */ - public static ElementPattern getOrmSingleLineScalarKey(String keyName) { - return getKeyPattern(keyName).inFile(getOrmFilePattern()).withLanguage(YAMLLanguage.INSTANCE); - } + /** + * auto complete on + *

+ * keyName: refer| + * + * @param keyName + */ + public static ElementPattern getOrmSingleLineScalarKey(String keyName) { + return getKeyPattern(keyName).inFile(getOrmFilePattern()).withLanguage(YAMLLanguage.INSTANCE); + } - public static ElementPattern getSingleLineScalarKey(String... keyName) { - // key: | and key: "quote" is valid here - // getKeyPattern - return PlatformPatterns.or( - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().oneOf(keyName) - ) - ) - .withLanguage(YAMLLanguage.INSTANCE) - , - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_DSTRING) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().oneOf(keyName) - ) - ) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + public static ElementPattern getSingleLineScalarKey(String... keyName) { + // key: | and key: "quote" is valid here + // getKeyPattern + return PlatformPatterns.or( + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().oneOf(keyName) + ) + ) + .withLanguage(YAMLLanguage.INSTANCE) + , + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_DSTRING) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().oneOf(keyName) + ) + ) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - /** - * provides auto complete on - *

- * keyName: - * refer| - * refer|: xxx - * refer| - * - * @param keyName key name - */ - public static ElementPattern getOrmParentLookup(String keyName) { - return PlatformPatterns.or( - // match - // - // keyName: - // refer|: xxx - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_KEY) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().equalTo(keyName) - ) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + /** + * provides auto complete on + *

+ * keyName: + * refer| + * refer|: xxx + * refer| + * + * @param keyName key name + */ + public static ElementPattern getOrmParentLookup(String keyName) { + return PlatformPatterns.or( + // match + // + // keyName: + // refer|: xxx + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_KEY) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().equalTo(keyName) + ) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // keyName: - // xxx: xxx - // refer| - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().equalTo(keyName) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + // match + // + // keyName: + // xxx: xxx + // refer| + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().equalTo(keyName) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // keyName: - // refer| - // xxx: xxx - getKeyPattern(keyName) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + // match + // + // keyName: + // refer| + // xxx: xxx + getKeyPattern(keyName) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - /** - * provides auto complete on - *

- * xxx: - * refer| - * refer|: xxx - * refer| - */ - public static ElementPattern getOrmRoot() { - return PlatformPatterns.or( + /** + * provides auto complete on + *

+ * xxx: + * refer| + * refer|: xxx + * refer| + */ + public static ElementPattern getOrmRoot() { + return PlatformPatterns.or( - // match - // - // xxx: - // refer|: xxx - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_KEY) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLDocument.class) - ) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + // match + // + // xxx: + // refer|: xxx + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_KEY) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLDocument.class) + ) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // xxx: - // xxx: xxx - // refer| - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLDocument.class) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + // match + // + // xxx: + // xxx: xxx + // refer| + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLDocument.class) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // xxx: - // refer| - // xxx: xxx - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLDocument.class) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + // match + // + // xxx: + // refer| + // xxx: xxx + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLDocument.class) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - /** - * provides auto complete on - *

- * tree: - * xxx: - * refer| - * refer|: xxx - * refer| - */ - public static ElementPattern getFilterOnPrevParent(String... tree) { - return PlatformPatterns.or( + /** + * provides auto complete on + *

+ * tree: + * xxx: + * refer| + * refer|: xxx + * refer| + */ + public static ElementPattern getFilterOnPrevParent(String... tree) { + return PlatformPatterns.or( - // match - // - // tree: - // xxx: - // refer|: xxx - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_KEY) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName(PlatformPatterns - .string().oneOfIgnoreCase(tree) - ) - ) - ) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + // match + // + // tree: + // xxx: + // refer|: xxx + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_KEY) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName(PlatformPatterns + .string().oneOfIgnoreCase(tree) + ) + ) + ) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // tree: - // xxx: - // xxx: xxx - // refer| - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName(PlatformPatterns - .string().oneOfIgnoreCase(tree) - ) - ) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE), + // match + // + // tree: + // xxx: + // xxx: xxx + // refer| + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName(PlatformPatterns + .string().oneOfIgnoreCase(tree) + ) + ) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE), - // match - // - // tree: - // xxx: - // refer| - // xxx: xxx - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName(PlatformPatterns - .string().oneOfIgnoreCase(tree) - ) - ) - ) - ) - .inFile(getOrmFilePattern()) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + // match + // + // tree: + // xxx: + // refer| + // xxx: xxx + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName(PlatformPatterns + .string().oneOfIgnoreCase(tree) + ) + ) + ) + ) + .inFile(getOrmFilePattern()) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - /** - * find common services - */ - public static ElementPattern getServiceDefinition() { + /** + * find common services + */ + public static ElementPattern getServiceDefinition() { - return PlatformPatterns.or( - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withText( - StandardPatterns.string().startsWith("@") - ) - .withLanguage(YAMLLanguage.INSTANCE) - , - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_DSTRING) - .withText( - StandardPatterns.string().startsWith("'@") - ) - .withLanguage(YAMLLanguage.INSTANCE), - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_DSTRING) - .withText( - StandardPatterns.string().startsWith("\"@") - ) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + return PlatformPatterns.or( + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withText( + StandardPatterns.string().startsWith("@") + ) + .withLanguage(YAMLLanguage.INSTANCE) + , + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_DSTRING) + .withText( + StandardPatterns.string().startsWith("'@") + ) + .withLanguage(YAMLLanguage.INSTANCE), + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_DSTRING) + .withText( + StandardPatterns.string().startsWith("\"@") + ) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - /** - * find common service parameter - */ - public static ElementPattern getServiceParameterDefinition() { - return PlatformPatterns.or( - PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withText( - StandardPatterns.string().startsWith("%") - ) - .withLanguage(YAMLLanguage.INSTANCE) - , - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_DSTRING) - .withText( - StandardPatterns.string().startsWith("'%") - ) - .withLanguage(YAMLLanguage.INSTANCE), - PlatformPatterns - .psiElement(YAMLTokenTypes.SCALAR_DSTRING) - .withText( - StandardPatterns.string().startsWith("\"%") - ) - .withLanguage(YAMLLanguage.INSTANCE) - ); - } + /** + * find common service parameter + */ + public static ElementPattern getServiceParameterDefinition() { + return PlatformPatterns.or( + PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withText( + StandardPatterns.string().startsWith("%") + ) + .withLanguage(YAMLLanguage.INSTANCE) + , + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_DSTRING) + .withText( + StandardPatterns.string().startsWith("'%") + ) + .withLanguage(YAMLLanguage.INSTANCE), + PlatformPatterns + .psiElement(YAMLTokenTypes.SCALAR_DSTRING) + .withText( + StandardPatterns.string().startsWith("\"%") + ) + .withLanguage(YAMLLanguage.INSTANCE) + ); + } - private static ElementPattern getOrmFilePattern() { - return PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith("orm.yml")); - } + private static ElementPattern getOrmFilePattern() { + return PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith("orm.yml")); + } - private static PsiElementPattern.Capture getKeyPattern(String keyName) { - return PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().equalTo(keyName) - ) - ); - } + private static PsiElementPattern.Capture getKeyPattern(String keyName) { + return PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().equalTo(keyName) + ) + ); + } - /** - * parameters: - * foo.example.class: | - */ - static PsiElementPattern.Capture getParameterClassPattern() { - return PlatformPatterns - .psiElement(YAMLTokenTypes.TEXT) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().endsWith(".class") - ) - .withParent(PlatformPatterns - .psiElement(YAMLElementTypes.COMPOUND_VALUE) - .withParent(PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName("parameters") - ) - ) - ); + /** + * parameters: + * foo.example.class: | + */ + static PsiElementPattern.Capture getParameterClassPattern() { + return PlatformPatterns + .psiElement(YAMLTokenTypes.TEXT) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().endsWith(".class") + ) + .withParent(PlatformPatterns + .psiElement(YAMLElementTypes.COMPOUND_VALUE) + .withParent(PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName("parameters") + ) + ) + ); - } + } - static PsiElementPattern.Capture getInsideServiceKeyPattern() { - return getInsideKeyValue("services", "parameters"); - } + static PsiElementPattern.Capture getInsideServiceKeyPattern() { + return getInsideKeyValue("services", "parameters"); + } - static PsiElementPattern.Capture getInsideKeyValue(String... keys) { - return PlatformPatterns - .psiElement() - .inside( - PlatformPatterns - .psiElement(YAMLKeyValue.class) - .withName( - PlatformPatterns.string().oneOf(keys) - ) - ); - } + static PsiElementPattern.Capture getInsideKeyValue(String... keys) { + return PlatformPatterns + .psiElement() + .inside( + PlatformPatterns + .psiElement(YAMLKeyValue.class) + .withName( + PlatformPatterns.string().oneOf(keys) + ) + ); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/inspection/GenericMethodParameterInspection.java b/src/pl/projectspace/idea/plugins/commons/php/code/inspection/GenericMethodParameterInspection.java index 79533e1..866898a 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/inspection/GenericMethodParameterInspection.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/inspection/GenericMethodParameterInspection.java @@ -18,61 +18,61 @@ */ public abstract class GenericMethodParameterInspection extends LocalInspectionTool { - @NotNull - @Override - public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { - return new MethodParameterVisitor(holder); - } + @NotNull + @Override + public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { + return new MethodParameterVisitor(holder); + } - public final class MethodParameterVisitor extends PhpElementVisitor { + protected abstract MethodDecorator createDecoratedMethod(MethodReference reference) throws MissingElementException, InvalidArgumentException; - private ProblemsHolder holder; + protected abstract void registerProblem(ProblemsHolder holder, MethodDecorator element); - public MethodParameterVisitor(ProblemsHolder holder) { - this.holder = holder; - } + protected boolean isEnabled(MethodReference methodReference) { + RequireMethod methodAnnotation = getClass().getAnnotation(RequireMethod.class); + if (methodAnnotation == null || !methodAnnotation.value().equalsIgnoreCase(methodReference.getName())) { + return false; + } - @Override - public void visitPhpMethodReference(MethodReference methodReference) { + DependsOnPlugin pluginAnnotation = getClass().getAnnotation(DependsOnPlugin.class); + if (pluginAnnotation == null || !((StateComponentInterface) methodReference.getProject().getComponent(pluginAnnotation.value())).isEnabled()) { + return false; + } - if (!isEnabled(methodReference)) { - return; - } + return true; + } - MethodDecorator method = null; - try { - method = createDecoratedMethod(methodReference); + public final class MethodParameterVisitor extends PhpElementVisitor { - if (method.isResolvableToType()) { - return; - } - } catch (MissingElementException e) { - } catch (InvalidArgumentException e) { - } + private ProblemsHolder holder; - if (method != null) { - registerProblem(holder, method); - } - } + public MethodParameterVisitor(ProblemsHolder holder) { + this.holder = holder; + } - } + @Override + public void visitPhpMethodReference(MethodReference methodReference) { - protected abstract MethodDecorator createDecoratedMethod(MethodReference reference) throws MissingElementException, InvalidArgumentException; + if (!isEnabled(methodReference)) { + return; + } - protected abstract void registerProblem(ProblemsHolder holder, MethodDecorator element); + MethodDecorator method = null; + try { + method = createDecoratedMethod(methodReference); - protected boolean isEnabled(MethodReference methodReference) { - RequireMethod methodAnnotation = getClass().getAnnotation(RequireMethod.class); - if (methodAnnotation == null || !methodAnnotation.value().equalsIgnoreCase(methodReference.getName())) { - return false; - } + if (method.isResolvableToType()) { + return; + } + } catch (MissingElementException e) { + } catch (InvalidArgumentException e) { + } - DependsOnPlugin pluginAnnotation = getClass().getAnnotation(DependsOnPlugin.class); - if (pluginAnnotation == null || !((StateComponentInterface) methodReference.getProject().getComponent(pluginAnnotation.value())).isEnabled()) { - return false; - } + if (method != null) { + registerProblem(holder, method); + } + } - return true; - } + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/inspection/PhpClassInspection.java b/src/pl/projectspace/idea/plugins/commons/php/code/inspection/PhpClassInspection.java index 9145071..e99de47 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/inspection/PhpClassInspection.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/inspection/PhpClassInspection.java @@ -11,20 +11,20 @@ public abstract class PhpClassInspection extends LocalInspectionTool { - @NotNull - @Override - public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { - DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); + @NotNull + @Override + public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { + DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); - BaseComponent component = holder.getProject().getComponent(annotation.value()); - if (component instanceof StateComponentInterface) { - if (((StateComponentInterface) component).isEnabled()) { - return getVisitor(holder); - } - } + BaseComponent component = holder.getProject().getComponent(annotation.value()); + if (component instanceof StateComponentInterface) { + if (((StateComponentInterface) component).isEnabled()) { + return getVisitor(holder); + } + } - return new DummyPhpElementVisitor(); - } + return new DummyPhpElementVisitor(); + } - protected abstract PhpElementVisitor getVisitor(@NotNull ProblemsHolder holder); + protected abstract PhpElementVisitor getVisitor(@NotNull ProblemsHolder holder); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/locator/GenericObjectLocator.java b/src/pl/projectspace/idea/plugins/commons/php/code/locator/GenericObjectLocator.java index d51113b..f20d8ff 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/locator/GenericObjectLocator.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/locator/GenericObjectLocator.java @@ -7,9 +7,9 @@ */ abstract public class GenericObjectLocator implements ObjectLocatorInterface { - protected PhpIndex index; + protected PhpIndex index; - public GenericObjectLocator(PhpIndex index) { - this.index = index; - } + public GenericObjectLocator(PhpIndex index) { + this.index = index; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/locator/ObjectLocatorInterface.java b/src/pl/projectspace/idea/plugins/commons/php/code/locator/ObjectLocatorInterface.java index c2e224c..927a2f0 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/locator/ObjectLocatorInterface.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/locator/ObjectLocatorInterface.java @@ -7,6 +7,6 @@ */ public interface ObjectLocatorInterface { - public T locate(String name) throws MissingElementException; + public T locate(String name) throws MissingElementException; } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericMethodCallTypeProvider.java b/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericMethodCallTypeProvider.java index 0db78be..5e67fa8 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericMethodCallTypeProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericMethodCallTypeProvider.java @@ -1,51 +1,41 @@ package pl.projectspace.idea.plugins.commons.php.code.type; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.jetbrains.php.lang.psi.elements.MethodReference; import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.jetbrains.php.lang.psi.elements.PhpNamedElement; -import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2; import org.jetbrains.annotations.Nullable; -import pl.projectspace.idea.plugins.commons.php.psi.PsiTreeUtils; import pl.projectspace.idea.plugins.commons.php.psi.element.MethodDecorator; -import pl.projectspace.idea.plugins.commons.php.psi.element.PhpClassDecorator; import pl.projectspace.idea.plugins.commons.php.psi.element.PsiElementDecorator; import pl.projectspace.idea.plugins.commons.php.psi.exceptions.InvalidArgumentException; import pl.projectspace.idea.plugins.commons.php.psi.exceptions.MissingElementException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - /** * @author Michal Przytulski */ public abstract class GenericMethodCallTypeProvider extends GenericTypeProvider { - @Nullable - @Override - public String getTypeFor(PsiElement element) { - if (DumbService.isDumb(element.getProject()) || !(element instanceof MethodReference)) { - return null; - } - - try { - MethodDecorator method = (MethodDecorator) getMethod((MethodReference) element); - - if (!(((PsiElementDecorator) method.getReturnType()).getDecoratedObject() instanceof PhpClass)) { - return null; - } - - return method.getReturnType().toString(); - } catch (InvalidArgumentException e) { - return null; - } catch (MissingElementException e) { - return null; - } - } - - protected abstract Object getMethod(MethodReference method) throws InvalidArgumentException, MissingElementException; + @Nullable + @Override + public String getTypeFor(PsiElement element) { + if (DumbService.isDumb(element.getProject()) || !(element instanceof MethodReference)) { + return null; + } + + try { + MethodDecorator method = (MethodDecorator) getMethod((MethodReference) element); + + if (!(((PsiElementDecorator) method.getReturnType()).getDecoratedObject() instanceof PhpClass)) { + return null; + } + + return method.getReturnType().toString(); + } catch (InvalidArgumentException e) { + return null; + } catch (MissingElementException e) { + return null; + } + } + + protected abstract Object getMethod(MethodReference method) throws InvalidArgumentException, MissingElementException; } diff --git a/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericTypeProvider.java b/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericTypeProvider.java index 00ae994..7c32685 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericTypeProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/code/type/GenericTypeProvider.java @@ -9,7 +9,6 @@ import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2; import org.jetbrains.annotations.Nullable; import pl.projectspace.idea.plugins.commons.php.StateComponentInterface; -import pl.projectspace.idea.plugins.commons.php.code.inspection.DummyPhpElementVisitor; import pl.projectspace.idea.plugins.commons.php.psi.PsiTreeUtils; import pl.projectspace.idea.plugins.commons.php.utils.annotation.DependsOnPlugin; @@ -22,54 +21,54 @@ */ public abstract class GenericTypeProvider implements PhpTypeProvider2 { - @Override - public char getKey() { - return 192; - } - - /** - * Return context instance for given expression - FQN - * - * @param expression - * @param project - * @return - */ - @Override - public Collection getBySignature(String expression, Project project) { + @Override + public char getKey() { + return 192; + } + + /** + * Return context instance for given expression - FQN + * + * @param expression + * @param project + * @return + */ + @Override + public Collection getBySignature(String expression, Project project) { PsiTreeUtils obj = ServiceManager.getService(project, PsiTreeUtils.class); - if ( obj == null ) { + if (obj == null) { return Collections.emptyList(); } - PhpClass phpClass = obj.getClassByFQN(expression); + PhpClass phpClass = obj.getClassByFQN(expression); - if (phpClass == null) { - return Collections.emptyList(); - } + if (phpClass == null) { + return Collections.emptyList(); + } - return Arrays.asList(phpClass); - } + return Arrays.asList(phpClass); + } - @Nullable - @Override - public String getType(PsiElement element) { + @Nullable + @Override + public String getType(PsiElement element) { - return getTypeFor(element); - } + return getTypeFor(element); + } - protected boolean isEnabled(PsiElement element) { - DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); + protected boolean isEnabled(PsiElement element) { + DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); - BaseComponent component = element.getProject().getComponent(annotation.value()); - if (component instanceof StateComponentInterface) { - return ((StateComponentInterface) component).isEnabled(); - } + BaseComponent component = element.getProject().getComponent(annotation.value()); + if (component instanceof StateComponentInterface) { + return ((StateComponentInterface) component).isEnabled(); + } - return false; - } + return false; + } - protected abstract String getTypeFor(PsiElement psiElement); + protected abstract String getTypeFor(PsiElement psiElement); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/Composer.java b/src/pl/projectspace/idea/plugins/commons/php/composer/Composer.java index e0f8d9f..22233cd 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/Composer.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/Composer.java @@ -9,57 +9,51 @@ */ public class Composer { - private String path; - - enum Type { - LIBRARY, - PROJECT, - METAPACKAGE, - COMPOSER_INSTALLER - } - - private String configFile; - - private String name; - private String description; - private String version; - private Type type; - private String keywords; - private String homepage; - private String license; - - private Configuration config = new Configuration(); - - - @SerializedName("minimum-stability") - private String minimumStability; - - private Require require; - - public Composer() { - - } - - public void setFile(String path) { - this.path = path; - } - - public Collection getRequiredPackages() { - return require.getCollection(); - } - - public boolean isRequired(String packageName) { - return require.hasPackage(packageName); - } - - public String getMinimumStability() { - return minimumStability; - } + private String path; + private String configFile; + private String name; + private String description; + private String version; + private Type type; + private String keywords; + private String homepage; + private String license; + private Configuration config = new Configuration(); + @SerializedName("minimum-stability") + private String minimumStability; + private Require require; + + public Composer() { + + } + + public void setFile(String path) { + this.path = path; + } + + public Collection getRequiredPackages() { + return require.getCollection(); + } + + public boolean isRequired(String packageName) { + return require.hasPackage(packageName); + } + + public String getMinimumStability() { + return minimumStability; + } + + public Configuration getConfig() { + return config; + } // public String get - public Configuration getConfig() { - return config; - } + enum Type { + LIBRARY, + PROJECT, + METAPACKAGE, + COMPOSER_INSTALLER + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/Configuration.java b/src/pl/projectspace/idea/plugins/commons/php/composer/Configuration.java index b8967a1..4b2e4c5 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/Configuration.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/Configuration.java @@ -7,18 +7,18 @@ */ public class Configuration { - private HashMapvalues = new HashMap(); + private HashMap values = new HashMap(); - public void set(String key, String value) { - values.put(key, value); - } + public void set(String key, String value) { + values.put(key, value); + } - public String getBinDir() { - if (!values.containsKey("bin-dir")) { - return "vendor/bin"; - } + public String getBinDir() { + if (!values.containsKey("bin-dir")) { + return "vendor/bin"; + } - return values.get("bin-dir"); - } + return values.get("bin-dir"); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/File.java b/src/pl/projectspace/idea/plugins/commons/php/composer/File.java index cdea4b6..3cb4b99 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/File.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/File.java @@ -13,31 +13,31 @@ */ public class File { - private final String path; + private final String path; - public File(String path) { - this.path = path; - } + public File(String path) { + this.path = path; + } - public Composer parse() { - try { - InputStreamReader is = new InputStreamReader( - new FileInputStream(this.path) - ); + public Composer parse() { + try { + InputStreamReader is = new InputStreamReader( + new FileInputStream(this.path) + ); - GsonBuilder gson = new GsonBuilder(); - gson.registerTypeAdapter(Require.class, new RequireConverter()); + GsonBuilder gson = new GsonBuilder(); + gson.registerTypeAdapter(Require.class, new RequireConverter()); - Gson parser = gson.create(); + Gson parser = gson.create(); - Composer composer = parser.fromJson(is, Composer.class); - composer.setFile(this.path); + Composer composer = parser.fromJson(is, Composer.class); + composer.setFile(this.path); - return composer; - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } + return composer; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/Package.java b/src/pl/projectspace/idea/plugins/commons/php/composer/Package.java index 9d7784e..2cb4394 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/Package.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/Package.java @@ -5,23 +5,23 @@ */ public class Package { - private String name; - private String version; + private String name; + private String version; - public Package() { - } + public Package() { + } - public Package(String name, String version) { - this.name = name; - this.version = version; - } + public Package(String name, String version) { + this.name = name; + this.version = version; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/Require.java b/src/pl/projectspace/idea/plugins/commons/php/composer/Require.java index 30fc2ed..09eac1a 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/Require.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/Require.java @@ -7,21 +7,21 @@ * @author Michal Przytulski */ public class Require { - private HashMap packages = new HashMap(); + private HashMap packages = new HashMap(); - public void addPackage(Package p) { - packages.put(p.getName(), p); - } + public void addPackage(Package p) { + packages.put(p.getName(), p); + } - public Package getPackage(String packageName) { - return packages.get(packageName); - } + public Package getPackage(String packageName) { + return packages.get(packageName); + } - public boolean hasPackage(String packageName) { - return packages.containsKey(packageName); - } + public boolean hasPackage(String packageName) { + return packages.containsKey(packageName); + } - public Collection getCollection() { - return packages.values(); - } + public Collection getCollection() { + return packages.values(); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/ConfigurationConverter.java b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/ConfigurationConverter.java index e8ebc0a..e11efbe 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/ConfigurationConverter.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/ConfigurationConverter.java @@ -1,6 +1,9 @@ package pl.projectspace.idea.plugins.commons.php.composer.converter; -import com.google.gson.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; import pl.projectspace.idea.plugins.commons.php.composer.Configuration; import java.lang.reflect.Type; @@ -10,14 +13,14 @@ * @author Michal Przytulski */ public class ConfigurationConverter implements JsonDeserializer { - @Override - public Configuration deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - Configuration config = new Configuration(); + @Override + public Configuration deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + Configuration config = new Configuration(); - for (Map.Entryelement : jsonElement.getAsJsonObject().entrySet()) { - config.set(element.getKey(), element.getValue().getAsString()); - } + for (Map.Entry element : jsonElement.getAsJsonObject().entrySet()) { + config.set(element.getKey(), element.getValue().getAsString()); + } - return config; - } + return config; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/PackageConverter.java b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/PackageConverter.java index 519bcf2..a0057e3 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/PackageConverter.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/PackageConverter.java @@ -11,8 +11,8 @@ * @author Michal Przytulski */ public class PackageConverter implements JsonDeserializer { - @Override - public pl.projectspace.idea.plugins.commons.php.composer.Package deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - return new pl.projectspace.idea.plugins.commons.php.composer.Package(); - } + @Override + public pl.projectspace.idea.plugins.commons.php.composer.Package deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + return new pl.projectspace.idea.plugins.commons.php.composer.Package(); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/RequireConverter.java b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/RequireConverter.java index d007c08..98c5de2 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/composer/converter/RequireConverter.java +++ b/src/pl/projectspace/idea/plugins/commons/php/composer/converter/RequireConverter.java @@ -1,8 +1,11 @@ package pl.projectspace.idea.plugins.commons.php.composer.converter; -import com.google.gson.*; -import pl.projectspace.idea.plugins.commons.php.composer.*; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; import pl.projectspace.idea.plugins.commons.php.composer.Package; +import pl.projectspace.idea.plugins.commons.php.composer.Require; import java.lang.reflect.Type; import java.util.Map; @@ -10,15 +13,15 @@ /** * @author Michal Przytulski */ -public class RequireConverter implements JsonDeserializer { - @Override - public Require deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - Require require = new Require(); +public class RequireConverter implements JsonDeserializer { + @Override + public Require deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + Require require = new Require(); - for (Map.Entryelement : jsonElement.getAsJsonObject().entrySet()) { - require.addPackage(new Package(element.getKey(), element.getValue().getAsString())); - } + for (Map.Entry element : jsonElement.getAsJsonObject().entrySet()) { + require.addPackage(new Package(element.getKey(), element.getValue().getAsString())); + } - return require; - } + return require; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/PsiTreeUtils.java b/src/pl/projectspace/idea/plugins/commons/php/psi/PsiTreeUtils.java index cb0b56c..6b7b7bd 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/PsiTreeUtils.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/PsiTreeUtils.java @@ -20,82 +20,82 @@ */ public class PsiTreeUtils { - private Project project; - private PhpIndex index; + private Project project; + private PhpIndex index; - public PsiTreeUtils(Project project, PhpIndex index) { - this.project = project; - this.index = index; - } + public PsiTreeUtils(Project project, PhpIndex index) { + this.project = project; + this.index = index; + } - /** - * Return first PhpClass instance from index based on FQN of this class - * - * @param fqn - * @return - */ - public PhpClass getClassByFQN(final String fqn, List excludedNamespaces) { - Collection result = index.getClassesByFQN(fqn); - if (!result.isEmpty()) { - PhpClass phpClass = null; - while ((phpClass = result.iterator().next()) != null) { + /** + * Return first PhpClass instance from index based on FQN of this class + * + * @param fqn + * @return + */ + public PhpClass getClassByFQN(final String fqn, List excludedNamespaces) { + Collection result = index.getClassesByFQN(fqn); + if (!result.isEmpty()) { + PhpClass phpClass = null; + while ((phpClass = result.iterator().next()) != null) { // for (String ns : excludedNamespaces) { // if (!phpClass.getNamespaceName().startsWith(ns)) { - return phpClass; + return phpClass; // } // } - } - } + } + } - return null; - } + return null; + } - public PhpClass getClassByFQN(final String fqn) { - return getClassByFQN(fqn, new ArrayList()); - } + public PhpClass getClassByFQN(final String fqn) { + return getClassByFQN(fqn, new ArrayList()); + } - /** - * Return PhpClass instance based on given PhpMethodReference expression. - * - * This method will resolve class reference to find type of response and will return PhpClass based on class name - * stored in type - * - * @param expression - * @return - */ - public PhpClass getClass(MethodReference expression, List excludedNamespaces) { + /** + * Return PhpClass instance based on given PhpMethodReference expression. + *

+ * This method will resolve class reference to find type of response and will return PhpClass based on class name + * stored in type + * + * @param expression + * @return + */ + public PhpClass getClass(MethodReference expression, List excludedNamespaces) { // || !expression.getClassReference().getType().equals(PhpType.OBJECT) - // @todo - better check if given expression belongs to proper calls - if (expression == null || expression.getClassReference() == null) { - return null; - } + // @todo - better check if given expression belongs to proper calls + if (expression == null || expression.getClassReference() == null) { + return null; + } - Pattern pattern = Pattern.compile("^([^\\\\]*)([\\\\a-zA-Z_0-9]*)(.*)$"); - Matcher matcher = pattern.matcher(expression.getClassReference().getType().toString()); + Pattern pattern = Pattern.compile("^([^\\\\]*)([\\\\a-zA-Z_0-9]*)(.*)$"); + Matcher matcher = pattern.matcher(expression.getClassReference().getType().toString()); - if (matcher.matches() && matcher.groupCount() == 3) { - return getClassByFQN(matcher.group(2), excludedNamespaces); - } + if (matcher.matches() && matcher.groupCount() == 3) { + return getClassByFQN(matcher.group(2), excludedNamespaces); + } - return null; - } + return null; + } - /** - * Return class for given PhpMethodReference expression (resolving reference) - * - * @param expression - * @return - */ - public PhpClass getClass(MethodReference expression) { - return getClass(expression, new LinkedList()); - } + /** + * Return class for given PhpMethodReference expression (resolving reference) + * + * @param expression + * @return + */ + public PhpClass getClass(MethodReference expression) { + return getClass(expression, new LinkedList()); + } - public PhpClass getClass(PsiElement element) throws MissingElementException { - PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class); - if (phpClass == null) { - throw new MissingElementException("Missing PhpClass as a parent for "); - } + public PhpClass getClass(PsiElement element) throws MissingElementException { + PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class); + if (phpClass == null) { + throw new MissingElementException("Missing PhpClass as a parent for "); + } - return phpClass; - } + return phpClass; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/element/MethodDecorator.java b/src/pl/projectspace/idea/plugins/commons/php/psi/element/MethodDecorator.java index 8d33bab..595a951 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/element/MethodDecorator.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/element/MethodDecorator.java @@ -12,56 +12,54 @@ */ public abstract class MethodDecorator { - protected PhpClass target; - - protected final MethodReference element; - - protected Object returnType = null; - - public MethodDecorator(PsiElement element) throws InvalidArgumentException { - if (!(element instanceof MethodReference)) { - throw new InvalidArgumentException("Passed PsiElement should be an instance of MethodReference"); - } - - this.element = (MethodReference) element; - } - - public PhpClass getTarget() { - if (target == null) { - target = PsiTreeUtil.getParentOfType(element, PhpClass.class); - } - - return target; - } - - public boolean hasParameter(int no) { - return (element.getParameters().length > no); - } - - public boolean hasParameter(int no, Class type) { - return (hasParameter(no) && type.isAssignableFrom(element.getParameters()[no].getClass())); - } - - public PsiElement getParameter(int no) { - return element.getParameters()[no]; - } - - public boolean isResolvableToType() { - try { - return (getReturnType() != null); - } catch (MissingElementException e) { - return false; - } - } - - public Object getReturnType() throws MissingElementException { - if (returnType == null) { - returnType = resolveType(); - } - - return returnType; - } - - protected abstract Object resolveType() throws MissingElementException; + protected final MethodReference element; + protected PhpClass target; + protected Object returnType = null; + + public MethodDecorator(PsiElement element) throws InvalidArgumentException { + if (!(element instanceof MethodReference)) { + throw new InvalidArgumentException("Passed PsiElement should be an instance of MethodReference"); + } + + this.element = (MethodReference) element; + } + + public PhpClass getTarget() { + if (target == null) { + target = PsiTreeUtil.getParentOfType(element, PhpClass.class); + } + + return target; + } + + public boolean hasParameter(int no) { + return (element.getParameters().length > no); + } + + public boolean hasParameter(int no, Class type) { + return (hasParameter(no) && type.isAssignableFrom(element.getParameters()[no].getClass())); + } + + public PsiElement getParameter(int no) { + return element.getParameters()[no]; + } + + public boolean isResolvableToType() { + try { + return (getReturnType() != null); + } catch (MissingElementException e) { + return false; + } + } + + public Object getReturnType() throws MissingElementException { + if (returnType == null) { + returnType = resolveType(); + } + + return returnType; + } + + protected abstract Object resolveType() throws MissingElementException; } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PhpClassDecorator.java b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PhpClassDecorator.java index 3ffe50e..d96d163 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PhpClassDecorator.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PhpClassDecorator.java @@ -8,35 +8,35 @@ */ public abstract class PhpClassDecorator extends PsiElementDecorator { - /** - * Create PhpClass decorator - * - * @param phpClass - */ - public PhpClassDecorator(PhpClass phpClass) { - super(phpClass); - } - - /** - * Get decorated PhpClass instance - * - * @return - */ - public PhpClass getDecoratedObject() { - return (PhpClass) this.element; - } - - public T getService(Class service) { - return getComponent().getService(service); - } - - @Override - public String toString() { - return getDecoratedObject().getFQN(); - } - - public abstract boolean hasRelatedClass(); - - protected abstract ProjectComponent getComponent(); + /** + * Create PhpClass decorator + * + * @param phpClass + */ + public PhpClassDecorator(PhpClass phpClass) { + super(phpClass); + } + + /** + * Get decorated PhpClass instance + * + * @return + */ + public PhpClass getDecoratedObject() { + return (PhpClass) this.element; + } + + public T getService(Class service) { + return getComponent().getService(service); + } + + @Override + public String toString() { + return getDecoratedObject().getFQN(); + } + + public abstract boolean hasRelatedClass(); + + protected abstract ProjectComponent getComponent(); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PluginIconProvider.java b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PluginIconProvider.java index 3504a50..3768161 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PluginIconProvider.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PluginIconProvider.java @@ -12,26 +12,26 @@ import javax.swing.*; public abstract class PluginIconProvider extends IconProvider { - @Nullable - @Override - public Icon getIcon(@NotNull PsiElement psiElement, @Iconable.IconFlags int i) { - if (!isEnabled(psiElement)) { - return null; - } + @Nullable + @Override + public Icon getIcon(@NotNull PsiElement psiElement, @Iconable.IconFlags int i) { + if (!isEnabled(psiElement)) { + return null; + } - return getIconForElement(psiElement, i); - } + return getIconForElement(psiElement, i); + } - protected abstract Icon getIconForElement(@NotNull PsiElement element, @Iconable.IconFlags int i); + protected abstract Icon getIconForElement(@NotNull PsiElement element, @Iconable.IconFlags int i); - private boolean isEnabled(PsiElement psiElement) { - DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); + private boolean isEnabled(PsiElement psiElement) { + DependsOnPlugin annotation = this.getClass().getAnnotation(DependsOnPlugin.class); - BaseComponent component = psiElement.getProject().getComponent(annotation.value()); - if (component instanceof StateComponentInterface) { - return ((StateComponentInterface) component).isEnabled(); - } + BaseComponent component = psiElement.getProject().getComponent(annotation.value()); + if (component instanceof StateComponentInterface) { + return ((StateComponentInterface) component).isEnabled(); + } - return false; - } + return false; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PsiElementDecorator.java b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PsiElementDecorator.java index f5b7e5a..474a4db 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/element/PsiElementDecorator.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/element/PsiElementDecorator.java @@ -7,24 +7,24 @@ */ public abstract class PsiElementDecorator { - protected PsiElement element; + protected PsiElement element; - /** - * Create PhpClass decorator - * - * @param element - */ - public PsiElementDecorator(PsiElement element) { - this.element = element; - } + /** + * Create PhpClass decorator + * + * @param element + */ + public PsiElementDecorator(PsiElement element) { + this.element = element; + } - /** - * Get decorated Element instance - * - * @return - */ - public PsiElement getDecoratedObject() { - return this.element; - } + /** + * Get decorated Element instance + * + * @return + */ + public PsiElement getDecoratedObject() { + return this.element; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidArgumentException.java b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidArgumentException.java index 7c5b85f..51f81b2 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidArgumentException.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidArgumentException.java @@ -4,7 +4,7 @@ * @author Michal Przytulski */ public class InvalidArgumentException extends Exception { - public InvalidArgumentException(String message) { - super(message); - } + public InvalidArgumentException(String message) { + super(message); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodArgumentsException.java b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodArgumentsException.java index 05347bf..55bb3cf 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodArgumentsException.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodArgumentsException.java @@ -4,7 +4,7 @@ * @author Michal Przytulski */ public class InvalidMethodArgumentsException extends InvalidMethodCallException { - public InvalidMethodArgumentsException(String message) { - super(message); - } + public InvalidMethodArgumentsException(String message) { + super(message); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodCallException.java b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodCallException.java index 4c9b80d..7a680d7 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodCallException.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/InvalidMethodCallException.java @@ -4,7 +4,7 @@ * @author Michal Przytulski */ public class InvalidMethodCallException extends Exception { - public InvalidMethodCallException(String message) { - super(message); - } + public InvalidMethodCallException(String message) { + super(message); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/MissingElementException.java b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/MissingElementException.java index c923110..451e7b5 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/MissingElementException.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/MissingElementException.java @@ -4,7 +4,7 @@ * @author Michal Przytulski */ public class MissingElementException extends Exception { - public MissingElementException(String message) { - super(message); - } + public MissingElementException(String message) { + super(message); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/PhpPluginException.java b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/PhpPluginException.java index 1aaa857..45ab9ca 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/PhpPluginException.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/exceptions/PhpPluginException.java @@ -4,7 +4,7 @@ * @author Michal Przytulski */ public class PhpPluginException extends Exception { - public PhpPluginException(String message) { - super(message); - } + public PhpPluginException(String message) { + super(message); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/lookup/SimpleTextLookup.java b/src/pl/projectspace/idea/plugins/commons/php/psi/lookup/SimpleTextLookup.java index c4150e2..768e0d2 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/lookup/SimpleTextLookup.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/lookup/SimpleTextLookup.java @@ -8,15 +8,15 @@ */ public class SimpleTextLookup extends LookupElement { - private String text; + private String text; - public SimpleTextLookup(String text){ - this.text = text; - } + public SimpleTextLookup(String text) { + this.text = text; + } - @NotNull - @Override - public String getLookupString() { - return text; - } + @NotNull + @Override + public String getLookupString() { + return text; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/ArrayElementReference.java b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/ArrayElementReference.java index 3eec968..befa781 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/ArrayElementReference.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/ArrayElementReference.java @@ -16,93 +16,92 @@ */ public class ArrayElementReference implements PsiReference { - private PsiElement reference; - private PsiElement element; + private PsiElement reference; + private PsiElement element; - public ArrayElementReference(PsiElement reference, PsiElement element) - { - this.reference = reference; - this.element = element; - } + public ArrayElementReference(PsiElement reference, PsiElement element) { + this.reference = reference; + this.element = element; + } - /** - * @see com.intellij.psi.PsiReference#getRangeInElement() - * @return the full range incl. quotes. - */ - @Override - public TextRange getRangeInElement() { - return new TextRange(1, this.element.getTextLength() - 1); - } + /** + * @return the full range incl. quotes. + * @see com.intellij.psi.PsiReference#getRangeInElement() + */ + @Override + public TextRange getRangeInElement() { + return new TextRange(1, this.element.getTextLength() - 1); + } - /** - * @see com.intellij.psi.PsiReference#resolve() - * @return the resolved template file or null - */ - @Override - public PsiElement resolve() { - return reference; - } + /** + * @return the resolved template file or null + * @see com.intellij.psi.PsiReference#resolve() + */ + @Override + public PsiElement resolve() { + return reference; + } - /** - * @see com.intellij.psi.PsiReference#getCanonicalText() - * @return Plain text representation. - */ - @NotNull - @Override - public String getCanonicalText() { - return ((StringLiteralExpression)this.element).getContents(); - } + /** + * @return Plain text representation. + * @see com.intellij.psi.PsiReference#getCanonicalText() + */ + @NotNull + @Override + public String getCanonicalText() { + return ((StringLiteralExpression) this.element).getContents(); + } - /** - * @see com.intellij.psi.PsiReference#handleElementRename(String) - * @param newElementName - * @return the new string literal with the new text - * @throws com.intellij.util.IncorrectOperationException - */ - @Override - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - ASTNode node = this.element.getNode(); - StringLiteralExpressionImpl se = new StringLiteralExpressionImpl(node); + /** + * @param newElementName + * @return the new string literal with the new text + * @throws com.intellij.util.IncorrectOperationException + * @see com.intellij.psi.PsiReference#handleElementRename(String) + */ + @Override + public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { + ASTNode node = this.element.getNode(); + StringLiteralExpressionImpl se = new StringLiteralExpressionImpl(node); - String[] parts = this.element.getText().split(":"); - StringBuilder sb = new StringBuilder(parts[0]).append(":").append(parts[1]).append(":"); - sb.append(newElementName); - se.updateText(sb.toString()); - this.element = se; - return this.element; - } + String[] parts = this.element.getText().split(":"); + StringBuilder sb = new StringBuilder(parts[0]).append(":").append(parts[1]).append(":"); + sb.append(newElementName); + se.updateText(sb.toString()); + this.element = se; + return this.element; + } - @Override - public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } + @Override + public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } - @Override - public boolean isReferenceTo(PsiElement element) { - if (element instanceof PhpClass) { - ((PhpClass) element).getName().equals(((StringLiteralExpression)this.element).getContents()); - } - return false; - } + @Override + public boolean isReferenceTo(PsiElement element) { + if (element instanceof PhpClass) { + ((PhpClass) element).getName().equals(((StringLiteralExpression) this.element).getContents()); + } + return false; + } - @NotNull - @Override - public Object[] getVariants() { - return ArrayUtil.EMPTY_OBJECT_ARRAY; - } + @NotNull + @Override + public Object[] getVariants() { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } - @Override - public boolean isSoft() { - return true; - } + @Override + public boolean isSoft() { + return true; + } - /** - * @see com.intellij.psi.PsiReference#getElement() - * @return the full source element - */ - @Override - public PsiElement getElement() { - return element; - } + /** + * @return the full source element + * @see com.intellij.psi.PsiReference#getElement() + */ + @Override + public PsiElement getElement() { + return element; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpClassReference.java b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpClassReference.java index 816113b..961e33e 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpClassReference.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpClassReference.java @@ -16,93 +16,92 @@ */ public class PhpClassReference implements PsiReference { - private PsiElement reference; - private PsiElement element; + private PsiElement reference; + private PsiElement element; - public PhpClassReference(PsiElement reference, PsiElement element) - { - this.reference = reference; - this.element = element; - } + public PhpClassReference(PsiElement reference, PsiElement element) { + this.reference = reference; + this.element = element; + } - /** - * @see com.intellij.psi.PsiReference#getRangeInElement() - * @return the full range incl. quotes. - */ - @Override - public TextRange getRangeInElement() { - return new TextRange(1, this.element.getTextLength() - 1); - } + /** + * @return the full range incl. quotes. + * @see com.intellij.psi.PsiReference#getRangeInElement() + */ + @Override + public TextRange getRangeInElement() { + return new TextRange(1, this.element.getTextLength() - 1); + } - /** - * @see com.intellij.psi.PsiReference#resolve() - * @return the resolved template file or null - */ - @Override - public PsiElement resolve() { - return reference; - } + /** + * @return the resolved template file or null + * @see com.intellij.psi.PsiReference#resolve() + */ + @Override + public PsiElement resolve() { + return reference; + } - /** - * @see com.intellij.psi.PsiReference#getCanonicalText() - * @return Plain text representation. - */ - @NotNull - @Override - public String getCanonicalText() { - return ((StringLiteralExpression)this.element).getContents(); - } + /** + * @return Plain text representation. + * @see com.intellij.psi.PsiReference#getCanonicalText() + */ + @NotNull + @Override + public String getCanonicalText() { + return ((StringLiteralExpression) this.element).getContents(); + } - /** - * @see com.intellij.psi.PsiReference#handleElementRename(String) - * @param newElementName - * @return the new string literal with the new text - * @throws IncorrectOperationException - */ - @Override - public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { - ASTNode node = this.element.getNode(); - StringLiteralExpressionImpl se = new StringLiteralExpressionImpl(node); + /** + * @param newElementName + * @return the new string literal with the new text + * @throws IncorrectOperationException + * @see com.intellij.psi.PsiReference#handleElementRename(String) + */ + @Override + public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException { + ASTNode node = this.element.getNode(); + StringLiteralExpressionImpl se = new StringLiteralExpressionImpl(node); - String[] parts = this.element.getText().split(":"); - StringBuilder sb = new StringBuilder(parts[0]).append(":").append(parts[1]).append(":"); - sb.append(newElementName); - se.updateText(sb.toString()); - this.element = se; - return this.element; - } + String[] parts = this.element.getText().split(":"); + StringBuilder sb = new StringBuilder(parts[0]).append(":").append(parts[1]).append(":"); + sb.append(newElementName); + se.updateText(sb.toString()); + this.element = se; + return this.element; + } - @Override - public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } + @Override + public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } - @Override - public boolean isReferenceTo(PsiElement element) { - if (element instanceof PhpClass) { - ((PhpClass) element).getName().equals(((StringLiteralExpression)this.element).getContents()); - } - return false; - } + @Override + public boolean isReferenceTo(PsiElement element) { + if (element instanceof PhpClass) { + ((PhpClass) element).getName().equals(((StringLiteralExpression) this.element).getContents()); + } + return false; + } - @NotNull - @Override - public Object[] getVariants() { - return ArrayUtil.EMPTY_OBJECT_ARRAY; - } + @NotNull + @Override + public Object[] getVariants() { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } - @Override - public boolean isSoft() { - return true; - } + @Override + public boolean isSoft() { + return true; + } - /** - * @see com.intellij.psi.PsiReference#getElement() - * @return the full source element - */ - @Override - public PsiElement getElement() { - return element; - } + /** + * @return the full source element + * @see com.intellij.psi.PsiReference#getElement() + */ + @Override + public PsiElement getElement() { + return element; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpMethodReference.java b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpMethodReference.java index f3828e4..a20db74 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpMethodReference.java +++ b/src/pl/projectspace/idea/plugins/commons/php/psi/reference/PhpMethodReference.java @@ -14,59 +14,59 @@ */ public class PhpMethodReference implements PsiReference { - protected PsiElement method; - protected PsiElement name; + protected PsiElement method; + protected PsiElement name; - public PhpMethodReference(@NotNull Method method, @NotNull final PsiElement name) { - this.method = method; - this.name = name; - } + public PhpMethodReference(@NotNull Method method, @NotNull final PsiElement name) { + this.method = method; + this.name = name; + } - @Override - public PsiElement getElement() { - return name; - } + @Override + public PsiElement getElement() { + return name; + } - @Override - public TextRange getRangeInElement() { - return new TextRange(1, this.name.getTextLength() - 1); - } + @Override + public TextRange getRangeInElement() { + return new TextRange(1, this.name.getTextLength() - 1); + } - @Nullable - @Override - public PsiElement resolve() { - return method; - } + @Nullable + @Override + public PsiElement resolve() { + return method; + } - @NotNull - @Override - public String getCanonicalText() { - return ((StringLiteralExpression)name).getContents(); - } + @NotNull + @Override + public String getCanonicalText() { + return ((StringLiteralExpression) name).getContents(); + } - @Override - public PsiElement handleElementRename(String s) throws IncorrectOperationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } + @Override + public PsiElement handleElementRename(String s) throws IncorrectOperationException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } - @Override - public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } + @Override + public PsiElement bindToElement(@NotNull PsiElement psiElement) throws IncorrectOperationException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } - @Override - public boolean isReferenceTo(PsiElement psiElement) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } + @Override + public boolean isReferenceTo(PsiElement psiElement) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } - @NotNull - @Override - public Object[] getVariants() { - return new Object[0]; //To change body of implemented methods use File | Settings | File Templates. - } + @NotNull + @Override + public Object[] getVariants() { + return new Object[0]; //To change body of implemented methods use File | Settings | File Templates. + } - @Override - public boolean isSoft() { - return true; - } + @Override + public boolean isSoft() { + return true; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/FileFactory.java b/src/pl/projectspace/idea/plugins/commons/php/utils/FileFactory.java index 2dea4a1..7bc05b9 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/FileFactory.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/FileFactory.java @@ -6,17 +6,13 @@ import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; -import com.intellij.psi.impl.file.impl.FileManager; -import com.intellij.util.IncorrectOperationException; import java.io.IOException; import java.util.Properties; @@ -26,98 +22,97 @@ */ public class FileFactory { - private Project project; - - public FileFactory(Project project) { - this.project = project; - } - - public CreateFileFromTemplateWriteAction getCreateFileFromTemplateWriteAction(VirtualFile dir, String fileName, FileType fileType, String templateName, Properties properties) { - return new CreateFileFromTemplateWriteAction(project, dir, fileName, fileType, templateName, properties); - } - - - public VirtualFile createNamespaceDirectory(final VirtualFile dir, final String namespace) throws IOException { - String[] parts = namespace.replaceAll("^/", "").replaceAll("/$", "").split("/"); - - VirtualFile parentDir = dir; - VirtualFile subDir = null; - - for (int i = 0; i < parts.length; i++) { - subDir = parentDir.findChild(parts[i]); - if (subDir == null) { - parentDir = createSubdirectory(parentDir, parts[i]); - } else { - parentDir = subDir; - } - } - - return parentDir; - } - - private VirtualFile createSubdirectory(final VirtualFile baseDir, final String name) throws IOException { - final VirtualFile[] subDirectory = new VirtualFile[1]; - final IOException[] exception = new IOException[1]; - - CommandProcessor.getInstance().executeCommand(project, new Runnable(){ - public void run() { - subDirectory[0] = ApplicationManager.getApplication().runWriteAction(new Computable() { - public VirtualFile compute() { - try { - return baseDir.createChildDirectory(baseDir, name); - } catch (IOException e) { - exception[0] = e; - } - return null; - } - }); - } - }, IdeBundle.message("command.create.new.subdirectory"), null); - - if (exception[0] != null) throw exception[0]; - - return subDirectory[0]; - } - - private static class CreateFileFromTemplateWriteAction implements Runnable { - - private Project project; - private VirtualFile dir; - private String fileName; - private FileType fileType; - private String templateName; - private Properties properties; - - public CreateFileFromTemplateWriteAction(Project project, VirtualFile dir, String fileName, FileType fileType, String templateName, Properties properties) { - this.project = project; - this.dir = dir; - this.fileName = fileName; - this.fileType = fileType; - this.templateName = templateName; - this.properties = properties; - } - - @Override - public void run() { - final FileTemplate template = FileTemplateManager.getInstance().getJ2eeTemplate(templateName); - - String text; - try { - text = template.getText(properties); - } - catch (Exception e) { - throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e); - } - - final PsiFileFactory factory = PsiFileFactory.getInstance(project); - final PsiFile file = factory.createFileFromText(fileName, fileType, text); - - PsiDirectory directory = file.getManager().findDirectory(dir); - - PsiFile newFile = (PsiFile) directory.add(file); - - OpenFileAction.openFile(newFile.getVirtualFile(), project); - } - } + private Project project; + + public FileFactory(Project project) { + this.project = project; + } + + public CreateFileFromTemplateWriteAction getCreateFileFromTemplateWriteAction(VirtualFile dir, String fileName, FileType fileType, String templateName, Properties properties) { + return new CreateFileFromTemplateWriteAction(project, dir, fileName, fileType, templateName, properties); + } + + + public VirtualFile createNamespaceDirectory(final VirtualFile dir, final String namespace) throws IOException { + String[] parts = namespace.replaceAll("^/", "").replaceAll("/$", "").split("/"); + + VirtualFile parentDir = dir; + VirtualFile subDir = null; + + for (int i = 0; i < parts.length; i++) { + subDir = parentDir.findChild(parts[i]); + if (subDir == null) { + parentDir = createSubdirectory(parentDir, parts[i]); + } else { + parentDir = subDir; + } + } + + return parentDir; + } + + private VirtualFile createSubdirectory(final VirtualFile baseDir, final String name) throws IOException { + final VirtualFile[] subDirectory = new VirtualFile[1]; + final IOException[] exception = new IOException[1]; + + CommandProcessor.getInstance().executeCommand(project, new Runnable() { + public void run() { + subDirectory[0] = ApplicationManager.getApplication().runWriteAction(new Computable() { + public VirtualFile compute() { + try { + return baseDir.createChildDirectory(baseDir, name); + } catch (IOException e) { + exception[0] = e; + } + return null; + } + }); + } + }, IdeBundle.message("command.create.new.subdirectory"), null); + + if (exception[0] != null) throw exception[0]; + + return subDirectory[0]; + } + + private static class CreateFileFromTemplateWriteAction implements Runnable { + + private Project project; + private VirtualFile dir; + private String fileName; + private FileType fileType; + private String templateName; + private Properties properties; + + public CreateFileFromTemplateWriteAction(Project project, VirtualFile dir, String fileName, FileType fileType, String templateName, Properties properties) { + this.project = project; + this.dir = dir; + this.fileName = fileName; + this.fileType = fileType; + this.templateName = templateName; + this.properties = properties; + } + + @Override + public void run() { + final FileTemplate template = FileTemplateManager.getInstance().getJ2eeTemplate(templateName); + + String text; + try { + text = template.getText(properties); + } catch (Exception e) { + throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e); + } + + final PsiFileFactory factory = PsiFileFactory.getInstance(project); + final PsiFile file = factory.createFileFromText(fileName, fileType, text); + + PsiDirectory directory = file.getManager().findDirectory(dir); + + PsiFile newFile = (PsiFile) directory.add(file); + + OpenFileAction.openFile(newFile.getVirtualFile(), project); + } + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/PhpClassUtils.java b/src/pl/projectspace/idea/plugins/commons/php/utils/PhpClassUtils.java index 47b0bf0..92ef631 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/PhpClassUtils.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/PhpClassUtils.java @@ -11,29 +11,29 @@ */ public class PhpClassUtils { - /** - * Check if given Page belongs to project test scope - * - * @param phpClass - * @return - */ - public static boolean isInExcludedNamespace(PhpClass phpClass, List excludedNamespaces) { - return excludedNamespaces.contains(phpClass.getNamespaceName()); - } - - public static String getPSRPathFromClassNamespace(String namespace) { - return namespace.replaceAll("\\\\", "/"); - } - - public static LeafPsiElement getClassNameIdentifierFrom(PhpClass phpClass) { - PsiElement child = phpClass.getFirstChild(); - do { - if (child instanceof LeafPsiElement && ((LeafPsiElement) child).getElementType().toString().equals("identifier")) { - return (LeafPsiElement) child; - } - } while((child = child.getNextSibling()) != null); - - return null; - } + /** + * Check if given Page belongs to project test scope + * + * @param phpClass + * @return + */ + public static boolean isInExcludedNamespace(PhpClass phpClass, List excludedNamespaces) { + return excludedNamespaces.contains(phpClass.getNamespaceName()); + } + + public static String getPSRPathFromClassNamespace(String namespace) { + return namespace.replaceAll("\\\\", "/"); + } + + public static LeafPsiElement getClassNameIdentifierFrom(PhpClass phpClass) { + PsiElement child = phpClass.getFirstChild(); + do { + if (child instanceof LeafPsiElement && ((LeafPsiElement) child).getElementType().toString().equals("identifier")) { + return (LeafPsiElement) child; + } + } while ((child = child.getNextSibling()) != null); + + return null; + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/PhpStringUtils.java b/src/pl/projectspace/idea/plugins/commons/php/utils/PhpStringUtils.java index a0da13f..631c018 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/PhpStringUtils.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/PhpStringUtils.java @@ -7,12 +7,12 @@ */ public class PhpStringUtils { - public static String normaliseToClassName(String str) { - return WordUtils.capitalize(str).trim().replaceAll(" ", ""); - } + public static String normaliseToClassName(String str) { + return WordUtils.capitalize(str).trim().replaceAll(" ", ""); + } - public static boolean belongsToNamespace(String fqn, String namespace) { - return fqn.replaceAll("^\\\\", "").startsWith(namespace.replaceAll("^\\\\", "")); - } + public static boolean belongsToNamespace(String fqn, String namespace) { + return fqn.replaceAll("^\\\\", "").startsWith(namespace.replaceAll("^\\\\", "")); + } } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/DependsOnPlugin.java b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/DependsOnPlugin.java index 9a2c0b0..dfdc1b8 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/DependsOnPlugin.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/DependsOnPlugin.java @@ -8,5 +8,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface DependsOnPlugin { - String value(); + String value(); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/PluginAction.java b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/PluginAction.java index 04bec93..ad23bf7 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/PluginAction.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/PluginAction.java @@ -11,5 +11,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface PluginAction { - String value(); + String value(); } diff --git a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/RequireMethod.java b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/RequireMethod.java index 7f18cce..0429844 100644 --- a/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/RequireMethod.java +++ b/src/pl/projectspace/idea/plugins/commons/php/utils/annotation/RequireMethod.java @@ -11,5 +11,5 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface RequireMethod { - String value(); + String value(); } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/PhpSpecProject.java b/src/pl/projectspace/idea/plugins/php/phpspec/PhpSpecProject.java index 4bf60d8..b72e0af 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/PhpSpecProject.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/PhpSpecProject.java @@ -9,24 +9,24 @@ public class PhpSpecProject extends ProjectComponent implements StateComponentInterface { - private final PhpSpec config; + private final PhpSpec config; - public PhpSpecProject(Project project, PhpIndex index) { - super(project, index); - config = new PhpSpec(project); - } + public PhpSpecProject(Project project, PhpIndex index) { + super(project, index); + config = new PhpSpec(project); + } - @NotNull - @Override - public String getComponentName() { - return "phpspec"; - } + @NotNull + @Override + public String getComponentName() { + return "phpspec"; + } - public boolean isEnabled() { - return true; - } + public boolean isEnabled() { + return true; + } - public PhpSpec getConfig() { - return config; - } + public PhpSpec getConfig() { + return config; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/actions/CreateSpecForClassAction.java b/src/pl/projectspace/idea/plugins/php/phpspec/actions/CreateSpecForClassAction.java index 9ab081e..2764c83 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/actions/CreateSpecForClassAction.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/actions/CreateSpecForClassAction.java @@ -1,7 +1,6 @@ package pl.projectspace.idea.plugins.php.phpspec.actions; import com.intellij.ide.fileTemplates.FileTemplateManager; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -12,8 +11,8 @@ import pl.projectspace.idea.plugins.commons.php.utils.PhpClassUtils; import pl.projectspace.idea.plugins.commons.php.utils.annotation.PluginAction; import pl.projectspace.idea.plugins.php.phpspec.PhpSpecProject; -import pl.projectspace.idea.plugins.php.phpspec.core.services.PhpSpecLocator; import pl.projectspace.idea.plugins.php.phpspec.core.services.FileFactory; +import pl.projectspace.idea.plugins.php.phpspec.core.services.PhpSpecLocator; import java.io.IOException; import java.util.Properties; @@ -21,53 +20,55 @@ @PluginAction("phpspec") public class CreateSpecForClassAction extends PhpClassAction { - public void perform(final PhpClass phpClass) { - try { - createSpecFor(phpClass); - } catch (Exception e1) { - Messages.showErrorDialog(phpClass.getProject(), "Failed creating spec for given class.", "Failed Creating Spec File."); - } - } + public void perform(final PhpClass phpClass) { + try { + createSpecFor(phpClass); + } catch (Exception e1) { + Messages.showErrorDialog(phpClass.getProject(), "Failed creating spec for given class.", "Failed Creating Spec File."); + } + } - @Override - protected boolean isAvailable(final PhpClass phpClass) { - return phpClass != null && super.isAvailable(phpClass) && - !phpClass.getProject().getComponent(PhpSpecProject.class) - .getService(PhpSpecLocator.class).isSpec(phpClass); - } + @Override + protected boolean isAvailable(final PhpClass phpClass) { + return + phpClass != null && super.isAvailable(phpClass) && + !phpClass.getProject().getComponent(PhpSpecProject.class) + .getService(PhpSpecLocator.class).isSpec(phpClass); + } - protected void createSpecFor(PhpClass phpClass) throws IOException { - Project project = phpClass.getProject(); - PhpSpecLocator locator = project.getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); + protected void createSpecFor(PhpClass phpClass) throws IOException { + Project project = phpClass.getProject(); + PhpSpecLocator locator = project.getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); - String className = locator.getSpecNameFor(phpClass); - String namespace = locator.getSpecNamespaceFor(phpClass); + String className = locator.getSpecNameFor(phpClass); + String namespace = locator.getSpecNamespaceFor(phpClass.getFQN()); - Properties properties = FileTemplateManager.getInstance().getDefaultProperties(); - properties.setProperty("CLASS_NAME", className); - properties.setProperty("NAMESPACE", namespace); + Properties properties = FileTemplateManager.getInstance().getDefaultProperties(); + properties.setProperty("CLASS_NAME", className); + properties.setProperty("IMPLEMENTATION", phpClass.getFQN()); + properties.setProperty("NAMESPACE", namespace); - String specPath = PhpClassUtils.getPSRPathFromClassNamespace(namespace); + String specPath = PhpClassUtils.getPSRPathFromClassNamespace(namespace); - VirtualFile baseDir = project.getBaseDir(); - VirtualFile dir = baseDir.findFileByRelativePath(specPath); + VirtualFile baseDir = project.getBaseDir(); + VirtualFile dir = baseDir.findFileByRelativePath(specPath); - if (dir == null) { - dir = project.getComponent(PhpSpecProject.class).getService(FileFactory.class) - .createNamespaceDirectory(baseDir, specPath); - } + if (dir == null) { + dir = project.getComponent(PhpSpecProject.class).getService(FileFactory.class) + .createNamespaceDirectory(baseDir, specPath); + } - ApplicationManager.getApplication().runWriteAction( - project.getComponent(PhpSpecProject.class).getService(FileFactory.class) - .getCreateFileFromTemplateWriteAction( - dir, - className.concat(".php"), - PhpFileType.INSTANCE, - "Spec Class.php", - properties - ) - ); - } + ApplicationManager.getApplication().runWriteAction( + project.getComponent(PhpSpecProject.class).getService(FileFactory.class) + .getCreateFileFromTemplateWriteAction( + dir, + className.concat(".php"), + PhpFileType.INSTANCE, + "Spec Class.php", + properties + ) + ); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpec.java b/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpec.java index 654043f..2af363d 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpec.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpec.java @@ -1,10 +1,6 @@ package pl.projectspace.idea.plugins.php.phpspec.actions; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * @author Michal Przytulski diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpecSwitchContext.java b/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpecSwitchContext.java index a1bed76..c465b99 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpecSwitchContext.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/actions/PhpSpecSwitchContext.java @@ -14,64 +14,64 @@ @PluginAction("phpspec") public class PhpSpecSwitchContext extends PhpClassAction { - @Override - protected void perform(PhpClass phpClass) { - PhpSpecClassDecorator currentContext = getCurrentContext(phpClass); + @Override + protected void perform(PhpClass phpClass) { + PhpSpecClassDecorator currentContext = getCurrentContext(phpClass); - if (currentContext == null) { - // @todo - propose creation of missing spec / class - return; - } + if (currentContext == null) { + // @todo - propose creation of missing spec / class + return; + } - PhpClass destination = null; + PhpClass destination = null; - try { - if (currentContext instanceof PhpSpecClass) { - destination = ((PhpSpecClass) currentContext).getDescribedClass().getDecoratedObject(); - } else { - destination = ((PhpSpecDescribedClass) currentContext).getSpecClass().getDecoratedObject(); - } - } catch (MissingElementException e1) { - return; - } + try { + if (currentContext instanceof PhpSpecClass) { + destination = ((PhpSpecClass) currentContext).getDescribedClass().getDecoratedObject(); + } else { + destination = ((PhpSpecDescribedClass) currentContext).getSpecClass().getDecoratedObject(); + } + } catch (MissingElementException e1) { + return; + } - OpenFileAction.openFile(destination.getContainingFile().getVirtualFile(), phpClass.getProject()); - } + OpenFileAction.openFile(destination.getContainingFile().getVirtualFile(), phpClass.getProject()); + } - @Override - protected boolean isAvailable(final PhpClass phpClass) { - try { - return (super.isAvailable(phpClass) && getCurrentContext(phpClass).hasRelatedClass()); - } catch (NullPointerException e1) { - } + @Override + protected boolean isAvailable(final PhpClass phpClass) { + try { + return (super.isAvailable(phpClass) && getCurrentContext(phpClass).hasRelatedClass()); + } catch (NullPointerException e1) { + } - return false; - } + return false; + } - @Override - protected String getLabel(PhpClass phpClass) { - PhpSpecClassDecorator currentContext = getCurrentContext(phpClass); + @Override + protected String getLabel(PhpClass phpClass) { + PhpSpecClassDecorator currentContext = getCurrentContext(phpClass); - try { - if (currentContext instanceof PhpSpecClass) { - return "Go to: " + ((PhpSpecClass) currentContext).getDescribedClass().getDecoratedObject().getName() + " class"; - } else { - return "Go to: " + currentContext.getDecoratedObject().getName() + " spec"; - } - } catch (MissingElementException e) { - } catch (NullPointerException e) { - } + try { + if (currentContext instanceof PhpSpecClass) { + return "Go to: " + ((PhpSpecClass) currentContext).getDescribedClass().getDecoratedObject().getName() + " class"; + } else { + return "Go to: " + currentContext.getDecoratedObject().getName() + " spec"; + } + } catch (MissingElementException e) { + } catch (NullPointerException e) { + } - return null; - } + return null; + } - private PhpSpecClassDecorator getCurrentContext(PhpClass phpClass) { - try { - PhpSpecFactory factory = phpClass.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecFactory.class); + private PhpSpecClassDecorator getCurrentContext(PhpClass phpClass) { + try { + PhpSpecFactory factory = phpClass.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecFactory.class); - return factory.create(phpClass); - } catch (NullPointerException e) { - return null; - } - } + return factory.create(phpClass); + } catch (NullPointerException e) { + return null; + } + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionContributor.java b/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionContributor.java index 2ea426e..ab2de40 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionContributor.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionContributor.java @@ -9,10 +9,10 @@ */ public class SpecCompletionContributor extends CompletionContributor { - public SpecCompletionContributor() { - SpecCompletionProvider p = new SpecCompletionProvider(); + public SpecCompletionContributor() { + SpecCompletionProvider p = new SpecCompletionProvider(); - extend(CompletionType.BASIC, PlatformPatterns.psiElement(), p); - } + extend(CompletionType.BASIC, PlatformPatterns.psiElement(), p); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionProvider.java b/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionProvider.java index 2000819..4d4fa2b 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionProvider.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/code/SpecCompletionProvider.java @@ -20,19 +20,19 @@ @DependsOnPlugin("phpspec") public class SpecCompletionProvider extends GenericCompletionProvider { - protected void addCompletionsFor(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { - PsiElement element = parameters.getPosition(); + protected void addCompletionsFor(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { + PsiElement element = parameters.getPosition(); - if (element.getPrevSibling() == null || element.getPrevSibling().getPrevSibling() == null - || !(element.getPrevSibling().getPrevSibling() instanceof Variable)) { - return; - } + if (element.getPrevSibling() == null || element.getPrevSibling().getPrevSibling() == null + || !(element.getPrevSibling().getPrevSibling() instanceof Variable)) { + return; + } - PhpSpecStaticCompletionProvider staticCompletionProvider - = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecStaticCompletionProvider.class); + PhpSpecStaticCompletionProvider staticCompletionProvider + = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecStaticCompletionProvider.class); - for (Method method : staticCompletionProvider.getMethodsFor(PhpSpecStaticCompletionProvider.OBJECT_BEHAVIOUR_CLASS)) { - resultSet.addElement(new SimpleTextLookup(method.getName())); - } - } + for (Method method : staticCompletionProvider.getMethodsFor(PhpSpecStaticCompletionProvider.OBJECT_BEHAVIOUR_CLASS)) { + resultSet.addElement(new SimpleTextLookup(method.getName())); + } + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/code/type/provider/WrappedObjectTypeProvider.java b/src/pl/projectspace/idea/plugins/php/phpspec/code/type/provider/WrappedObjectTypeProvider.java index e1af505..fdf03f6 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/code/type/provider/WrappedObjectTypeProvider.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/code/type/provider/WrappedObjectTypeProvider.java @@ -1,45 +1,39 @@ package pl.projectspace.idea.plugins.php.phpspec.code.type.provider; import com.intellij.openapi.project.DumbService; -import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; -import com.jetbrains.php.PhpIndex; -import com.jetbrains.php.lang.psi.elements.*; -import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2; +import com.jetbrains.php.lang.psi.elements.MethodReference; +import com.jetbrains.php.lang.psi.elements.PhpClass; import org.jetbrains.annotations.Nullable; import pl.projectspace.idea.plugins.commons.php.code.type.GenericTypeProvider; -import pl.projectspace.idea.plugins.php.phpspec.core.PhpSpecClass; - -import java.util.Arrays; -import java.util.Collection; /** * @author Michal Przytulski */ public class WrappedObjectTypeProvider extends GenericTypeProvider { - @Nullable - @Override - public String getTypeFor(PsiElement psiElement) { + @Nullable + @Override + public String getTypeFor(PsiElement psiElement) { - if (DumbService.isDumb(psiElement.getProject())) { - return null; - } + if (DumbService.isDumb(psiElement.getProject())) { + return null; + } - if (psiElement instanceof MethodReference) { - MethodReference method = (MethodReference)psiElement; - if (!method.getName().equals("getWrappedObject")) { - return null; - } + if (psiElement instanceof MethodReference) { + MethodReference method = (MethodReference) psiElement; + if (!method.getName().equals("getWrappedObject")) { + return null; + } - PhpClass phpClass = PsiTreeUtil.getContextOfType(psiElement, PhpClass.class, false); + PhpClass phpClass = PsiTreeUtil.getContextOfType(psiElement, PhpClass.class, false); // PhpClass returnType = PhpSpecClass.getClassForSpec(phpClass, psiElement.getProject()); // return returnType.getFQN(); - } + } - return null; - } + return null; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/AbstractCommand.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/AbstractCommand.java index 8be0cb2..0b17b79 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/AbstractCommand.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/AbstractCommand.java @@ -1,9 +1,11 @@ package pl.projectspace.idea.plugins.php.phpspec.command; import com.intellij.openapi.project.Project; -import org.apache.commons.lang.ArrayUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; /** * @author Michal Przytulski @@ -11,53 +13,52 @@ public abstract class AbstractCommand implements CommandInterface { - private final Project project; - private HashMap namedParameters; - private LinkedList parameters; + private final Project project; + private HashMap namedParameters; + private LinkedList parameters; - public AbstractCommand(Project project) { - this.project = project; - - namedParameters = new HashMap(); - parameters = new LinkedList(); - } + public AbstractCommand(Project project) { + this.project = project; - public HashMap getNamedParams() { - return namedParameters; - } + namedParameters = new HashMap(); + parameters = new LinkedList(); + } - public List getParams() { - return parameters; - } + public HashMap getNamedParams() { + return namedParameters; + } - public void addNamedParameter(String name, String val) { - namedParameters.put(name, val); - } + public List getParams() { + return parameters; + } - public void addParameter(String param) { - parameters.add(param); - } + public void addNamedParameter(String name, String val) { + namedParameters.put(name, val); + } - public Project getProject() { - return project; - } + public void addParameter(String param) { + parameters.add(param); + } - public String[] getCommandLineArgs() { - List params = new ArrayList(); + public Project getProject() { + return project; + } - params.add(getCommand()); + public String[] getCommandLineArgs() { + List params = new ArrayList(); - for (String key : namedParameters.keySet()) { - if (key.length() == 1) { - params.add("-" + key + " " + namedParameters.get(key)); - } - else { - params.add("--" + key + "=" + namedParameters.get(key)); - } - } + params.add(getCommand()); - params.addAll(parameters); + for (String key : namedParameters.keySet()) { + if (key.length() == 1) { + params.add("-" + key + " " + namedParameters.get(key)); + } else { + params.add("--" + key + "=" + namedParameters.get(key)); + } + } - return params.toArray(new String[0]); - } + params.addAll(parameters); + + return params.toArray(new String[0]); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/CommandInterface.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/CommandInterface.java index 8a3ae3b..311106d 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/CommandInterface.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/CommandInterface.java @@ -10,14 +10,22 @@ */ public interface CommandInterface { - public String getTitle(); - public String getCommand(); - public HashMapgetNamedParams(); - public ListgetParams(); - public void addNamedParameter(String name, String val); - public void addParameter(String param); - public Project getProject(); - public boolean validateOutput(String output); - public String[] getCommandLineArgs(); + public String getTitle(); + + public String getCommand(); + + public HashMap getNamedParams(); + + public List getParams(); + + public void addNamedParameter(String name, String val); + + public void addParameter(String param); + + public Project getProject(); + + public boolean validateOutput(String output); + + public String[] getCommandLineArgs(); } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/Describe.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/Describe.java index e898840..00f8173 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/Describe.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/Describe.java @@ -8,34 +8,34 @@ */ public class Describe extends AbstractCommand implements CommandInterface { - private final PhpClass phpClass; - - public Describe(Project project, PhpClass phpClass) { - super(project); - this.phpClass = phpClass; - String fqn = phpClass.getFQN(); - fqn = fqn.substring(1, fqn.length()); - - addParameter(fqn); - } - - public String getSpecPath() { - return "spec/Test/TestSpec.php"; - } - - @Override - public String getTitle() { - return "Generate spec for class"; - } - - @Override - public String getCommand() { - return "desc"; - } - - @Override - public boolean validateOutput(String output) { - return true; - } + private final PhpClass phpClass; + + public Describe(Project project, PhpClass phpClass) { + super(project); + this.phpClass = phpClass; + String fqn = phpClass.getFQN(); + fqn = fqn.substring(1, fqn.length()); + + addParameter(fqn); + } + + public String getSpecPath() { + return "spec/Test/TestSpec.php"; + } + + @Override + public String getTitle() { + return "Generate spec for class"; + } + + @Override + public String getCommand() { + return "desc"; + } + + @Override + public boolean validateOutput(String output) { + return true; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/Executor.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/Executor.java index f617438..dec25ec 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/Executor.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/Executor.java @@ -2,128 +2,114 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.process.*; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; -import com.jetbrains.php.PhpBundle; -import com.jetbrains.php.composer.ComposerCommandExecutor; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; - /** * @author Michal Przytulski */ public class Executor { - private Project project; + private Project project; - private Locator locator; + private Locator locator; - public Executor setLocator(Locator locator) { - this.locator = locator; - return this; - } + public Executor setLocator(Locator locator) { + this.locator = locator; + return this; + } - public Executor setProject(Project project) { - this.project = project; - return this; - } + public Executor setProject(Project project) { + this.project = project; + return this; + } - public void execute(final CommandInterface command, @Nullable final Runnable callback) { - Task task = new Task.Modal(command.getProject(), command.getTitle(), true) { - public void run(ProgressIndicator indicator) { + public void execute(final CommandInterface command, @Nullable final Runnable callback) { + Task task = new Task.Modal(command.getProject(), command.getTitle(), true) { + public void run(ProgressIndicator indicator) { // if (indicator == null) { // throw new IllegalArgumentException( // "Argument 0 for @NotNull parameter of com/jetbrains/php/composer/ComposerCommandExecutor$1.run must not be null" // ); //// indicator.setIndeterminate(true); // } - StringBuilder sb = new StringBuilder(); - sb.append("Generating spec for class: "); - indicator.setText(sb.toString()); - - boolean cancelledByUser = false; - ExecutionException exception = null; - final StringBuilder outputBuilder = new StringBuilder(); - try { - String phpspecPath = locator.getPath(); - OSProcessHandler processHandler = ScriptRunnerUtil.execute( - phpspecPath, - getWorkingDir(), - null, - command.getCommandLineArgs() - ); - - String c = processHandler.getCommandLine(); - - processHandler.addProcessListener(new ProcessAdapter() - { - public void onTextAvailable(ProcessEvent event, Key outputType) { - outputBuilder.append(event.getText()); - } - }); - processHandler.startNotify(); - while (true) - { - boolean finished = processHandler.waitFor(1000L); - if (finished) { - break; - } - if (indicator.isCanceled()) { - cancelledByUser = true; - OSProcessManager.getInstance().killProcessTree(processHandler.getProcess()); - break; - } - } - } - catch (ExecutionException e) { - exception = e; - } - - String output = outputBuilder.toString(); - - final boolean success = - (exception == null) - && (!cancelledByUser) - && (output != null) - && (command.validateOutput(output)); - - if (!success) - { - String outputToReport; - String message; - if (exception != null) { - message = "m1"; - outputToReport = exception.getMessage(); - } - else - { - if (cancelledByUser) { - message = "m2"; - outputToReport = output; - } - else { + StringBuilder sb = new StringBuilder(); + sb.append("Generating spec for class: "); + indicator.setText(sb.toString()); + + boolean cancelledByUser = false; + ExecutionException exception = null; + final StringBuilder outputBuilder = new StringBuilder(); + try { + String phpspecPath = locator.getPath(); + OSProcessHandler processHandler = ScriptRunnerUtil.execute( + phpspecPath, + getWorkingDir(), + null, + command.getCommandLineArgs() + ); + + String c = processHandler.getCommandLine(); + + processHandler.addProcessListener(new ProcessAdapter() { + public void onTextAvailable(ProcessEvent event, Key outputType) { + outputBuilder.append(event.getText()); + } + }); + processHandler.startNotify(); + while (true) { + boolean finished = processHandler.waitFor(1000L); + if (finished) { + break; + } + if (indicator.isCanceled()) { + cancelledByUser = true; + OSProcessManager.getInstance().killProcessTree(processHandler.getProcess()); + break; + } + } + } catch (ExecutionException e) { + exception = e; + } + + String output = outputBuilder.toString(); + + final boolean success = + (exception == null) + && (!cancelledByUser) + && (output != null) + && (command.validateOutput(output)); + + if (!success) { + String outputToReport; + String message; + if (exception != null) { + message = "m1"; + outputToReport = exception.getMessage(); + } else { + if (cancelledByUser) { + message = "m2"; + outputToReport = output; + } else { // message = PhpBundle.message("framework.composer.failed.to.0.1.version.2", new Object[] { ComposerCommandExecutor.this.getActionName(), ComposerCommandExecutor.this.myPackage.getName(), ComposerCommandExecutor.this.getPresentableVersion() }); - message = "m3"; - outputToReport = output; - } - } - final boolean finalCancelledByUser = cancelledByUser; + message = "m3"; + outputToReport = output; + } + } + final boolean finalCancelledByUser = cancelledByUser; // ApplicationManager.getApplication().invokeLater(new Runnable() // { // public void run() { // ComposerCommandExecutor.this.showFailureOutput(outputToReport, finalCancelledByUser, message, ComposerCommandExecutor.1.this.myProject); // } // }); - } + } - final String finalOutput = output; + final String finalOutput = output; // ApplicationManager.getApplication().invokeLater(new Runnable() // { // public void run() @@ -131,15 +117,15 @@ public void onTextAvailable(ProcessEvent event, Key outputType) { // ComposerCommandExecutor.this.provideFeedback(success, finalOutput, ComposerCommandExecutor.this.myPackage, ComposerCommandExecutor.this.myVersion); // } // }); - if (callback != null) - callback.run(); - } - }; - ProgressManager.getInstance().run(task); - } - - private String getWorkingDir() { - return project.getBaseDir().getPath(); - } + if (callback != null) + callback.run(); + } + }; + ProgressManager.getInstance().run(task); + } + + private String getWorkingDir() { + return project.getBaseDir().getPath(); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/Locator.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/Locator.java index 1c96710..04db5e6 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/Locator.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/Locator.java @@ -11,10 +11,10 @@ import java.util.Map; @State( - name = "Locator", - storages = { - @Storage(id = "default", file="$PROJECT_CONFIG_DIR$/locator.xml", scheme = StorageScheme.DIRECTORY_BASED) - } + name = "Locator", + storages = { + @Storage(id = "default", file = "$PROJECT_CONFIG_DIR$/locator.xml", scheme = StorageScheme.DIRECTORY_BASED) + } ) /** @@ -22,58 +22,58 @@ */ public class Locator { - private Project project; + private Project project; - public Locator setProject(Project project) { - this.project = project; + public Locator setProject(Project project) { + this.project = project; - return this; - } + return this; + } - public String getPath() { - String path = getGlobalPath(); - if (path != null) { - return path; - } + public String getPath() { + String path = getGlobalPath(); + if (path != null) { + return path; + } - return getComposerPath(); - } + return getComposerPath(); + } - private String getGlobalPath() { - Map env = System.getenv(); - String paths = env.get("PATH"); - String separator = System.getProperty("path.separator"); + private String getGlobalPath() { + Map env = System.getenv(); + String paths = env.get("PATH"); + String separator = System.getProperty("path.separator"); - for (String path : paths.split(separator)) { - File file = new File(path.concat("/phpspec")); - if (file.exists()) { - return file.getAbsolutePath(); - } - } + for (String path : paths.split(separator)) { + File file = new File(path.concat("/phpspec")); + if (file.exists()) { + return file.getAbsolutePath(); + } + } - return null; - } + return null; + } - private String getComposerPath() { - ComposerDataService service = ComposerDataService.getInstance(project); - if (service.getConfigPath() == null) { - return null; - } + private String getComposerPath() { + ComposerDataService service = ComposerDataService.getInstance(project); + if (service.getConfigPath() == null) { + return null; + } - Composer composer = new pl.projectspace.idea.plugins.commons.php.composer.File(service.getConfigPath()).parse(); + Composer composer = new pl.projectspace.idea.plugins.commons.php.composer.File(service.getConfigPath()).parse(); - if (!composer.isRequired("phpspec/phpspec")) { - return null; - } + if (!composer.isRequired("phpspec/phpspec")) { + return null; + } - String path = project.getBasePath() + "/" + composer.getConfig().getBinDir() + "/phpspec"; + String path = project.getBasePath() + "/" + composer.getConfig().getBinDir() + "/phpspec"; - File file = new File(path); - if (!file.exists()) { - return null; - } + File file = new File(path); + if (!file.exists()) { + return null; + } - return path; - } + return path; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/command/PhpSpecCommand.java b/src/pl/projectspace/idea/plugins/php/phpspec/command/PhpSpecCommand.java index b6ea0d2..0090548 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/command/PhpSpecCommand.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/command/PhpSpecCommand.java @@ -7,13 +7,13 @@ */ public abstract class PhpSpecCommand { - protected final Project project; + protected final Project project; - public PhpSpecCommand(Project project) { - this.project = project; - } + public PhpSpecCommand(Project project) { + this.project = project; + } - protected abstract String getProgressTitle(); + protected abstract String getProgressTitle(); // protected abstract String getActionName(); diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/config/PhpSpec.java b/src/pl/projectspace/idea/plugins/php/phpspec/config/PhpSpec.java index 14c1712..c52a935 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/config/PhpSpec.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/config/PhpSpec.java @@ -7,13 +7,13 @@ */ public class PhpSpec { - private Project project; + private Project project; - public PhpSpec(Project project) { - this.project = project; - } + public PhpSpec(Project project) { + this.project = project; + } - public String getSpecsDir() { - return "spec/"; - } + public String getSpecsDir() { + return "spec/"; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClass.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClass.java index a189fb8..f684eb7 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClass.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClass.java @@ -1,51 +1,41 @@ package pl.projectspace.idea.plugins.php.phpspec.core; -import com.intellij.openapi.project.Project; -import com.jetbrains.php.PhpIndex; -import com.jetbrains.php.lang.psi.PhpPsiUtil; import com.jetbrains.php.lang.psi.elements.PhpClass; -import pl.projectspace.idea.plugins.commons.php.psi.element.PhpClassDecorator; import pl.projectspace.idea.plugins.commons.php.psi.exceptions.MissingElementException; -import pl.projectspace.idea.plugins.commons.php.utils.PhpClassUtils; -import pl.projectspace.idea.plugins.php.phpspec.PhpSpecProject; -import pl.projectspace.idea.plugins.php.phpspec.core.services.PhpSpecFactory; import pl.projectspace.idea.plugins.php.phpspec.core.services.PhpSpecLocator; -import pl.projectspace.idea.plugins.php.phpspec.core.services.PsiTreeUtils; - -import java.util.Collection; /** * @author Michal Przytulski */ public class PhpSpecClass extends PhpSpecClassDecorator { - private PhpSpecDescribedClass klass; + private PhpSpecDescribedClass klass; - public PhpSpecClass(PhpClass phpClass) { - super(phpClass); - } + public PhpSpecClass(PhpClass phpClass) { + super(phpClass); + } - @Override - public boolean hasRelatedClass() { - try { - getPhpSpecDescribedClass(); + @Override + public boolean hasRelatedClass() { + try { + getPhpSpecDescribedClass(); - return true; - } catch (MissingElementException e) { - } + return true; + } catch (MissingElementException e) { + } - return false; - } + return false; + } - public PhpSpecDescribedClass getDescribedClass() throws MissingElementException { - return getPhpSpecDescribedClass(); - } + public PhpSpecDescribedClass getDescribedClass() throws MissingElementException { + return getPhpSpecDescribedClass(); + } - protected PhpSpecDescribedClass getPhpSpecDescribedClass() throws MissingElementException { - if (klass == null) { - klass = getService(PhpSpecLocator.class).locateDescriptionFor(getDecoratedObject()); - } + protected PhpSpecDescribedClass getPhpSpecDescribedClass() throws MissingElementException { + if (klass == null) { + klass = getService(PhpSpecLocator.class).locateDescriptionFor(getDecoratedObject()); + } - return klass; - } + return klass; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClassDecorator.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClassDecorator.java index 5abc994..96eab1e 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClassDecorator.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecClassDecorator.java @@ -10,17 +10,17 @@ */ public abstract class PhpSpecClassDecorator extends PhpClassDecorator { - /** - * Create PhpClass decorator - * - * @param phpClass - */ - public PhpSpecClassDecorator(PhpClass phpClass) { - super(phpClass); - } + /** + * Create PhpClass decorator + * + * @param phpClass + */ + public PhpSpecClassDecorator(PhpClass phpClass) { + super(phpClass); + } - @Override - protected ProjectComponent getComponent() { - return getDecoratedObject().getProject().getComponent(PhpSpecProject.class); - } + @Override + protected ProjectComponent getComponent() { + return getDecoratedObject().getProject().getComponent(PhpSpecProject.class); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecDescribedClass.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecDescribedClass.java index ff1da7f..7c75b2c 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecDescribedClass.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecDescribedClass.java @@ -1,44 +1,41 @@ package pl.projectspace.idea.plugins.php.phpspec.core; import com.jetbrains.php.lang.psi.elements.PhpClass; -import pl.projectspace.idea.plugins.commons.php.psi.element.PhpClassDecorator; import pl.projectspace.idea.plugins.commons.php.psi.exceptions.MissingElementException; -import pl.projectspace.idea.plugins.php.phpspec.PhpSpecProject; import pl.projectspace.idea.plugins.php.phpspec.core.services.PhpSpecLocator; -import pl.projectspace.idea.plugins.php.phpspec.core.services.PsiTreeUtils; /** * @author Michal Przytulski */ public class PhpSpecDescribedClass extends PhpSpecClassDecorator { - protected PhpSpecClass spec = null; + protected PhpSpecClass spec = null; - public PhpSpecDescribedClass(PhpClass phpClass) { - super(phpClass); - } + public PhpSpecDescribedClass(PhpClass phpClass) { + super(phpClass); + } - @Override - public boolean hasRelatedClass() { - try { - getSpec(); + @Override + public boolean hasRelatedClass() { + try { + getSpec(); - return true; - } catch (MissingElementException e) { - return false; - } - } + return true; + } catch (MissingElementException e) { + return false; + } + } - public PhpSpecClass getSpecClass() throws MissingElementException { - return getSpec(); - } + public PhpSpecClass getSpecClass() throws MissingElementException { + return getSpec(); + } - protected PhpSpecClass getSpec() throws MissingElementException { - if (spec == null) { - spec = getService(PhpSpecLocator.class).locateSpecFor(getDecoratedObject()); - } + protected PhpSpecClass getSpec() throws MissingElementException { + if (spec == null) { + spec = getService(PhpSpecLocator.class).locateSpecFor(getDecoratedObject()); + } - return spec; - } + return spec; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIconProvider.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIconProvider.java index d0f2632..a237a0e 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIconProvider.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIconProvider.java @@ -1,6 +1,5 @@ package pl.projectspace.idea.plugins.php.phpspec.core; -import com.intellij.ide.IconProvider; import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; @@ -21,28 +20,28 @@ @DependsOnPlugin("phpspec") public class PhpSpecIconProvider extends PluginIconProvider { - private PhpSpecLocator locator; - - @Nullable - protected Icon getIconForElement(@NotNull PsiElement element, @Iconable.IconFlags int i) { - if ((element instanceof PhpFile)) { - PhpSpecLocator locator = getUtils(element); - - for (PsiNamedElement el : ((PhpFile)element).getTopLevelDefs().values()) { - if (el instanceof PhpClass && locator.isSpec((PhpClass) el)) { - return PhpSpecIcons.File; - } - } - } - return null; - } - - private PhpSpecLocator getUtils(PsiElement element) { - if (locator == null) { - locator = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); - } - - return locator; - } + private PhpSpecLocator locator; + + @Nullable + protected Icon getIconForElement(@NotNull PsiElement element, @Iconable.IconFlags int i) { + if ((element instanceof PhpFile)) { + PhpSpecLocator locator = getUtils(element); + + for (PsiNamedElement el : ((PhpFile) element).getTopLevelDefs().values()) { + if (el instanceof PhpClass && locator.isSpec((PhpClass) el)) { + return PhpSpecIcons.File; + } + } + } + return null; + } + + private PhpSpecLocator getUtils(PsiElement element) { + if (locator == null) { + locator = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); + } + + return locator; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIcons.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIcons.java index 8b438d8..ed2ef93 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIcons.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecIcons.java @@ -9,12 +9,11 @@ */ public class PhpSpecIcons { - public static final javax.swing.Icon Icon = load("/pl/projectspace/idea/plugins/php/phpspec/icons/phpspec_16_16.png"); - public static final Icon File = load("/pl/projectspace/idea/plugins/php/phpspec/icons/phpspec_file_16_16.png"); + public static final javax.swing.Icon Icon = load("/pl/projectspace/idea/plugins/php/phpspec/icons/phpspec_16_16.png"); + public static final Icon File = load("/pl/projectspace/idea/plugins/php/phpspec/icons/phpspec_file_16_16.png"); - private static Icon load(String path) - { - return IconLoader.getIcon(path, PhpSpecIcons.class); - } + private static Icon load(String path) { + return IconLoader.getIcon(path, PhpSpecIcons.class); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecLineMarker.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecLineMarker.java index 81761dc..34a1baa 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecLineMarker.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecLineMarker.java @@ -3,10 +3,6 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo; import com.intellij.codeInsight.daemon.LineMarkerProvider; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNameIdentifierOwner; -import com.intellij.psi.impl.source.tree.LeafPsiElement; -import com.intellij.psi.util.PsiTreeUtil; -import com.jetbrains.php.lang.psi.elements.PhpClass; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,18 +13,18 @@ * @author Michal Przytulski */ public class PhpSpecLineMarker implements LineMarkerProvider { - @Nullable - @Override - public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { + @Nullable + @Override + public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) { // if (element instanceof LeafPsiElement && ((LeafPsiElement) element).getElementType().toString().equals("class")) { // PsiTreeUtil.getNextSiblingOfType(element, PsiNameIdentifierOwner.class) // System.out.println("print 1"); // } - return null; - } + return null; + } - @Override - public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection lineMarkerInfos) { - System.out.println("print 2"); - } + @Override + public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection lineMarkerInfos) { + System.out.println("print 2"); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecTypeProvider.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecTypeProvider.java index 93f88ec..406649d 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecTypeProvider.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/PhpSpecTypeProvider.java @@ -15,35 +15,35 @@ */ public class PhpSpecTypeProvider extends GenericTypeProvider { - private PhpSpecLocator locator = null; + private PhpSpecLocator locator = null; - @Nullable - @Override - protected String getTypeFor(PsiElement element) { + @Nullable + @Override + protected String getTypeFor(PsiElement element) { - PhpSpecLocator locator1 = getLocator(element); - PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class); + PhpSpecLocator locator1 = getLocator(element); + PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class); - if (!(element instanceof Variable) || !((Variable)element).getName().equals("this") - || (phpClass == null) || !locator1.isSpec(phpClass)) { - return null; - } + if (!(element instanceof Variable) || !((Variable) element).getName().equals("this") + || (phpClass == null) || !locator1.isSpec(phpClass)) { + return null; + } - try { - PhpSpecDescribedClass spec = locator1.locateDescriptionFor(phpClass); + try { + PhpSpecDescribedClass spec = locator1.locateDescriptionFor(phpClass); - return spec.getDecoratedObject().getFQN(); - } catch (MissingElementException e) { - } + return spec.getDecoratedObject().getFQN(); + } catch (MissingElementException e) { + } - return null; - } + return null; + } - private PhpSpecLocator getLocator(PsiElement element) { - if (locator == null) { - locator = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); - } + private PhpSpecLocator getLocator(PsiElement element) { + if (locator == null) { + locator = element.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); + } - return locator; - } + return locator; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/PhpSpecClassInspection.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/PhpSpecClassInspection.java index fdbfa8f..b12e703 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/PhpSpecClassInspection.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/PhpSpecClassInspection.java @@ -16,37 +16,37 @@ @DependsOnPlugin("phpspec") public class PhpSpecClassInspection extends PhpClassInspection { - @Override - protected PhpElementVisitor getVisitor(@NotNull ProblemsHolder holder) { - return new ClassInspector(holder); - } - - public final class ClassInspector extends PhpElementVisitor { - - private ProblemsHolder holder; - - private PhpSpecLocator locator; - - public ClassInspector(ProblemsHolder holder) { - this.holder = holder; - this.locator = holder.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); - } - - @Override - public void visitPhpClass(PhpClass phpClass) { - if (phpClass.isInterface() || phpClass.isAbstract()) { - return; - } - - if (!locator.isSpec(phpClass)) { - try { - locator.locate(locator.getSpecFQNFor(phpClass)); - } catch (MissingElementException e) { - LeafPsiElement id = PhpClassUtils.getClassNameIdentifierFrom(phpClass); - holder.registerProblem(id, "Missing spec for class: " + phpClass.getName(), new GenerateSpecForClassFix(phpClass)); - } - } - } - } + @Override + protected PhpElementVisitor getVisitor(@NotNull ProblemsHolder holder) { + return new ClassInspector(holder); + } + + public final class ClassInspector extends PhpElementVisitor { + + private ProblemsHolder holder; + + private PhpSpecLocator locator; + + public ClassInspector(ProblemsHolder holder) { + this.holder = holder; + this.locator = holder.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecLocator.class); + } + + @Override + public void visitPhpClass(PhpClass phpClass) { + if (phpClass.isInterface() || phpClass.isAbstract()) { + return; + } + + if (!locator.isSpec(phpClass)) { + try { + locator.locate(locator.getSpecFQNFor(phpClass)); + } catch (MissingElementException e) { + LeafPsiElement id = PhpClassUtils.getClassNameIdentifierFrom(phpClass); + holder.registerProblem(id, "Missing spec for class: " + phpClass.getName(), new GenerateSpecForClassFix(phpClass)); + } + } + } + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/actions/GenerateSpecForClassFix.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/actions/GenerateSpecForClassFix.java index 895e0aa..7b8b342 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/actions/GenerateSpecForClassFix.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/inspection/actions/GenerateSpecForClassFix.java @@ -8,40 +8,38 @@ import org.jetbrains.annotations.NotNull; import pl.projectspace.idea.plugins.php.phpspec.actions.CreateSpecForClassAction; -import java.io.IOException; - /** * @author Michal Przytulski */ public class GenerateSpecForClassFix implements LocalQuickFix { - private final PhpClass relatedClass; - - public GenerateSpecForClassFix(PhpClass phpClass) { - relatedClass = phpClass; - } - - @NotNull - @Override - public String getName() { - return "Create missing spec for: '" + relatedClass.getName() + "'"; - } - - @NotNull - @Override - public String getFamilyName() { - return getName(); - } - - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { - if (!(problemDescriptor.getPsiElement() instanceof LeafPsiElement) - || !((LeafPsiElement) problemDescriptor.getPsiElement()).getElementType().toString().equals("identifier")) { - return; - } - - CreateSpecForClassAction action = new CreateSpecForClassAction(); - action.perform(relatedClass); - } + private final PhpClass relatedClass; + + public GenerateSpecForClassFix(PhpClass phpClass) { + relatedClass = phpClass; + } + + @NotNull + @Override + public String getName() { + return "Create missing spec for: '" + relatedClass.getName() + "'"; + } + + @NotNull + @Override + public String getFamilyName() { + return getName(); + } + + @Override + public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { + if (!(problemDescriptor.getPsiElement() instanceof LeafPsiElement) + || !((LeafPsiElement) problemDescriptor.getPsiElement()).getElementType().toString().equals("identifier")) { + return; + } + + CreateSpecForClassAction action = new CreateSpecForClassAction(); + action.perform(relatedClass); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/FileFactory.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/FileFactory.java index 3282ffe..cad9669 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/FileFactory.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/FileFactory.java @@ -6,7 +6,7 @@ * @author Michal Przytulski */ public class FileFactory extends pl.projectspace.idea.plugins.commons.php.utils.FileFactory { - public FileFactory(Project project) { - super(project); - } + public FileFactory(Project project) { + super(project); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecFactory.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecFactory.java index 157e168..bed3eb0 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecFactory.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecFactory.java @@ -10,27 +10,27 @@ */ public class PhpSpecFactory { - private final PsiTreeUtils utils; - private final PhpIndex index; - private PhpSpecLocator locator; + private final PsiTreeUtils utils; + private final PhpIndex index; + private PhpSpecLocator locator; - public PhpSpecFactory(PsiTreeUtils utils, PhpIndex index, PhpSpecLocator locator) { - this.utils = utils; - this.index = index; - this.locator = locator; - } + public PhpSpecFactory(PsiTreeUtils utils, PhpIndex index, PhpSpecLocator locator) { + this.utils = utils; + this.index = index; + this.locator = locator; + } - public T create(PhpClass phpClass) { - if (locator.isSpec(phpClass)) { - return (T) new PhpSpecClass(phpClass); - } else { - return (T) new PhpSpecDescribedClass(phpClass); - } - } + public T create(PhpClass phpClass) { + if (locator.isSpec(phpClass)) { + return (T) new PhpSpecClass(phpClass); + } else { + return (T) new PhpSpecDescribedClass(phpClass); + } + } - public T create(String fqn) { - PhpClass phpClass = utils.getClassByFQN(fqn); - return create(phpClass); - } + public T create(String fqn) { + PhpClass phpClass = utils.getClassByFQN(fqn); + return create(phpClass); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecLocator.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecLocator.java index 7b08b0c..0eab603 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecLocator.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecLocator.java @@ -1,78 +1,75 @@ package pl.projectspace.idea.plugins.php.phpspec.core.services; import com.jetbrains.php.PhpIndex; -import com.jetbrains.php.lang.psi.PhpPsiUtil; import com.jetbrains.php.lang.psi.elements.PhpClass; import pl.projectspace.idea.plugins.commons.php.code.locator.GenericObjectLocator; -import pl.projectspace.idea.plugins.commons.php.psi.element.PhpClassDecorator; import pl.projectspace.idea.plugins.commons.php.psi.exceptions.MissingElementException; import pl.projectspace.idea.plugins.php.phpspec.PhpSpecProject; import pl.projectspace.idea.plugins.php.phpspec.core.PhpSpecClass; import pl.projectspace.idea.plugins.php.phpspec.core.PhpSpecDescribedClass; -import pl.projectspace.idea.plugins.php.phpspec.core.services.PsiTreeUtils; /** * @author Michal Przytulski */ public class PhpSpecLocator extends GenericObjectLocator { - private final PsiTreeUtils utils; + private final PsiTreeUtils utils; - protected PhpSpecLocator(PhpIndex index, PsiTreeUtils utils) { - super(index); - this.utils = utils; - } + protected PhpSpecLocator(PhpIndex index, PsiTreeUtils utils) { + super(index); + this.utils = utils; + } - @Override - public T locate(String name) throws MissingElementException { - PhpClass phpClass = utils.getClassByFQN(name); + @Override + public T locate(String name) throws MissingElementException { + PhpClass phpClass = utils.getClassByFQN(name); - if (phpClass != null) { - return (T) phpClass.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecFactory.class).create(phpClass); - } + if (phpClass != null) { + return (T) phpClass.getProject().getComponent(PhpSpecProject.class).getService(PhpSpecFactory.class).create(phpClass); + } - throw new MissingElementException("Failed to locate object"); - } + throw new MissingElementException("Failed to locate object"); + } - public boolean isSpec(PhpClass phpClass) { - return (phpClass.getFQN().startsWith("\\spec") && phpClass.getFQN().endsWith("Spec")); - } + public boolean isSpec(PhpClass phpClass) { + return (phpClass.getFQN().startsWith("\\spec") && phpClass.getFQN().endsWith("Spec")); + } - public boolean isDescribed(PhpClass phpClass) { - try { - String name = getSpecFQNFor(phpClass); - return (!isSpec(phpClass) && (locate(name) != null)); - } catch (MissingElementException e) { - return false; - } - } + public boolean isDescribed(PhpClass phpClass) { + try { + String name = getSpecFQNFor(phpClass); + return (!isSpec(phpClass) && (locate(name) != null)); + } catch (MissingElementException e) { + return false; + } + } - public String getSpecFQNFor(PhpClass phpClass) { - return getSpecNamespaceFor(phpClass) + "\\"+ getSpecNameFor(phpClass); - } + public String getSpecFQNFor(PhpClass phpClass) { + return getSpecNamespaceFor(phpClass) + "\\" + getSpecNameFor(phpClass); + } - public String getDescribedFQNFor(PhpClass phpClass) { - return phpClass.getFQN().replaceAll("^\\\\spec", "").replaceAll("Spec$", ""); - } + public String getDescribedFQNFor(PhpClass phpClass) { + return phpClass.getFQN().replaceAll("^\\\\spec", "").replaceAll("Spec$", ""); + } - public String getSpecNameFor(PhpClass phpClass) { - return phpClass.getName() + "Spec"; - } + public String getSpecNameFor(PhpClass phpClass) { + return phpClass.getName() + "Spec"; + } - public String getSpecNamespaceFor(PhpClass phpClass) { - return getSpecNamespaceFor(phpClass.getFQN()); - } + public String getSpecNamespaceFor(PhpClass phpClass) { + return getSpecNamespaceFor(phpClass.getFQN()); + } - public String getSpecNamespaceFor(String fqn) { - return "spec" + fqn.substring(0, fqn.lastIndexOf("\\")); - } + public String getSpecNamespaceFor(String fqn) { + return "spec" + fqn.substring(0, fqn.lastIndexOf("\\")); + } - public PhpSpecClass locateSpecFor(PhpClass decoratedObject) throws MissingElementException { - return locate(getSpecFQNFor(decoratedObject)); - } + public PhpSpecClass locateSpecFor(PhpClass decoratedObject) throws MissingElementException { + return locate(getSpecFQNFor(decoratedObject)); + } - public PhpSpecDescribedClass locateDescriptionFor(PhpClass phpClass) throws MissingElementException { - return locate(getDescribedFQNFor(phpClass)); - } + public PhpSpecDescribedClass locateDescriptionFor(PhpClass phpClass) throws MissingElementException { + return locate(getDescribedFQNFor(phpClass)); + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecStaticCompletionProvider.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecStaticCompletionProvider.java index b77a7f4..f7eeafe 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecStaticCompletionProvider.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PhpSpecStaticCompletionProvider.java @@ -15,43 +15,41 @@ */ public class PhpSpecStaticCompletionProvider { - private PhpIndex index; - private PsiTreeUtils utils; - - private Map> map; - - public final static String OBJECT_BEHAVIOUR_CLASS = "\\PhpSpec\\ObjectBehavior"; - - public PhpSpecStaticCompletionProvider(PhpIndex index, PsiTreeUtils utils) { - this.index = index; - this.utils = utils; - - PhpClass objectBehaviourClass = utils.getClassByFQN(OBJECT_BEHAVIOUR_CLASS); - - map = new HashMap>(); - map.put(objectBehaviourClass.getFQN(), buildCompletionFor(objectBehaviourClass)); - } - - public List getMethodsFor(PhpClass phpClass) { - return getMethodsFor(phpClass.getFQN()); - } - - public List getMethodsFor(String className) { - if (!map.containsKey(className)) { - return null; - } - - return map.get(className); - } - - private List buildCompletionFor(PhpClass phpClass) { - List list = new ArrayList(); - for (Method method : phpClass.getMethods()) { - if (method.getAccess().isWeakerThan(PhpModifier.Access.PROTECTED)) { - list.add(method); - } - } - - return list; - } + public final static String OBJECT_BEHAVIOUR_CLASS = "\\PhpSpec\\ObjectBehavior"; + private PhpIndex index; + private PsiTreeUtils utils; + private Map> map; + + public PhpSpecStaticCompletionProvider(PhpIndex index, PsiTreeUtils utils) { + this.index = index; + this.utils = utils; + + PhpClass objectBehaviourClass = utils.getClassByFQN(OBJECT_BEHAVIOUR_CLASS); + + map = new HashMap>(); + map.put(objectBehaviourClass.getFQN(), buildCompletionFor(objectBehaviourClass)); + } + + public List getMethodsFor(PhpClass phpClass) { + return getMethodsFor(phpClass.getFQN()); + } + + public List getMethodsFor(String className) { + if (!map.containsKey(className)) { + return null; + } + + return map.get(className); + } + + private List buildCompletionFor(PhpClass phpClass) { + List list = new ArrayList(); + for (Method method : phpClass.getMethods()) { + if (method.getAccess().isWeakerThan(PhpModifier.Access.PROTECTED)) { + list.add(method); + } + } + + return list; + } } diff --git a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PsiTreeUtils.java b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PsiTreeUtils.java index c223a17..86201be 100644 --- a/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PsiTreeUtils.java +++ b/src/pl/projectspace/idea/plugins/php/phpspec/core/services/PsiTreeUtils.java @@ -7,7 +7,7 @@ * @author Michal Przytulski */ public class PsiTreeUtils extends pl.projectspace.idea.plugins.commons.php.psi.PsiTreeUtils { - public PsiTreeUtils(Project project, PhpIndex index) { - super(project, index); - } + public PsiTreeUtils(Project project, PhpIndex index) { + super(project, index); + } }