Git Product home page Git Product logo

idea-php-annotation-plugin's Introduction

IntelliJ IDEA - PhpStorm PHP Annotations / Attributes

Build Status Version Downloads Downloads last month Donate to this project using Paypal

Provides PHP annotation extended Attribute support and for PhpStorm / IntelliJ IDEA and references for "Code > Optimize Imports" action.

Key Value
Plugin url https://plugins.jetbrains.com/plugin/7320
Id de.espend.idea.php.annotation
Changelog CHANGELOG

Install

  • Download plugin or install directly out of PhpStorm
  • Force file reindex if necessary with: File -> Invalidate Cache

Settings

PHP > Annotations / Attributes

Round brackets

/**
 * @Foo<caret>()
 * @Foo<caret>
 */
class NotBlank extends Constraint {}

Use / Import alias

PHP -> Annotations / Attributes -> Use Alias

Annotations
use Doctrine\ORM\Mapping as ORM;

/**
 * @Id() -> @ORM\Id()
 * @NotBlank() -> @Assert\NotBlank()
 */
class Foo {}
Attributes
use Doctrine\ORM\Mapping as ORM;

#[Id] -> #[ORM\Id()]
#[NotBlank] -> #[Assert\NotBlank()]
class Foo {}

Class LineMarker

LineMarker which provide navigation to annotation class usages

namespace Doctrine\ORM\Mapping;

/**
 * @Annotation
 */
final class Entity implements Annotation
{
}

Targeting

/**
 * @ORM\Entity()
 */

Annotation Class Detection

  • Every class with @Annotation inside class doc block is detected on file indexing
  • Annotation Properties on property names
  • Property value types
  • @ENUM Tags
/**
 * @Annotation
 */
class NotBlank extends Constraint {
    public $message = 'This value should not be blank.';
    public $groups = array();

    /**
     * @var bool|boolean
     */
    public $option = false;

    /**
     *
     * @Enum({"AUTO", "SEQUENCE", "TABLE", "IDENTITY", "NONE", "UUID", "CUSTOM"})
     */
    public $strategy = 'AUTO';

    /**
     * @var array<string>
     */
    public $cascade;
    
    /**
     * @var mixed|foobar|bool
     */
    public $mixed;
}

https://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html#attribute-types

/**
 * @Annotation
 *
 * @Attributes({
 *   @Attribute("stringProperty", type = "string"),
 *   @Attribute("annotProperty",  type = "bool"),
 * })
 */
 *
 * @Attributes(
 *   @Attribute("stringProperty", type = "string"),
 *   @Attribute("annotProperty",  type = "bool"),
 * )
 */
class Foobar {}

Annotation Target Detection

@Target is used to attach annotation, if non provided its added to "ALL list"

/**
 * @Annotation
 * @Target("PROPERTY", "METHOD", "CLASS", "ALL")
 */
class NotBlank extends Constraint {
    public $message = 'This value should not be blank.';
}

Extension Points

Plugins provides several extension points, which allows external plugins to provide additional. See some examples on Symfony2 Plugin

Example for extension points.

<extensionPoints>
      <extensionPoint name="PhpAnnotationCompletionProvider" interface="de.espend.idea.php.annotation.extension.PhpAnnotationCompletionProvider"/>
      <extensionPoint name="PhpAnnotationReferenceProvider" interface="de.espend.idea.php.annotation.extension.PhpAnnotationReferenceProvider"/>
      <extensionPoint name="PhpAnnotationDocTagGotoHandler" interface="de.espend.idea.php.annotation.extension.PhpAnnotationDocTagGotoHandler"/>
      <extensionPoint name="PhpAnnotationDocTagAnnotator" interface="de.espend.idea.php.annotation.extension.PhpAnnotationDocTagAnnotator"/>
      <extensionPoint name="PhpAnnotationGlobalNamespacesLoader" interface="de.espend.idea.php.annotation.extension.PhpAnnotationGlobalNamespacesLoader"/>
      <extensionPoint name="PhpAnnotationVirtualProperties" interface="de.espend.idea.php.annotation.extension.PhpAnnotationVirtualProperties"/>
      
      <!-- Custom class alias mapping: "ORM" => "Doctrine\\ORM\\Mapping" -->
      <extensionPoint name="PhpAnnotationUseAlias" interface="de.espend.idea.php.annotation.extension.PhpAnnotationUseAlias"/>
</extensionPoints>

Usage

<extensions defaultExtensionNs="de.espend.idea.php.annotation">
  <PhpAnnotationExtension implementation="de.espend.idea.php.annotation.completion.PhpAnnotationTypeCompletionProvider"/>
</extensions>

PHP Attributes Bridge

All extensions points providing support to DocBlock and PHP Attributes at the same time.

use Symfony\Component\Validator\Constraints\NotBlank;

#[NotBlank(message: 'An empty file is not allowed.')]
/* @NotBlank({message: "An empty file is not allowed."}) */
#[Template('foo.html.twig')]
/* @Template("foo.html.twig") */

Completion confidence

Annoying pressing completion shortcut? Plugin provides a nice completion confidence to open completion popover on several conditions

/**
 * @<caret>
 * <caret>
 */

Static values

    /**
     * @DI\Observe(SomethingEvents::PRE_UPDATE)
     */

Doctrine

ORM: Property generator

class Foo {
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    public $id<caret>;
}
class Foo {
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[ORM\Column(type: 'integer')]
    public $id<caret>;
}

ORM: class entity generator

#[ORM\Entity(repositoryClass: \Foo::class)]
#[ORM\Table(name: 'bike')]
class Foo { }

ORM: repository class generator / intention

/**
 * @ORM\Entity(repositoryClass="UnknownClass")
 */
class Foo { }
/**
 * @ORM\Entity<caret>
 */
class Foo { }

ORM: repository class completion

/**
 * @ORM\Entity(repositoryClass="<caret>")
 */

PHP Toolbox

Provides integration for PHP Toolbox

Default and property values

use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route("<caret>")
 * @Route(condition="<caret>")
 */
{
  "registrar":[
    {
      "signatures":[
        {
          "class": "Symfony\\Component\\Routing\\Annotation\\Route",
          "type": "annotation"
        },
        {
          "class": "Symfony\\Component\\Routing\\Annotation\\Route",
          "field": "condition",
          "type": "annotation"
        }
      ],
      "provider":"foo",
      "language":"php"
    }
  ],
}

Property array values

use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route(methods={"<caret>"})
 */
{
  "registrar":[
    {
      "language":"php",
      "provider":"methods",
      "signatures":[
        {
          "class": "Symfony\\Component\\Routing\\Annotation\\Route",
          "type": "annotation_array",
          "field": "methods"
        }
      ]
    }
  ],
  "providers": [
    {
      "name": "methods",
      "items":[
        {
          "lookup_string": "POST"
        }
      ]
    }
  ]
}

idea-php-annotation-plugin's People

Contributors

artspb avatar cedricziel avatar derrabus avatar haehnchen avatar jackbentley avatar king2500 avatar koc avatar meyerbaptiste avatar rvishnyakov avatar shyim avatar vkhramtsov avatar wbars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

idea-php-annotation-plugin's Issues

Plugin version 1.6 is incompatible with the PhpStorm 9 EAP 141.115+

There are the following incompatibilities:

accessing to unknown class: PhpCodeUtil$AccessorMethodData 
PhpCodeUtil$AccessorMethodData[] DoctrinePropertyOrmAnnotationGenerateAction$1#createAccessors(PsiElement)

method isn't implemented: boolean PhpGenerateFieldAccessorHandlerBase#containsSetters() 
DoctrinePropertyOrmAnnotationGenerateAction$1

method isn't implemented: PhpAccessorMethodData[] PhpGenerateFieldAccessorHandlerBase#createAccessors(PsiElement)
DoctrinePropertyOrmAnnotationGenerateAction$1

PhpStorm initialization failed with plugin

PhpStorm 131.98, Windows 7 x64

Internal error. Please report to http://youtrack.jetbrains.com

java.lang.RuntimeException: com.intellij.ide.plugins.PluginManager$StartupAbortedException: Fatal error initializing 'com.intellij.util.indexing.FileBasedIndex'
    at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:258)
    at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:59)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:696)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:524)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:335)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: com.intellij.ide.plugins.PluginManager$StartupAbortedException: Fatal error initializing 'com.intellij.util.indexing.FileBasedIndex'
    at com.intellij.ide.plugins.PluginManager.handleComponentError(PluginManager.java:215)
    at com.intellij.openapi.application.impl.ApplicationImpl.handleInitComponentError(ApplicationImpl.java:366)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter$1.getComponentInstance(ComponentManagerImpl.java:570)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:590)
    at com.intellij.util.pico.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:226)
    at com.intellij.util.pico.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:213)
    at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:200)
    at org.picocontainer.alternatives.AbstractDelegatingMutablePicoContainer.getComponentInstance(AbstractDelegatingMutablePicoContainer.java:75)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponent(ComponentManagerImpl.java:121)
    at com.intellij.openapi.application.impl.ApplicationImpl.createComponent(ApplicationImpl.java:386)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:112)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:89)
    at com.intellij.openapi.components.impl.stores.ApplicationStoreImpl.load(ApplicationStoreImpl.java:87)
    at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:525)
    at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:250)
    ... 18 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: de.espend.idea.php.annotation.AnnotationStubIndex PluginClassLoader[de.espend.idea.php.annotation, 0.1]
    at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.loadClass(ExtensionComponentAdapter.java:151)
    at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.getComponentImplementation(ExtensionComponentAdapter.java:63)
    at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.getComponentInstance(ExtensionComponentAdapter.java:70)
    at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.getExtension(ExtensionComponentAdapter.java:111)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.processAdapters(ExtensionPointImpl.java:241)
    at com.intellij.openapi.extensions.impl.ExtensionPointImpl.getExtensions(ExtensionPointImpl.java:185)
    at com.intellij.openapi.extensions.Extensions.getExtensions(Extensions.java:111)
    at com.intellij.openapi.extensions.Extensions.getExtensions(Extensions.java:98)
    at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:278)
    at com.intellij.util.indexing.FileBasedIndexImpl.initComponent(FileBasedIndexImpl.java:356)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter$1.getComponentInstance(ComponentManagerImpl.java:548)
    ... 30 more
Caused by: java.lang.ClassNotFoundException: de.espend.idea.php.annotation.AnnotationStubIndex PluginClassLoader[de.espend.idea.php.annotation, 0.1]
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.java:82)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.openapi.extensions.impl.ExtensionComponentAdapter.loadClass(ExtensionComponentAdapter.java:148)
    ... 40 more

Read access is allowed from event dispatch thread

Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())
Details: Current thread: Thread[ApplicationImpl pooled thread 223,4,main] 32537843
Our dispatch thread:Thread[AWT-EventQueue-0 7.1.1#PS-133.679, eap:false,6,main] 18913093
SystemEventQueueThread: Thread[AWT-EventQueue-0 7.1.1#PS-133.679, eap:false,6,main] 18913093
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:124)
at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:1025)
at com.intellij.psi.impl.source.tree.LazyParseableElement.f(LazyParseableElement.java:163)
at com.intellij.psi.impl.source.tree.LazyParseableElement.getFirstChildNode(LazyParseableElement.java:202)
at com.intellij.psi.impl.source.tree.LazyParseablePsiElement.getFirstChild(LazyParseablePsiElement.java:89)
at com.intellij.psi.PsiWalkingState$PsiTreeGuide.getFirstChild(PsiWalkingState.java:43)
at com.intellij.psi.PsiWalkingState$PsiTreeGuide.getFirstChild(PsiWalkingState.java:30)
at com.intellij.util.WalkingState.next(WalkingState.java:73)
at com.intellij.util.WalkingState.walkChildren(WalkingState.java:61)
at com.intellij.util.WalkingState.elementStarted(WalkingState.java:52)
at com.intellij.psi.PsiWalkingState.elementStarted(PsiWalkingState.java:70)
at com.intellij.psi.PsiRecursiveElementWalkingVisitor.visitElement(PsiRecursiveElementWalkingVisitor.java:48)
at de.espend.idea.php.annotation.AnnotationStubIndex$1$1.visitElement(AnnotationStubIndex.java:58)
at com.intellij.psi.PsiElementVisitor.visitFile(PsiElementVisitor.java:32)
at com.intellij.psi.PsiRecursiveElementWalkingVisitor.visitFile(PsiRecursiveElementWalkingVisitor.java:70)
at com.intellij.extapi.psi.PsiFileBase.accept(PsiFileBase.java:70)
at com.jetbrains.php.lang.psi.PhpFileImpl.accept(PhpFileImpl.java:141)
at de.espend.idea.php.annotation.AnnotationStubIndex$1.map(AnnotationStubIndex.java:51)
at de.espend.idea.php.annotation.AnnotationStubIndex$1.map(AnnotationStubIndex.java:36)
at com.intellij.util.indexing.MapReduceIndex.update(MapReduceIndex.java:209)
at com.intellij.util.indexing.FileBasedIndexImpl.a(FileBasedIndexImpl.java:1777)
at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1717)
at com.intellij.util.indexing.FileBasedIndexImpl$ChangedFilesCollector.a(FileBasedIndexImpl.java:2284)
at com.intellij.util.indexing.FileBasedIndexImpl$ChangedFilesCollector.a(FileBasedIndexImpl.java:2235)
at com.intellij.util.indexing.FileBasedIndexImpl$ChangedFilesCollector.access$1600(FileBasedIndexImpl.java:1879)
at com.intellij.util.indexing.FileBasedIndexImpl.ensureUpToDate(FileBasedIndexImpl.java:815)
at com.intellij.util.indexing.FileBasedIndexImpl.ensureUpToDate(FileBasedIndexImpl.java:785)
at com.intellij.psi.stubs.StubIndexImpl.process(StubIndexImpl.java:240)
at com.intellij.psi.stubs.StubIndexImpl.get(StubIndexImpl.java:219)
at com.intellij.psi.stubs.StubIndexImpl.get(StubIndexImpl.java:209)
at com.jetbrains.php.PhpIndexImpl.getDirectSubclasses(PhpIndexImpl.java:280)
at com.jetbrains.php.PhpIndexImpl.getAllSubclasses(PhpIndexImpl.java:297)
at com.jetbrains.php.PhpIndexImpl.getAllSubclasses(PhpIndexImpl.java:289)
at com.jetbrains.php.PhpClassHierarchyUtils.processOverridingMembers(PhpClassHierarchyUtils.java:222)
at com.jetbrains.php.lang.findUsages.PhpFindUsagesHandlerFactory$1.processInReadAction(PhpFindUsagesHandlerFactory.java:63)
at com.jetbrains.php.lang.findUsages.PhpFindUsagesHandlerFactory.checkImplementedMethods(PhpFindUsagesHandlerFactory.java:60)
at com.jetbrains.php.lang.findUsages.PhpFindUsagesHandler.processElementUsages(PhpFindUsagesHandler.java:77)
at com.intellij.find.findUsages.FindUsagesManager$3.generate(FindUsagesManager.java:436)
at com.intellij.usages.impl.UsageViewManagerImpl$SearchForUsagesRunnable.searchUsages(UsageViewManagerImpl.java:350)
at com.intellij.usages.impl.UsageViewManagerImpl$SearchForUsagesRunnable.run(UsageViewManagerImpl.java:331)
at com.intellij.usages.impl.UsageViewManagerImpl$1.run(UsageViewManagerImpl.java:147)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:464)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:373)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:420)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:150)

Missing import for annotations after update to 1.5

Before plugin has been updated everything works fine, but after the upgrade to version 1.5, all annotations become highlighted error "No import - Doc class block annotations found - but do not fall in the use of the statement"

oiaqrw9

How to find Psi elements for concrete annotations

I'm building a PhpStorm extension for Go! Aspect-Oriented framework. Now I'm looking for the best way to find specific annotations and inject my annotator with pointcut grammar parser and highlightrer into these annotations.

My annotation class is one from https://github.com/lisachenko/go-aop-php/tree/master/src/Lang/Annotation (e.g. After, Around, Before, etc). How can I look for them across the project? Maybe do you have any helpers in your extension for quick check the FQDN of annotation node?

Any help will be appreciated )

Imported classes are marked as unused when used for constant

When importing classes for using its constants in an annotation, the imports are incorrectly marked as unused. Example:

namespace A;

use JMS\DiExtraBundle\Annotation as DI;
use Some\Namespace\To\MyEvents; // incorrectly marked as unused

class SomeClass {
    /** @DI\Observe(MyEvents::SOME_EVENT) */
    public function doSomething() {
    }
}

I'm using the latest version of the plugin (2.6.2). This makes it impossible to let the IDE automically optimize imports (e.g. via the shortcut or on commit). When not using this feature, it is still error-prone because mistakenly removing such an import will break the code.

Auto-complete without "()" by default

Hi! :)

Thanks first of all for this wonderful plugin! I use and enjoy it a lot.

I'd love to see annotations being auto-completed without "()" by default. If I type @Generat + [Ctrl]+[Space], then the plugin inserts:

@GeneratedValue()

although I'd like to see

@GeneratedValue

Is this feasible?

Unable to get it working under 7.1.2

Hi,

I installed this and the symfony2 plugin under 7.1.2 133.803 and I'm unable to get this working. I've restarted and invalidated file caches. Under PHP > Annotations the plugin is enabled.

On a blank line I'm not getting prompted with the autocomplete dropdown, do I have to initiate a shortcut?

invalidate cache req

Any chances of removing this requirement.
This is extremely annoying as it clears local history.
Also this wouldn't be a problem if I had only two project, but when switching between multiple projects and turning on annotations on each of them and clearing cache for each of them this really becomes troublesome.

Improve "Add Doctrine Column" intentions

Works:

protected<caret> $test;
protected $test<caret>;

Doesn't work yet:

protected $test<caret>
protected $te<caret>st;
protected <caret>$test;
<caret>protected $test;

Can you implement these cases as well?

This is my most common usecase:

protected $test<caret>

I've just written the field name (but not the semicolon yet and want to make it a Doctrine field now before completing the line with ";"). Currently I have to write the semicolon and go one char left to get the intention.

Thanks.

Tested with PhpStorm EAP 141.332

Add support for automatic namespace import and aliasing

It would be very nice, if you could add support for automatic namespace import and aliasing, so there is no need for importing the annotation classes explicitly. For example the XML Mapper Hitch is using this feature: https://github.com/lampjunkie/xml-hitch

Let me show you with some code, what i mean.

Sample Annotation class:

/**
 * Annotation mapping components of the sample project
 */
namespace MyProject\SampleNamespace\Annotation;
// Import dependencies
use Doctrine\Common\Annotations\Annotation;

/**
 * Sample annotation
 *
 * @Annotation
 */
class SampleAnnotation extends Annotation
{
    /**
     * Name of the element
     *
     * @var string
     */
    public $name;
}

In the bootstrap code you have to do the following:

// Import dependencies
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\AnnotationReader;

function setUpAnnotationReader(AnnotationReader $reader) {
        // register the namespace for autoloading and register an alias for it
        $namespace = '\\MyProject\\SampleNamespace\\Annotation\\';
        AnnotationRegistry::registerAutoloadNamespace($namespace, realpath(__DIR__));
        $reader->setAnnotationNamespaceAlias($namespace, 'sample');
        return $reader;
}

$reader = setUpAnnotationReader(new AnnotationReader());

In your application, you can use the Annotation classes without the need of importing them explicitly by writing:

namespace MyProject\SampleNamespace\Application;

/**
 * Sample entity
 */
class Entity
{
    /**
     * Name of the element
     *
     * @sample:SampleAnnotation(name="publicName")
     */
    private $_internalName;
}

Add option to always use an aliased import for some annotations or namespaces

Sometimes some annotations are generally namespaces and named something else to make it easier to read. For example Doctrine\ORM\Mapping is generally imported as just ORM or JMS\DiExtraBundle\Annotation as just DI. Currently to be able to do this from scratch you have to do the following:

  1. Type @[any of the annotations within aforementioned namespace]
  2. Enter/Ctrl + Space to auto import the annotation
  3. Go to imports, and remove the class name, append as [alias name]
  4. Prefix annotation with [alias name]\

It's quite fiddly. It would be nice to have an option to simply list some annotations or namespaces in the settings and this would always auto import with an alias, and the annotation will be prepended with the alias name.

Upgrade autocompletion: class constants

I'm very much hoping to use this plugin for a custom annotation implementation but am having issues with auto completion. Would it be possible to allow auto completion for class constants, or even application constants?

How I'd like to use it is any of the following (Route can be an annotated class):

/**
 * @Route CONSTANT_HERE
 * @Route(CONSTANT_HERE) <- maybe for class constant from Route?
 * @Route @CONSTANT_HERE <- global constant?
 */

The Enum gets me so far (for request method, accept-type, small collections), but for url rewriting and routing the enum would not work as it would get too long.

End quote does not typeover, but inserts

When typing out an annotation, I often get a second quote that doesn't reflect how PHPStorm typically handles quotes in the rest of the program.

For example, I typed out @Column(ty[TAB]
and the autocomplete is:

/* @Column(type="") */

Then, I type in boolean" (with the double quote at the end)

and the result is:

/* @ORM\Column(type="boolean"") */

(note the double quotes at the end of boolean)

In all other parts of PHPStorm that I can find, typing the double quote at the end would perform a typeover of the " instead of an insert so that you could easily keep typing a comma and move onto the next parameter.

working with annotation and symfony2 plugin

Hello, I like this plugin as it handles my "organize imports" problem, unfortunatly it disables the annotation-handling from your symfony2 plugin, for example clicking on @template() will go to the class now, instead of the used Template, what can i do to get the function from sf2 plugin back?

Clicking on the annotation does not highlight the corresponding `use` statement

Consider this example:

use My\BaseClass;
use My\Custom\Annotation;

/** @Annotation */
class SubClass
extends BaseClass {
}

When I click on BaseClass, either in the imports section or in the class body, both instances of the text BaseClass are highlighted. That's nice.

In contrast, when I click on @Annotation, the text Annotation in the imports section is not highlighted. It would be nice if custom annotations were highlighted the same way as regular classes.

GoTo and Inspection for Doctrine Annotations

Hi, thanks for the usefull plugin :)

Is it possible to have goto (and inspection check) for doctrine annotations target classes like repositoryClass="" or targetEntity=""?

Injecting YAML language reference into the annotation works (only for the goto), but it is of course temporary.

Doctrine: Generation of ORM indexes automatically

Add the way to generate ORM indexes with single click.
Update indexes when clicked on generated indexes entity

@ORM\Index(name="index_name", columns={"field_name"})
@ORM\Index(name="second_index_name", columns={"other_field_name"})
// other indexes ...

Full qualified classnames are not recognized as annotation

When using full qualified class names I cannot click on the name.

example: (Both annotations are not detected, but they are valid)

class User
{
    /**
     * @Doctrine\ORM\Mapping\Column(type="string")
     * @JMS\Serializer\Annotation\Groups({"main"})
     */
    private $name;
}

Setting Doctrine Repository path manual

Maybe as an improvement:

I've my doctrine repositories under a special folder, it would be nice to configure this plugin with a custom path while generate a repository that doesn't exists yet. At the moment the repository class will be generated in the same folder.

Example:
../Entity/FooEntity.php
../Repository/FooRepository.php

Greetings
Erik

[PhpStorm9] Remove deprecated method calls

Warning:(104, 48) java: C:\Users\daniel\IdeaProjects\php-annotation\src\de\espend\idea\php\annotation\annotator\AnnotationImportAnnotator.java:104: warning: [deprecation] insertUseStatement(java.lang.String,com.jetbrains.php.lang.psi.elements.PhpPsiElement) in com.jetbrains.php.lang.psi.PhpCodeEditUtil has been deprecated
Warning:(44, 32) java: C:\Users\daniel\IdeaProjects\php-annotation\src\de\espend\idea\php\annotation\util\PhpIndexUtil.java:44: warning: [deprecation] <Key,Psi>process(com.intellij.psi.stubs.StubIndexKey<Key,Psi>,Key,com.intellij.openapi.project.Project,com.intellij.psi.search.GlobalSearchScope,com.intellij.util.Processor<? super Psi>) in com.intellij.psi.stubs.StubIndex has been deprecated

MySQL syntax check interferes with Doctrine's entity referencing

What steps will reproduce the problem?

  1. Need to have PHPStorm v9 EAP
  2. Enable MySQL dialect
  3. Write a Symfony/Doctrine's createQuery query containing Entity in it

What is the expected result?
Should be accepted as a valid query.

What happens instead?
PHPStorm will mark a semi-column as error.

Thank you!

screen shot 2015-04-24 at 6 40 24 pm

Find Usages does not work with annotations

I've opened Callback constraint and tryed to find usages of this annotation (alt+F7). No any usage found. But this annotation used in many pieces of the code.

NB: Find Usages of doctrine entities works correcly - it is displays all of the getRepository calls

Problem with some class annotations that cause PhpStorm mark file in error

Using the library BazingaHateoas we have some annotation to define relations between objects. I cannot figure out why these annotations cause PHPStorm (with the PHP-Annotation plugin) warn me about an expected DOC_COMMENT_END.

The docblock:

/**
 * Class User
 *
 * @Hateoas\Relation(name="self", href=@Hateoas\Route(name="test1", parameters = { "userId"="expr(object.id)" } ))
 * @Hateoas\Relation(name="links", href=@Hateoas\Route(name="test2", parameters = { "userId"="expr(object.id)" } ), exclusion = @Hateoas\Exclusion(groups={"Own"}))
 *
 */
class Test
{
...
}

The error in PHPStorm display a red underline just after the end of the docblock.

Thanks for your help.

Class constants as arguments are not recognised as valid imports

See below. Happy to expand on this if it's not clear.

<?php

namespace Com\SomeBundle\Observer;

use Com\SomeBundle\Events\SomethingEvents; // this use statement is unrecognised, and e.g. when optimizing imports, this gets removed
use Com\SomeBundle\Event\MySomethingEvent;
use JMS\DiExtraBundle\Annotation as DI;

/**
 * @DI\Service
 */
class SomeEventObserver
{
    /**
     * @DI\Observe(SomethingEvents::PRE_UPDATE)
     */
    public function doSomething(MySomethingEvent $event)
    {
        // whatever
    }
}
<?php

namespace Com\SomeBundle\Events;

class SomethingEvents
{
    const PRE_UPDATE = 'something.pre_update';
}

Annotation that has substring doesn't get found.

Currently I'm using Symfony2's JMSDiExtraBundle and it never seems to autocomplete one of the annotations. The bundle has the annotation InjectParams and Inject, however, the latter never shows up in the autocomplete. Any ideas what's going on?

Recognize annotations spanning several lines

The following annotation is properly recognized:

/**
 * @ORM\Column(type="string", name="location")
 */

If I CTRL-hover type or name, I get the tooltip for the annotation property as expected.

However the same annotation on several lines fails to be recognized:

/**
 * @ORM\Column(
 *   type="string",
 *   name="location"
 * )
 */

This annotation is perfectly valid for Doctrine, but CTRL-hovering type or name yields nothing.

Annotations from composer deps are not autocompleted anymore

The autocompletion of annotations now includes only the annotations defined in the project, not annotations defined in composer dependencies (it used to work in the past).
This is annoying as most annotations are coming from third-party packages (Doctrine, Symfony Validator, ...)

Can't enable the plugin in PhpStorm 7.1.3

Hi there! First of all, thx for this plugin, can't wait to use it !

I try to install it on PhpStorm 7.1.3 but I can't enable the plugin. The "enable plugin" checkbox.
I have install the plugin using "Browes repositories..." in the IDE.

OS : Windows 8.1 64Bit.

Inline annotations are not recognized

Inline annotations are not recognised and will give a warning that there is no import for it. When I use the annotation in a docblock for a method or class it will work.

<?php

namespace Gadgetdude\AcmeBundle\Controller;

use Gadgetdude\AcmeBundle\Annotation\Ignore;

/**
 * @Ignore (Is resolved correctly)
 */
class TestController
{
    /**
     * @Ignore (Is resolved correctly)
     */
    public function annotationAction()
    {
        /** @Ignore (Is not resolved, results in warning) */
        return $this->doSomethingPrivate();
    }

    // ...
}

Interesting is that when the annotation is only used inline (which results in a warning) does not result in a unused warning for the use statement above.

<?php

namespace Gadgetdude\AcmeBundle\Controller;

use Gadgetdude\AcmeBundle\Annotation\Ignore; // No unused warning

class TestController
{
    public function annotationAction()
    {
        /** @Ignore (Is not resolved, results in warning) */
        return $this->doSomethingPrivate();
    }

    // ...
}

I've tested it in the last versions of PhpStorm (7.1.3, 7.1.4 and 8.0). The only other custom plugin I have enabled is the Symfony framework plugin, but I don't think that would be an issue (it never was before). The problem I'm having is a recent problem, probably introduced in 1.4 of this plugin or maybe one version earlier?

NPE is thrown after removing/adding definition of variable and GoTo Declaration action

How to reproduce:

  1. Activate plugin
  2. Create the following code:
<?php

$a = 1;
array_key_exists($a,$a);
  1. CTRL-Click on $a
  2. Remove line with
$a =1 ;
  1. Try to CTRL-Click again (nothing will happen)
  2. Add line again
  3. CTRL-Click

May be there are easier scenario to reproduce. I got the exception a couple of times.

The following exception is thrown:

null
java.lang.NullPointerException
    at de.espend.idea.php.annotation.completion.AnnotationGoToDeclarationHandler.getGotoDeclarationTargets(AnnotationGoToDeclarationHandler.java:39)
    at com.intellij.codeInsight.navigation.actions.GotoDeclarationAction.findTargetElementsNoVS(GotoDeclarationAction.java:206)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler.a(CtrlMouseHandler.java:498)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler.access$2100(CtrlMouseHandler.java:102)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler$TooltipProvider.a(CtrlMouseHandler.java:779)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler$TooltipProvider.access$2000(CtrlMouseHandler.java:726)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler$TooltipProvider$1$1.run(CtrlMouseHandler.java:769)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:947)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils$3.run(ProgressIndicatorUtils.java:62)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:207)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:57)
    at com.intellij.codeInsight.navigation.CtrlMouseHandler$TooltipProvider$1.run(CtrlMouseHandler.java:766)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:434)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
    at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:151)

[API] Provide an index with annotated elements stubs

It would be nice to provide an API for querying the collections of PhpNamedElements by annotation name. This can be useful in many places and plugins to quickly get interesting elements, for example, to find all methods, annotated with \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route, etc

Stub index should be something like this: <String, PhpNamedElement[]>

[Doctrine] Generator for entity field

As all plugins now getting code generation, we should also include some here. for example doctrine field properties of ORM classes.

Haehnchen/idea-php-symfony2-plugin#445:
A generator under the ALT+insert menu for a Doctrine entity property would be nice. Also add a option to select column type and to generate getter/setter directly.

Warnings on non-imported annotations

Depending on the configuration, you sometimes don't need to import annotations. However the plugin will add warnings on every not-imported annotation.

Would it be possible to disable this behavior, or make an option to disable it?

Auto whitespace issues

I'm getting some pretty glaring indentation problems from this plugin. Here's a GIF of them...

GIF of whitespace issues

Am I doing something wrong?

PhpStorm 10: Unused symfony2 annotations imports

Annotation imports became mark unused right after aftercompletion succeedes.

image

PhpStorm 10.0
Build #PS-143.381, built on October 31, 2015
JRE: 1.8.0_51-b16 x86
JVM: Java HotSpot(TM) Server VM by Oracle Corporation

Plugin version: 2.6.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.