Skip to content

Commit

Permalink
reformat everything to have a better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
wodka committed Oct 30, 2014
1 parent 6fceaed commit d45aee3
Show file tree
Hide file tree
Showing 71 changed files with 1,967 additions and 2,027 deletions.
13 changes: 8 additions & 5 deletions resources/fileTemplates/j2ee/Spec Class.php.ft
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
#parse("PHP File Header.php")

#if (${NAMESPACE})

namespace ${NAMESPACE};
Expand All @@ -9,6 +7,11 @@ namespace ${NAMESPACE};
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ${CLASS_NAME} extends ObjectBehavior
{
}
/**
* specification for ${IMPLEMENTATION}
*/
class ${CLASS_NAME} extends ObjectBehavior {
public function it_is_initializable() {
$this->shouldHaveType('${IMPLEMENTATION}');
}
}
82 changes: 41 additions & 41 deletions src/pl/projectspace/idea/plugins/commons/php/ProjectComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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>T getService(@NotNull Class<T> 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> T getService(@NotNull Class<T> service) {
return (T) ServiceManager.getService(project, service);
}

public Project getProject() {
return project;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface StateComponentInterface {

public boolean isEnabled();
public boolean isEnabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@

public abstract class GenericCompletionProvider extends CompletionProvider<CompletionParameters> {

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);

}
Loading

0 comments on commit d45aee3

Please sign in to comment.