-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ttps://www.doctrine-project.org/projects/doctrine-annotations/en/latest/custom.html#attribute-types)
- Loading branch information
Showing
11 changed files
with
265 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
src/main/java/de/espend/idea/php/annotation/dict/AnnotationPropertyEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
package de.espend.idea.php.annotation.dict; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public enum AnnotationPropertyEnum { | ||
ARRAY, STRING, INTEGER, BOOLEAN | ||
ARRAY, STRING, INTEGER, BOOLEAN, UNKNOWN; | ||
|
||
public static AnnotationPropertyEnum fromString(@NotNull String value) { | ||
if (value.equalsIgnoreCase("string")) { | ||
return STRING; | ||
} | ||
|
||
if (value.equalsIgnoreCase("array")) { | ||
return ARRAY; | ||
} | ||
|
||
if (value.equalsIgnoreCase("integer") || value.equalsIgnoreCase("int")) { | ||
return INTEGER; | ||
} | ||
|
||
if (value.equalsIgnoreCase("boolean") || value.equalsIgnoreCase("bool")) { | ||
return BOOLEAN; | ||
} | ||
|
||
return UNKNOWN; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/de/espend/idea/php/annotation/dict/PhpDocTagAnnotationNonReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package de.espend.idea.php.annotation.dict; | ||
|
||
import com.jetbrains.php.lang.documentation.phpdoc.parser.PhpDocElementTypes; | ||
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag; | ||
import com.jetbrains.php.lang.psi.elements.PhpPsiElement; | ||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; | ||
import de.espend.idea.php.annotation.pattern.AnnotationPattern; | ||
import de.espend.idea.php.annotation.util.PhpElementsUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class PhpDocTagAnnotationNonReference { | ||
final private PhpDocTag phpDocTag; | ||
|
||
public PhpDocTagAnnotationNonReference(@NotNull PhpDocTag phpDocTag) { | ||
this.phpDocTag = phpDocTag; | ||
} | ||
|
||
@NotNull | ||
public PhpDocTag getPhpDocTag() { | ||
return phpDocTag; | ||
} | ||
|
||
/** | ||
* Get property Value from "@Template(template="foo"); | ||
* | ||
* @param propertyName property name template="" | ||
* @return Property value | ||
*/ | ||
@Nullable | ||
public String getPropertyValue(String propertyName) { | ||
StringLiteralExpression literalExpression = getPropertyValuePsi(propertyName); | ||
if(literalExpression != null) { | ||
return literalExpression.getContents(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get property psi element | ||
* | ||
* @param propertyName property name template="" | ||
* @return Property value | ||
*/ | ||
@Nullable | ||
public StringLiteralExpression getPropertyValuePsi(String propertyName) { | ||
PhpPsiElement docAttrList = phpDocTag.getFirstPsiChild(); | ||
if(docAttrList != null) { | ||
return PhpElementsUtil.getChildrenOnPatternMatch(docAttrList, AnnotationPattern.getPropertyIdentifierValue(propertyName)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get default property value from annotation "@Template("foo"); | ||
* | ||
* @return Content of property value literal | ||
*/ | ||
@Nullable | ||
public String getDefaultPropertyValue() { | ||
PhpPsiElement phpDocAttrList = phpDocTag.getFirstPsiChild(); | ||
|
||
if(phpDocAttrList != null) { | ||
if(phpDocAttrList.getNode().getElementType() == PhpDocElementTypes.phpDocAttributeList) { | ||
PhpPsiElement phpPsiElement = phpDocAttrList.getFirstPsiChild(); | ||
if(phpPsiElement instanceof StringLiteralExpression) { | ||
return ((StringLiteralExpression) phpPsiElement).getContents(); | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.