http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/ZestFacetEditorTab.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/ZestFacetEditorTab.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/ZestFacetEditorTab.java new file mode 100644 index 0000000..3974bd3 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/ZestFacetEditorTab.java @@ -0,0 +1,70 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.common.facet.ui; + +import com.intellij.facet.ui.FacetEditorContext; +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.openapi.options.ConfigurationException; +import org.jetbrains.annotations.Nls; + +import javax.swing.*; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestFacetEditorTab extends FacetEditorTab +{ + private final FacetEditorContext editorContext; + + public ZestFacetEditorTab( FacetEditorContext aContext ) + { + editorContext = aContext; + } + + @Nls + public final String getDisplayName() + { + return "Zest"; + } + + public JComponent createComponent() + { + return new JPanel(); + } + + public final boolean isModified() + { + return false; + } + + public final void apply() + throws ConfigurationException + { + // From UI to configuration + } + + public final void reset() + { + // From Configuration to UI + } + + public final void disposeUIResources() + { + // Do nothing for now + } +}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractFix.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractFix.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractFix.java index c6b9893..a713d41 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractFix.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractFix.java @@ -19,7 +19,7 @@ package org.apache.zest.ide.plugin.idea.common.inspections; import com.intellij.codeInspection.LocalQuickFix; import org.jetbrains.annotations.NotNull; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; /** * @author [email protected] @@ -44,6 +44,6 @@ public abstract class AbstractFix @NotNull public final String getFamilyName() { - return message( "qi4j.quick.fixes.family.name" ); + return message( "zest.quick.fixes.family.name" ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractInspection.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractInspection.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractInspection.java index 55d59dd..cac04c0 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractInspection.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/inspections/AbstractInspection.java @@ -20,7 +20,7 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel; import com.intellij.codeInspection.BaseJavaLocalInspectionTool; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; -import org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle; +import org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle; import static com.intellij.codeHighlighting.HighlightDisplayLevel.ERROR; @@ -30,11 +30,11 @@ import static com.intellij.codeHighlighting.HighlightDisplayLevel.ERROR; */ public abstract class AbstractInspection extends BaseJavaLocalInspectionTool { - private static final String QI4J_IDEA_INSPECTIONS_NAME = "qi4j.inspections.name"; + private static final String ZEST_IDEA_INSPECTIONS_NAME = "zest.inspections.name"; @Nls @NotNull public String getGroupDisplayName() { - return Qi4jResourceBundle.message( QI4J_IDEA_INSPECTIONS_NAME ); + return ZestResourceBundle.message( ZEST_IDEA_INSPECTIONS_NAME ); } @NotNull @@ -43,7 +43,7 @@ public abstract class AbstractInspection extends BaseJavaLocalInspectionTool @Nls @NotNull public final String getDisplayName() { - return Qi4jResourceBundle.message( resourceBundlePrefixId() + ".name.display" ); + return ZestResourceBundle.message( resourceBundlePrefixId() + ".name.display" ); } @NotNull @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/intentions/AbstractIntention.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/intentions/AbstractIntention.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/intentions/AbstractIntention.java index 7bd1b9d..c1cacbe 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/intentions/AbstractIntention.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/intentions/AbstractIntention.java @@ -28,7 +28,7 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; /** * This class is based from {@code com.siyeh.ipp.base.Intention} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/Qi4jResourceBundle.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/Qi4jResourceBundle.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/Qi4jResourceBundle.java deleted file mode 100644 index 72af195..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/Qi4jResourceBundle.java +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.common.resource; - -import com.intellij.CommonBundle; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.PropertyKey; - -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jResourceBundle -{ - - @NonNls - private static final String RESOURCE_BUNDLE_NAME = "org.qi4j.ide.plugin.idea.common.resource.Qi4jResourceBundle"; - - private static Reference<ResourceBundle> BUNDLE_REF; - - private Qi4jResourceBundle() - { - } - - public static String message( @PropertyKey( resourceBundle = RESOURCE_BUNDLE_NAME ) String key, - Object... params ) - { - ResourceBundle resourceBundle = getBundle(); - return CommonBundle.message( resourceBundle, key, params ); - } - - private static ResourceBundle getBundle() - { - ResourceBundle bundle = null; - if( BUNDLE_REF != null ) - { - bundle = BUNDLE_REF.get(); - } - - if( bundle == null ) - { - bundle = ResourceBundle.getBundle( Qi4jResourceBundle.class.getName() ); - BUNDLE_REF = new SoftReference<ResourceBundle>( bundle ); - } - - return bundle; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/ZestResourceBundle.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/ZestResourceBundle.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/ZestResourceBundle.java new file mode 100644 index 0000000..b7aee52 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/ZestResourceBundle.java @@ -0,0 +1,66 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.common.resource; + +import com.intellij.CommonBundle; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.PropertyKey; + +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import java.util.ResourceBundle; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestResourceBundle +{ + + @NonNls + private static final String RESOURCE_BUNDLE_NAME = "org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle"; + + private static Reference<ResourceBundle> BUNDLE_REF; + + private ZestResourceBundle() + { + } + + public static String message( @PropertyKey( resourceBundle = RESOURCE_BUNDLE_NAME ) String key, + Object... params ) + { + ResourceBundle resourceBundle = getBundle(); + return CommonBundle.message( resourceBundle, key, params ); + } + + private static ResourceBundle getBundle() + { + ResourceBundle bundle = null; + if( BUNDLE_REF != null ) + { + bundle = BUNDLE_REF.get(); + } + + if( bundle == null ) + { + bundle = ResourceBundle.getBundle( ZestResourceBundle.class.getName() ); + BUNDLE_REF = new SoftReference<ResourceBundle>( bundle ); + } + + return bundle; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/actions/create/inPackage/CreateConcernOfInPackageAction.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/actions/create/inPackage/CreateConcernOfInPackageAction.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/actions/create/inPackage/CreateConcernOfInPackageAction.java index a171b20..b228c84 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/actions/create/inPackage/CreateConcernOfInPackageAction.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/actions/create/inPackage/CreateConcernOfInPackageAction.java @@ -32,9 +32,9 @@ import static com.intellij.openapi.actionSystem.DataKeys.PROJECT; import static com.intellij.openapi.actionSystem.DataKeys.PSI_ELEMENT; import static com.intellij.util.Icons.CLASS_ICON; import static org.apache.zest.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernConstants.TEMPLATE_GENERIC_CONCERN_OF; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernUtil.getConcernOfClass; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernConstants.TEMPLATE_GENERIC_CONCERN_OF; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernUtil.getConcernOfClass; /** * JAVADOC: Non generic concern http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernConstants.java deleted file mode 100644 index 9e1dfdd..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernConstants.java +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.concerns.common; - -import org.jetbrains.annotations.NonNls; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jConcernConstants -{ - public static final String QUALIFIED_NAME_CONCERNS = "org.qi4j.api.concern.Concerns"; - - public static final String QUALIFIED_NAME_CONCERN_OF = "org.qi4j.api.concern.ConcernOf"; - public static final String QUALIFIED_NAME_GENERIC_CONCERN = "org.qi4j.api.concern.GenericConcern"; - - @NonNls - public static final String TEMPLATE_GENERIC_CONCERN_OF = "GenericConcernOf.java"; - - private Qi4jConcernConstants() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernUtil.java deleted file mode 100644 index 45fb79d..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/Qi4jConcernUtil.java +++ /dev/null @@ -1,226 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.concerns.common; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.codeStyle.JavaCodeStyleManager; -import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; -import static java.util.Collections.emptyList; -import static org.apache.zest.ide.plugin.idea.common.psi.PsiAnnotationUtil.getAnnotationDefaultParameterValue; -import static org.apache.zest.ide.plugin.idea.common.psi.PsiAnnotationUtil.getClassReference; -import static org.apache.zest.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; -import static org.apache.zest.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernConstants.*; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jConcernUtil -{ - - - /** - * @param searchContext Search context. - * @return {@code GenericConcern} psi class if found, {@code null} otherwise. - * @since 0.1 - */ - @Nullable - public static PsiClass getGenericConcernClass( @NotNull PsiElement searchContext ) - { - Project project = searchContext.getProject(); - GlobalSearchScope searchScope = determineSearchScope( searchContext ); - return getGenericConcernClass( project, searchScope ); - } - - /** - * @param project project. - * @param scope search scope. - * @return {@code GenericConcern} psi class if found, {@code null} otherwise. - * @since 0.1 - */ - @Nullable - public static PsiClass getGenericConcernClass( @NotNull Project project, - @Nullable GlobalSearchScope scope ) - { - JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); - return scope != null ? psiFacade.findClass( QUALIFIED_NAME_GENERIC_CONCERN, scope ) : null; - } - - @Nullable - public static PsiClass getConcernOfClass( @NotNull PsiElement searchContext ) - { - Project project = searchContext.getProject(); - GlobalSearchScope searchScope = determineSearchScope( searchContext ); - return getConcernOfClass( project, searchScope ); - } - - @Nullable - public static PsiClass getConcernOfClass( @NotNull Project project, - @Nullable GlobalSearchScope scope ) - { - JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); - return scope != null ? psiFacade.findClass( QUALIFIED_NAME_CONCERN_OF, scope ) : null; - } - - @Nullable - public static PsiAnnotation getConcernsAnnotation( @NotNull PsiElement element ) - { - PsiClass psiClass = getPSIClass( element ); - return findAnnotation( psiClass, QUALIFIED_NAME_CONCERNS ); - } - - @NotNull - public static PsiAnnotation addOrReplaceConcernAnnotation( @NotNull PsiModifierListOwner modifierListOwner, - @NotNull PsiClass concernClassToAdd ) - { - Project project = modifierListOwner.getProject(); - JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); - PsiElementFactory factory = psiFacade.getElementFactory(); - PsiAnnotation existingConcernsAnnotation = findAnnotation( modifierListOwner, QUALIFIED_NAME_CONCERNS ); - - boolean isReplace = false; - PsiAnnotation newConcernsAnnotation; - if( existingConcernsAnnotation != null ) - { - // Check duplicate - List<PsiAnnotationMemberValue> concernsValues = getConcernsAnnotationValue( existingConcernsAnnotation ); - for( PsiAnnotationMemberValue concernValue : concernsValues ) - { - PsiJavaCodeReferenceElement concernClassReference = getConcernClassReference( concernValue ); - if( concernClassReference == null ) - { - continue; - } - - PsiElement concernClass = concernClassReference.resolve(); - if( concernClassToAdd.equals( concernClass ) ) - { - return existingConcernsAnnotation; - } - } - - isReplace = true; - } - - String concernAnnotationText = createConcernAnnotationText( existingConcernsAnnotation, concernClassToAdd ); - newConcernsAnnotation = - factory.createAnnotationFromText( concernAnnotationText, modifierListOwner ); - - if( isReplace ) - { - // Replace @Concerns instead - existingConcernsAnnotation.replace( newConcernsAnnotation ); - } - else - { - // @Concerns doesn't exists, add it as first child - PsiModifierList modifierList = modifierListOwner.getModifierList(); - modifierList.addBefore( newConcernsAnnotation, modifierList.getFirstChild() ); - } - - // Shorten all class references if possible - JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance( project ); - codeStyleManager.shortenClassReferences( newConcernsAnnotation ); - - return newConcernsAnnotation; - } - - @NotNull - private static String createConcernAnnotationText( @Nullable PsiAnnotation concernAnnotationBase, - @NotNull PsiClass concernClassToAdd ) - { - StringBuilder annotationTextBuilder = new StringBuilder(); - annotationTextBuilder.append( "@" ).append( QUALIFIED_NAME_CONCERNS ).append( "( {" ); - List<PsiAnnotationMemberValue> concernsAnnotationValue = getConcernsAnnotationValue( concernAnnotationBase ); - for( PsiAnnotationMemberValue concernValue : concernsAnnotationValue ) - { - annotationTextBuilder.append( concernValue.getText() ).append( ", " ); - } - annotationTextBuilder.append( concernClassToAdd.getQualifiedName() ).append( ".class" ); - annotationTextBuilder.append( "} )" ); - return annotationTextBuilder.toString(); - } - - @NotNull - public static List<PsiAnnotationMemberValue> getConcernsAnnotationValue( @Nullable PsiAnnotation concernsAnnotation ) - { - if( concernsAnnotation == null ) - { - return emptyList(); - } - - String concernsQualifiedName = concernsAnnotation.getQualifiedName(); - if( !QUALIFIED_NAME_CONCERNS.equals( concernsQualifiedName ) ) - { - return emptyList(); - } - - return getAnnotationDefaultParameterValue( concernsAnnotation ); - } - - @Nullable - public static PsiJavaCodeReferenceElement getConcernClassReference( @NotNull PsiAnnotationMemberValue value ) - { - return getClassReference( value ); - } - - /** - * @param psiClass psi class to check. - * @return {@code true} if {@code psiClass} extends {@code ConcernOf}, {@code false} if {@code psiClass} does - * not extends {@code ConcernOf} or {@code ConcernOf} is not found. - * @since 0.1 - */ - public static boolean isAConcern( @NotNull PsiClass psiClass ) - { - if( psiClass.isInterface() ) - { - return false; - } - - PsiClass concernOfClass = getConcernOfClass( psiClass ); - return concernOfClass != null && psiClass.isInheritor( concernOfClass, true ); - } - - /** - * @param psiClass psi class to check. - * @return {@code true} if {@code psiClass} extends {@code GenericConcern}, {@code false} if {@code psiClass} does - * not extends {@code GenericConcern} or {@code GenericConcern} is not found. - * @since 0.1 - */ - public static boolean isAGenericConcern( @NotNull PsiClass psiClass ) - { - if( psiClass.isInterface() ) - { - return false; - } - - PsiClass genericConcern = getGenericConcernClass( psiClass ); - return genericConcern != null && psiClass.isInheritor( genericConcern, true ); - } - - private Qi4jConcernUtil() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernConstants.java new file mode 100644 index 0000000..08934ed --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernConstants.java @@ -0,0 +1,38 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.concerns.common; + +import org.jetbrains.annotations.NonNls; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestConcernConstants +{ + public static final String QUALIFIED_NAME_CONCERNS = "org.apache.zest.api.concern.Concerns"; + + public static final String QUALIFIED_NAME_CONCERN_OF = "org.apache.zest.api.concern.ConcernOf"; + public static final String QUALIFIED_NAME_GENERIC_CONCERN = "org.apache.zest.api.concern.GenericConcern"; + + @NonNls + public static final String TEMPLATE_GENERIC_CONCERN_OF = "GenericConcernOf.java"; + + private ZestConcernConstants() + { + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernUtil.java new file mode 100644 index 0000000..c024560 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernUtil.java @@ -0,0 +1,226 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.concerns.common; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.psi.codeStyle.JavaCodeStyleManager; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; +import static java.util.Collections.emptyList; +import static org.apache.zest.ide.plugin.idea.common.psi.PsiAnnotationUtil.getAnnotationDefaultParameterValue; +import static org.apache.zest.ide.plugin.idea.common.psi.PsiAnnotationUtil.getClassReference; +import static org.apache.zest.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; +import static org.apache.zest.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernConstants.*; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestConcernUtil +{ + + + /** + * @param searchContext Search context. + * @return {@code GenericConcern} psi class if found, {@code null} otherwise. + * @since 0.1 + */ + @Nullable + public static PsiClass getGenericConcernClass( @NotNull PsiElement searchContext ) + { + Project project = searchContext.getProject(); + GlobalSearchScope searchScope = determineSearchScope( searchContext ); + return getGenericConcernClass( project, searchScope ); + } + + /** + * @param project project. + * @param scope search scope. + * @return {@code GenericConcern} psi class if found, {@code null} otherwise. + * @since 0.1 + */ + @Nullable + public static PsiClass getGenericConcernClass( @NotNull Project project, + @Nullable GlobalSearchScope scope ) + { + JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); + return scope != null ? psiFacade.findClass( QUALIFIED_NAME_GENERIC_CONCERN, scope ) : null; + } + + @Nullable + public static PsiClass getConcernOfClass( @NotNull PsiElement searchContext ) + { + Project project = searchContext.getProject(); + GlobalSearchScope searchScope = determineSearchScope( searchContext ); + return getConcernOfClass( project, searchScope ); + } + + @Nullable + public static PsiClass getConcernOfClass( @NotNull Project project, + @Nullable GlobalSearchScope scope ) + { + JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); + return scope != null ? psiFacade.findClass( QUALIFIED_NAME_CONCERN_OF, scope ) : null; + } + + @Nullable + public static PsiAnnotation getConcernsAnnotation( @NotNull PsiElement element ) + { + PsiClass psiClass = getPSIClass( element ); + return findAnnotation( psiClass, QUALIFIED_NAME_CONCERNS ); + } + + @NotNull + public static PsiAnnotation addOrReplaceConcernAnnotation( @NotNull PsiModifierListOwner modifierListOwner, + @NotNull PsiClass concernClassToAdd ) + { + Project project = modifierListOwner.getProject(); + JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); + PsiElementFactory factory = psiFacade.getElementFactory(); + PsiAnnotation existingConcernsAnnotation = findAnnotation( modifierListOwner, QUALIFIED_NAME_CONCERNS ); + + boolean isReplace = false; + PsiAnnotation newConcernsAnnotation; + if( existingConcernsAnnotation != null ) + { + // Check duplicate + List<PsiAnnotationMemberValue> concernsValues = getConcernsAnnotationValue( existingConcernsAnnotation ); + for( PsiAnnotationMemberValue concernValue : concernsValues ) + { + PsiJavaCodeReferenceElement concernClassReference = getConcernClassReference( concernValue ); + if( concernClassReference == null ) + { + continue; + } + + PsiElement concernClass = concernClassReference.resolve(); + if( concernClassToAdd.equals( concernClass ) ) + { + return existingConcernsAnnotation; + } + } + + isReplace = true; + } + + String concernAnnotationText = createConcernAnnotationText( existingConcernsAnnotation, concernClassToAdd ); + newConcernsAnnotation = + factory.createAnnotationFromText( concernAnnotationText, modifierListOwner ); + + if( isReplace ) + { + // Replace @Concerns instead + existingConcernsAnnotation.replace( newConcernsAnnotation ); + } + else + { + // @Concerns doesn't exists, add it as first child + PsiModifierList modifierList = modifierListOwner.getModifierList(); + modifierList.addBefore( newConcernsAnnotation, modifierList.getFirstChild() ); + } + + // Shorten all class references if possible + JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance( project ); + codeStyleManager.shortenClassReferences( newConcernsAnnotation ); + + return newConcernsAnnotation; + } + + @NotNull + private static String createConcernAnnotationText( @Nullable PsiAnnotation concernAnnotationBase, + @NotNull PsiClass concernClassToAdd ) + { + StringBuilder annotationTextBuilder = new StringBuilder(); + annotationTextBuilder.append( "@" ).append( QUALIFIED_NAME_CONCERNS ).append( "( {" ); + List<PsiAnnotationMemberValue> concernsAnnotationValue = getConcernsAnnotationValue( concernAnnotationBase ); + for( PsiAnnotationMemberValue concernValue : concernsAnnotationValue ) + { + annotationTextBuilder.append( concernValue.getText() ).append( ", " ); + } + annotationTextBuilder.append( concernClassToAdd.getQualifiedName() ).append( ".class" ); + annotationTextBuilder.append( "} )" ); + return annotationTextBuilder.toString(); + } + + @NotNull + public static List<PsiAnnotationMemberValue> getConcernsAnnotationValue( @Nullable PsiAnnotation concernsAnnotation ) + { + if( concernsAnnotation == null ) + { + return emptyList(); + } + + String concernsQualifiedName = concernsAnnotation.getQualifiedName(); + if( !QUALIFIED_NAME_CONCERNS.equals( concernsQualifiedName ) ) + { + return emptyList(); + } + + return getAnnotationDefaultParameterValue( concernsAnnotation ); + } + + @Nullable + public static PsiJavaCodeReferenceElement getConcernClassReference( @NotNull PsiAnnotationMemberValue value ) + { + return getClassReference( value ); + } + + /** + * @param psiClass psi class to check. + * @return {@code true} if {@code psiClass} extends {@code ConcernOf}, {@code false} if {@code psiClass} does + * not extends {@code ConcernOf} or {@code ConcernOf} is not found. + * @since 0.1 + */ + public static boolean isAConcern( @NotNull PsiClass psiClass ) + { + if( psiClass.isInterface() ) + { + return false; + } + + PsiClass concernOfClass = getConcernOfClass( psiClass ); + return concernOfClass != null && psiClass.isInheritor( concernOfClass, true ); + } + + /** + * @param psiClass psi class to check. + * @return {@code true} if {@code psiClass} extends {@code GenericConcern}, {@code false} if {@code psiClass} does + * not extends {@code GenericConcern} or {@code GenericConcern} is not found. + * @since 0.1 + */ + public static boolean isAGenericConcern( @NotNull PsiClass psiClass ) + { + if( psiClass.isInterface() ) + { + return false; + } + + PsiClass genericConcern = getGenericConcernClass( psiClass ); + return genericConcern != null && psiClass.isInheritor( genericConcern, true ); + } + + private ZestConcernUtil() + { + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/inspections/ConcernsAnnotationDeclaredCorrectlyInspection.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/inspections/ConcernsAnnotationDeclaredCorrectlyInspection.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/inspections/ConcernsAnnotationDeclaredCorrectlyInspection.java index fc598d5..9d072c0 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/inspections/ConcernsAnnotationDeclaredCorrectlyInspection.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/inspections/ConcernsAnnotationDeclaredCorrectlyInspection.java @@ -27,15 +27,15 @@ import com.intellij.psi.search.GlobalSearchScope; import org.jetbrains.annotations.NotNull; import org.apache.zest.ide.plugin.idea.common.inspections.AbstractFix; import org.apache.zest.ide.plugin.idea.common.inspections.AbstractInspection; -import org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle; +import org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle; import java.util.LinkedList; import java.util.List; import static com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING; import static org.apache.zest.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernUtil.*; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernUtil.*; /** @@ -115,7 +115,7 @@ public final class ConcernsAnnotationDeclaredCorrectlyInspection extends Abstrac // If concern class does not inherit concern class, suggest remove that reference. if( !concernClass.isInheritor( concernOfClass, true ) ) { - String message = Qi4jResourceBundle.message( + String message = ZestResourceBundle.message( "concerns.annotation.declared.correctly.error.concern.class.does.not.extend.ConcernOf", concernClass.getQualifiedName() ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/intentions/add/AddConcernOnType.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/intentions/add/AddConcernOnType.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/intentions/add/AddConcernOnType.java index 9a06c04..ab4d33c 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/intentions/add/AddConcernOnType.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/intentions/add/AddConcernOnType.java @@ -35,11 +35,11 @@ import java.util.List; import static com.intellij.psi.search.searches.ClassInheritorsSearch.search; import static java.util.Collections.emptyList; import static org.apache.zest.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernUtil.addOrReplaceConcernAnnotation; -import static org.apache.zest.ide.plugin.idea.concerns.common.Qi4jConcernUtil.getConcernOfClass; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernUtil.addOrReplaceConcernAnnotation; +import static org.apache.zest.ide.plugin.idea.concerns.common.ZestConcernUtil.getConcernOfClass; /** - * JAVADOC: This is disabled in Qi4jApplicationComponent. + * JAVADOC: This is disabled in ZestApplicationComponent. * * @author [email protected] * @since 0.1 http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/common/inspections/AbstractInjectionAnnotationDeclarationOnFieldInspection.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/common/inspections/AbstractInjectionAnnotationDeclarationOnFieldInspection.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/common/inspections/AbstractInjectionAnnotationDeclarationOnFieldInspection.java index 88b3e24..30b4c19 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/common/inspections/AbstractInjectionAnnotationDeclarationOnFieldInspection.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/common/inspections/AbstractInjectionAnnotationDeclarationOnFieldInspection.java @@ -23,6 +23,7 @@ import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiField; import com.intellij.psi.PsiModifierList; import com.intellij.psi.PsiVariable; +import org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.apache.zest.ide.plugin.idea.common.inspections.AbstractFix; @@ -109,8 +110,8 @@ public abstract class AbstractInjectionAnnotationDeclarationOnFieldInspection ex @NotNull protected String getInjectionAnnotationValidDeclarationMessage() { String annotationQualifiedName = getAnnotationToCheckQualifiedName(); - return org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message( "abstract.injection.annotation.declaration.inspection.error.annotation.not.declared.correctly", - annotationQualifiedName ); + return ZestResourceBundle.message( "abstract.injection.annotation.declaration.inspection.error.annotation.not.declared.correctly", + annotationQualifiedName ); } @NotNull http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationConstants.java deleted file mode 100644 index c2004c6..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationConstants.java +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.invocation.common; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jInvocationAnnotationConstants -{ - public static final String QUALIFIED_NAME_INVOCATION_ANNOTATION = "org.qi4j.api.injection.scope.Invocation"; - - private Qi4jInvocationAnnotationConstants() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationUtil.java deleted file mode 100644 index c7ef6da..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/Qi4jInvocationAnnotationUtil.java +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.invocation.common; - -import com.intellij.psi.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; -import static com.intellij.psi.PsiModifier.STATIC; -import static org.apache.zest.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; -import static org.apache.zest.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; -import static org.apache.zest.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult.*; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.isInjecteableByStructureAnnotation; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jInvocationAnnotationUtil -{ - /** - * Returns {@code @Invocation} annotation if exists. - * - * @param modifierListOwner modifier list owner to process. - * @return {@code @Invocation} annotation if exists, {@code null} otherwise. - * @since 0.1 - */ - @Nullable - public static PsiAnnotation getInvocationAnnotation( @NotNull PsiModifierListOwner modifierListOwner ) - { - return findAnnotation( modifierListOwner, QUALIFIED_NAME_INVOCATION_ANNOTATION ); - } - - /** - * @param psiClass psi class to check. - * @return {@code true} if the specified psiClass is injectable by invocation annotation, {@code false} otherwise. - */ - public static boolean isInjectableByInvocationAnnotation( @NotNull PsiClass psiClass ) - { - if( psiClass.isAnnotationType() ) - { - return true; - } - - String classQualifiedName = psiClass.getQualifiedName(); - return "java.lang.reflect.Method".equals( classQualifiedName ) || - "java.lang.reflect.AnnotatedElement".equals( classQualifiedName ); - } - - /** - * Validates whether the variable has {@code @Invocation} annotation declared correctly. - * - * @param variable variable to check. - * @return Look at {@link InvocationAnnotationDeclarationValidationResult}. - * @since 0.1 - */ - @NotNull - public static InvocationAnnotationDeclarationValidationResult isValidInvocationAnnotationDeclaration( - @NotNull PsiVariable variable ) - { - PsiAnnotation invocationAnnotation = getInvocationAnnotation( variable ); - if( invocationAnnotation == null ) - { - return invalidInvocationAnnotationNotDeclared; - } - - PsiModifierList modifierList = variable.getModifierList(); - if( modifierList != null ) - { - if( modifierList.hasModifierProperty( STATIC ) ) - { - return invalidDeclaredOnStaticVariable; - } - } - - // TODO: Check whether variable is either an instance of java.lang.reflect.Method or - // java.lang.reflect.AnnotatedElement or Annotation - PsiTypeElement typeElement = variable.getTypeElement(); - if( typeElement != null ) - { - PsiClass psiClass = getPSIClass( typeElement ); - if( psiClass != null ) - { - if( !isInjectableByInvocationAnnotation( psiClass ) ) - { - // Can't be type that is injected by @Structure - if( isInjecteableByStructureAnnotation( variable ) ) - { - return invalidTypeIsInjectedViaStructureAnnotation; - } - - return invalidType; - } - } - } - - return valid; - } - - public enum InvocationAnnotationDeclarationValidationResult - { - invalidInvocationAnnotationNotDeclared, - invalidDeclaredOnStaticVariable, - invalidTypeIsInjectedViaStructureAnnotation, - invalidType, - valid, - } - - private Qi4jInvocationAnnotationUtil() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationConstants.java new file mode 100644 index 0000000..d7cfa31 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationConstants.java @@ -0,0 +1,30 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.injections.invocation.common; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestInvocationAnnotationConstants +{ + public static final String QUALIFIED_NAME_INVOCATION_ANNOTATION = "org.apache.zest.api.injection.scope.Invocation"; + + private ZestInvocationAnnotationConstants() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationUtil.java new file mode 100644 index 0000000..419ec28 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationUtil.java @@ -0,0 +1,127 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.injections.invocation.common; + +import com.intellij.psi.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; +import static com.intellij.psi.PsiModifier.STATIC; +import static org.apache.zest.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; +import static org.apache.zest.ide.plugin.idea.injections.invocation.common.ZestInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; +import static org.apache.zest.ide.plugin.idea.injections.invocation.common.ZestInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult.*; +import static org.apache.zest.ide.plugin.idea.injections.structure.common.ZestStructureAnnotationUtil.isInjecteableByStructureAnnotation; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestInvocationAnnotationUtil +{ + /** + * Returns {@code @Invocation} annotation if exists. + * + * @param modifierListOwner modifier list owner to process. + * @return {@code @Invocation} annotation if exists, {@code null} otherwise. + * @since 0.1 + */ + @Nullable + public static PsiAnnotation getInvocationAnnotation( @NotNull PsiModifierListOwner modifierListOwner ) + { + return findAnnotation( modifierListOwner, QUALIFIED_NAME_INVOCATION_ANNOTATION ); + } + + /** + * @param psiClass psi class to check. + * @return {@code true} if the specified psiClass is injectable by invocation annotation, {@code false} otherwise. + */ + public static boolean isInjectableByInvocationAnnotation( @NotNull PsiClass psiClass ) + { + if( psiClass.isAnnotationType() ) + { + return true; + } + + String classQualifiedName = psiClass.getQualifiedName(); + return "java.lang.reflect.Method".equals( classQualifiedName ) || + "java.lang.reflect.AnnotatedElement".equals( classQualifiedName ); + } + + /** + * Validates whether the variable has {@code @Invocation} annotation declared correctly. + * + * @param variable variable to check. + * @return Look at {@link InvocationAnnotationDeclarationValidationResult}. + * @since 0.1 + */ + @NotNull + public static InvocationAnnotationDeclarationValidationResult isValidInvocationAnnotationDeclaration( + @NotNull PsiVariable variable ) + { + PsiAnnotation invocationAnnotation = getInvocationAnnotation( variable ); + if( invocationAnnotation == null ) + { + return invalidInvocationAnnotationNotDeclared; + } + + PsiModifierList modifierList = variable.getModifierList(); + if( modifierList != null ) + { + if( modifierList.hasModifierProperty( STATIC ) ) + { + return invalidDeclaredOnStaticVariable; + } + } + + // TODO: Check whether variable is either an instance of java.lang.reflect.Method or + // java.lang.reflect.AnnotatedElement or Annotation + PsiTypeElement typeElement = variable.getTypeElement(); + if( typeElement != null ) + { + PsiClass psiClass = getPSIClass( typeElement ); + if( psiClass != null ) + { + if( !isInjectableByInvocationAnnotation( psiClass ) ) + { + // Can't be type that is injected by @Structure + if( isInjecteableByStructureAnnotation( variable ) ) + { + return invalidTypeIsInjectedViaStructureAnnotation; + } + + return invalidType; + } + } + } + + return valid; + } + + public enum InvocationAnnotationDeclarationValidationResult + { + invalidInvocationAnnotationNotDeclared, + invalidDeclaredOnStaticVariable, + invalidTypeIsInjectedViaStructureAnnotation, + invalidType, + valid, + } + + private ZestInvocationAnnotationUtil() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/inspections/InvocationAnnotationDeclaredCorrectlyInspection.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/inspections/InvocationAnnotationDeclaredCorrectlyInspection.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/inspections/InvocationAnnotationDeclaredCorrectlyInspection.java index 57e9b60..155dd61 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/inspections/InvocationAnnotationDeclaredCorrectlyInspection.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/inspections/InvocationAnnotationDeclaredCorrectlyInspection.java @@ -27,11 +27,11 @@ import org.apache.zest.ide.plugin.idea.injections.common.inspections.AbstractInj import org.apache.zest.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation; import static com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; -import static org.apache.zest.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; -import static org.apache.zest.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult; -import static org.apache.zest.ide.plugin.idea.injections.invocation.common.Qi4jInvocationAnnotationUtil.isValidInvocationAnnotationDeclaration; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.getStructureAnnotation; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.injections.invocation.common.ZestInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; +import static org.apache.zest.ide.plugin.idea.injections.invocation.common.ZestInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult; +import static org.apache.zest.ide.plugin.idea.injections.invocation.common.ZestInvocationAnnotationUtil.isValidInvocationAnnotationDeclaration; +import static org.apache.zest.ide.plugin.idea.injections.structure.common.ZestStructureAnnotationUtil.getStructureAnnotation; /** * {@code InvocationAnnotationDeclaredCorrectlyInspection} validates {@code @Invocation} injection annotation http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationConstants.java deleted file mode 100644 index 4ab8602..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationConstants.java +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.service.common; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jServiceAnnotationConstants -{ - public static final String QUALIFIED_NAME_SERVICE_ANNOTATION = "org.qi4j.api.injection.scope.Service"; - - private Qi4jServiceAnnotationConstants() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationUtil.java deleted file mode 100644 index 824466c..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/Qi4jServiceAnnotationUtil.java +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.service.common; - -import com.intellij.psi.PsiAnnotation; -import com.intellij.psi.PsiModifierList; -import com.intellij.psi.PsiModifierListOwner; -import com.intellij.psi.PsiVariable; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; -import static com.intellij.psi.PsiModifier.STATIC; -import static org.apache.zest.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationConstants.QUALIFIED_NAME_SERVICE_ANNOTATION; -import static org.apache.zest.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult.*; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.isInjecteableByStructureAnnotation; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jServiceAnnotationUtil -{ - /** - * Returns {@code @Service} annotation if exists. - * - * @param modifierListOwner modifier list owner to process. - * @return {@code @Service} annotation if exists, {@code null} otherwise. - * @since 0.1 - */ - @Nullable - public static PsiAnnotation getServiceAnnotation( @NotNull PsiModifierListOwner modifierListOwner ) - { - return findAnnotation( modifierListOwner, QUALIFIED_NAME_SERVICE_ANNOTATION ); - } - - /** - * Validates whether the variable has {@code @Service} annotation declared correctly. - * - * @param variable variable to check. - * @return Look at {@link ServiceAnnotationDeclarationValidationResult}. - * @since 0.1 - */ - @NotNull - public static ServiceAnnotationDeclarationValidationResult isValidServiceAnnotationDeclaration( - @NotNull PsiVariable variable ) - { - PsiAnnotation serviceAnnotation = getServiceAnnotation( variable ); - if( serviceAnnotation == null ) - { - return invalidServiceAnnotationNotDeclared; - } - - PsiModifierList modifierList = variable.getModifierList(); - if( modifierList != null ) - { - if( modifierList.hasModifierProperty( STATIC ) ) - { - return invalidDeclaredOnStaticVariable; - } - } - - // Can't be type that is injected by @Structure - if( isInjecteableByStructureAnnotation( variable ) ) - { - return invalidTypeIsInjectedViaStructureAnnotation; - } - - return valid; - } - - public enum ServiceAnnotationDeclarationValidationResult - { - invalidServiceAnnotationNotDeclared, - invalidDeclaredOnStaticVariable, - invalidTypeIsInjectedViaStructureAnnotation, - valid, - } - - private Qi4jServiceAnnotationUtil() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationConstants.java new file mode 100644 index 0000000..156bb39 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationConstants.java @@ -0,0 +1,30 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.injections.service.common; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestServiceAnnotationConstants +{ + public static final String QUALIFIED_NAME_SERVICE_ANNOTATION = "org.apache.zest.api.injection.scope.Service"; + + private ZestServiceAnnotationConstants() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationUtil.java new file mode 100644 index 0000000..4fdd2b0 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/ZestServiceAnnotationUtil.java @@ -0,0 +1,97 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.injections.service.common; + +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiModifierList; +import com.intellij.psi.PsiModifierListOwner; +import com.intellij.psi.PsiVariable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; +import static com.intellij.psi.PsiModifier.STATIC; +import static org.apache.zest.ide.plugin.idea.injections.service.common.ZestServiceAnnotationConstants.QUALIFIED_NAME_SERVICE_ANNOTATION; +import static org.apache.zest.ide.plugin.idea.injections.service.common.ZestServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult.*; +import static org.apache.zest.ide.plugin.idea.injections.structure.common.ZestStructureAnnotationUtil.isInjecteableByStructureAnnotation; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestServiceAnnotationUtil +{ + /** + * Returns {@code @Service} annotation if exists. + * + * @param modifierListOwner modifier list owner to process. + * @return {@code @Service} annotation if exists, {@code null} otherwise. + * @since 0.1 + */ + @Nullable + public static PsiAnnotation getServiceAnnotation( @NotNull PsiModifierListOwner modifierListOwner ) + { + return findAnnotation( modifierListOwner, QUALIFIED_NAME_SERVICE_ANNOTATION ); + } + + /** + * Validates whether the variable has {@code @Service} annotation declared correctly. + * + * @param variable variable to check. + * @return Look at {@link ServiceAnnotationDeclarationValidationResult}. + * @since 0.1 + */ + @NotNull + public static ServiceAnnotationDeclarationValidationResult isValidServiceAnnotationDeclaration( + @NotNull PsiVariable variable ) + { + PsiAnnotation serviceAnnotation = getServiceAnnotation( variable ); + if( serviceAnnotation == null ) + { + return invalidServiceAnnotationNotDeclared; + } + + PsiModifierList modifierList = variable.getModifierList(); + if( modifierList != null ) + { + if( modifierList.hasModifierProperty( STATIC ) ) + { + return invalidDeclaredOnStaticVariable; + } + } + + // Can't be type that is injected by @Structure + if( isInjecteableByStructureAnnotation( variable ) ) + { + return invalidTypeIsInjectedViaStructureAnnotation; + } + + return valid; + } + + public enum ServiceAnnotationDeclarationValidationResult + { + invalidServiceAnnotationNotDeclared, + invalidDeclaredOnStaticVariable, + invalidTypeIsInjectedViaStructureAnnotation, + valid, + } + + private ZestServiceAnnotationUtil() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/inspections/ServiceAnnotationDeclaredCorrectlyInspection.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/inspections/ServiceAnnotationDeclaredCorrectlyInspection.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/inspections/ServiceAnnotationDeclaredCorrectlyInspection.java index be3a82b..c078a1b 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/inspections/ServiceAnnotationDeclaredCorrectlyInspection.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/inspections/ServiceAnnotationDeclaredCorrectlyInspection.java @@ -27,11 +27,11 @@ import org.apache.zest.ide.plugin.idea.injections.common.inspections.AbstractInj import org.apache.zest.ide.plugin.idea.injections.structure.common.ReplaceWithStructureAnnotation; import static com.intellij.codeInspection.ProblemHighlightType.GENERIC_ERROR_OR_WARNING; -import static org.apache.zest.ide.plugin.idea.common.resource.Qi4jResourceBundle.message; -import static org.apache.zest.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationConstants.QUALIFIED_NAME_SERVICE_ANNOTATION; -import static org.apache.zest.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult; -import static org.apache.zest.ide.plugin.idea.injections.service.common.Qi4jServiceAnnotationUtil.isValidServiceAnnotationDeclaration; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.getStructureAnnotation; +import static org.apache.zest.ide.plugin.idea.common.resource.ZestResourceBundle.message; +import static org.apache.zest.ide.plugin.idea.injections.service.common.ZestServiceAnnotationConstants.QUALIFIED_NAME_SERVICE_ANNOTATION; +import static org.apache.zest.ide.plugin.idea.injections.service.common.ZestServiceAnnotationUtil.ServiceAnnotationDeclarationValidationResult; +import static org.apache.zest.ide.plugin.idea.injections.service.common.ZestServiceAnnotationUtil.isValidServiceAnnotationDeclaration; +import static org.apache.zest.ide.plugin.idea.injections.structure.common.ZestStructureAnnotationUtil.getStructureAnnotation; /** * {@code ServiceAnnotationDeclaredCorrectly} validates {@code @Service} injection annotation declaration. http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationConstants.java deleted file mode 100644 index 9635ad4..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationConstants.java +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.structure.common; - -import static java.util.Arrays.sort; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jStructureAnnotationConstants -{ - public static final String QUALIFIED_NAME_STRUCTURE_ANNOTATION = "org.qi4j.api.injection.scope.Structure"; - - public static final String[] VALID_STRUCTURE_INJECTION_TYPE; - - static - { - VALID_STRUCTURE_INJECTION_TYPE = new String[] - { - "org.qi4j.composite.CompositeBuilderFactory", - "org.qi4j.object.ObjectBuilderFactory", - "org.qi4j.entity.UnitOfWorkFactory", - "org.qi4j.service.ServiceFinder", - "org.qi4j.structure.Module", - "org.qi4j.structure.Layer", - "org.qi4j.structure.Application", - "org.qi4j.Qi4j", - "org.qi4j.spi.Qi4jSPI" - }; - sort( VALID_STRUCTURE_INJECTION_TYPE ); - } - - private Qi4jStructureAnnotationConstants() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationUtil.java deleted file mode 100644 index da54dd9..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/Qi4jStructureAnnotationUtil.java +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright 2008 Edward Yakop. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -* implied. -* -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package org.apache.zest.ide.plugin.idea.injections.structure.common; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; -import static com.intellij.psi.PsiModifier.STATIC; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationConstants.QUALIFIED_NAME_STRUCTURE_ANNOTATION; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationConstants.VALID_STRUCTURE_INJECTION_TYPE; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.StructureAnnotationDeclarationValidationResult.*; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class Qi4jStructureAnnotationUtil -{ - /** - * Returns {@code Structure} annotation if exists. - * - * @param modifierListOwner Modifier list owner. - * @return @Structure annotation if exists, {@code null} otherwise. - * @since 0.1 - */ - @Nullable - public static PsiAnnotation getStructureAnnotation( @NotNull PsiModifierListOwner modifierListOwner ) - { - return findAnnotation( modifierListOwner, QUALIFIED_NAME_STRUCTURE_ANNOTATION ); - } - - /** - * Create structure annotation. - * - * @param project project to create structure annotation. - * @param context the context to create structure annotation. - * @return @Structure annotation. - */ - @NotNull - public static PsiAnnotation createStructureAnnotation( @NotNull Project project, - @NotNull PsiElement context ) - { - JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); - PsiElementFactory factory = psiFacade.getElementFactory(); - return factory.createAnnotationFromText( "@" + QUALIFIED_NAME_STRUCTURE_ANNOTATION, context ); - } - - /** - * @param variable variable to check. - * @return Look at {@link StructureAnnotationDeclarationValidationResult}. - * @since 0.1 - */ - @NotNull - public static StructureAnnotationDeclarationValidationResult validateStructureAnnotationDeclaration( - @NotNull PsiVariable variable ) - { - PsiAnnotation structureAnnotation = getStructureAnnotation( variable ); - if( structureAnnotation == null ) - { - return invalidStructureAnnotationNotDeclared; - } - - PsiModifierList modifierList = variable.getModifierList(); - if( modifierList != null ) - { - if( modifierList.hasModifierProperty( STATIC ) ) - { - return invalidDeclaredOnStaticVariable; - } - } - - if( !isInjecteableByStructureAnnotation( variable ) ) - { - return invalidInjectionType; - } - - return valid; - } - - /** - * Returns a {@code boolean} indicator whether variable type is injectable by @Structure annotation. - * - * @param variable variable to check. - * @return {@code true} if variable type is injecteable by @Structure annotation. - * @since 0.1 - */ - public static boolean isInjecteableByStructureAnnotation( @NotNull PsiVariable variable ) - { - PsiType type = variable.getType(); - String fieldClassQualifiedName = type.getCanonicalText(); - return binarySearch( VALID_STRUCTURE_INJECTION_TYPE, fieldClassQualifiedName ) > -1; - } - - private Qi4jStructureAnnotationUtil() - { - } - - public enum StructureAnnotationDeclarationValidationResult - { - invalidStructureAnnotationNotDeclared, - invalidDeclaredOnStaticVariable, - invalidInjectionType, - valid, - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ReplaceWithStructureAnnotation.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ReplaceWithStructureAnnotation.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ReplaceWithStructureAnnotation.java index 3cd6fb6..14a47f9 100644 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ReplaceWithStructureAnnotation.java +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ReplaceWithStructureAnnotation.java @@ -22,7 +22,7 @@ import com.intellij.psi.PsiAnnotation; import org.jetbrains.annotations.NotNull; import org.apache.zest.ide.plugin.idea.common.inspections.AbstractFix; -import static org.apache.zest.ide.plugin.idea.injections.structure.common.Qi4jStructureAnnotationUtil.createStructureAnnotation; +import static org.apache.zest.ide.plugin.idea.injections.structure.common.ZestStructureAnnotationUtil.createStructureAnnotation; /** * @author [email protected] http://git-wip-us.apache.org/repos/asf/zest-java/blob/95d31c05/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ZestStructureAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ZestStructureAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ZestStructureAnnotationConstants.java new file mode 100644 index 0000000..fd42df5 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/structure/common/ZestStructureAnnotationConstants.java @@ -0,0 +1,51 @@ +/* Copyright 2008 Edward Yakop. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +* implied. +* +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.zest.ide.plugin.idea.injections.structure.common; + +import static java.util.Arrays.sort; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class ZestStructureAnnotationConstants +{ + public static final String QUALIFIED_NAME_STRUCTURE_ANNOTATION = "org.apache.zest.api.injection.scope.Structure"; + + public static final String[] VALID_STRUCTURE_INJECTION_TYPE; + + static + { + VALID_STRUCTURE_INJECTION_TYPE = new String[] + { + "org.apache.zest.composite.CompositeBuilderFactory", + "org.apache.zest.object.ObjectBuilderFactory", + "org.apache.zest.entity.UnitOfWorkFactory", + "org.apache.zest.service.ServiceFinder", + "org.apache.zest.structure.Module", + "org.apache.zest.structure.Layer", + "org.apache.zest.structure.Application", + "org.apache.zest.ZestAPI", + "org.apache.zest.spi.ZestSPI" + }; + sort( VALID_STRUCTURE_INJECTION_TYPE ); + } + + private ZestStructureAnnotationConstants() + { + } +}
