http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/appliesTo/common/ZestAppliesToUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/appliesTo/common/ZestAppliesToUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/appliesTo/common/ZestAppliesToUtil.java deleted file mode 100644 index fd56b6b..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/appliesTo/common/ZestAppliesToUtil.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.appliesTo.common; - -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; - -import static com.intellij.codeInsight.AnnotationUtil.findAnnotation; -import static java.util.Collections.emptyList; -import static org.apache.polygene.ide.plugin.idea.appliesTo.common.PolygeneAppliesToConstants.QUALIFIED_NAME_APPLIES_TO; -import static org.apache.polygene.ide.plugin.idea.appliesTo.common.PolygeneAppliesToConstants.QUALIFIED_NAME_APPLIES_TO_FILTER; -import static org.apache.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getAnnotationDefaultParameterValue; -import static org.apache.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getClassReference; -import static org.apache.polygene.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; -import static org.apache.polygene.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneAppliesToUtil -{ - /** - * @param searchContext Search context. - * @return {@code AppliesToFilter} class given the search context. {@code null} if not found. - * @since 0.1 - */ - @Nullable - public static PsiClass getAppliesToFilterClass( @NotNull PsiElement searchContext ) - { - Project project = searchContext.getProject(); - GlobalSearchScope searchScope = determineSearchScope( searchContext ); - return getAppliesToFilterClass( project, searchScope ); - } - - /** - * @param project project. - * @param scope search scope. - * @return {@code AppliesToFilter} class given {@code project} and {@code scope} parameters. - * Returns {@code null} if not found. - * @since 0.1 - */ - @Nullable - public static PsiClass getAppliesToFilterClass( @NotNull Project project, - @Nullable GlobalSearchScope scope ) - { - JavaPsiFacade psiFacade = JavaPsiFacade.getInstance( project ); - return scope == null ? null : psiFacade.findClass( QUALIFIED_NAME_APPLIES_TO_FILTER, scope ); - } - - /** - * @param elementWithinJavaClass element within java class. - * @return {@code @AppliesTo} annotation declaration of the class that contains the element. - * Returns {@code null} if not found, or {@code element} is an invalid context. - * @since 0.1 - */ - @Nullable - public static PsiAnnotation getAppliesToAnnotation( @NotNull PsiElement elementWithinJavaClass ) - { - PsiClass psiClass = getPSIClass( elementWithinJavaClass ); - return findAnnotation( psiClass, QUALIFIED_NAME_APPLIES_TO ); - } - - /** - * @param annotation annotation to process. - * @return {@code @AppliesTo} annotation value. Returns {@link Collections#emptyList()} if {@code annotation} is - * {@code null} or annotation is not a {@code @AppliesTo} annotation. - * @since 0.1 - */ - @NotNull - public static List<PsiAnnotationMemberValue> getAppliesToAnnotationValue( @Nullable PsiAnnotation annotation ) - { - if( annotation == null ) - { - return emptyList(); - } - - String concernsQualifiedName = annotation.getQualifiedName(); - if( !QUALIFIED_NAME_APPLIES_TO.equals( concernsQualifiedName ) ) - { - return emptyList(); - } - - return getAnnotationDefaultParameterValue( annotation ); - } - - /** - * @param value annotation member value. - * @return Applies to class reference given the {@code value} parameter. Returns {@code null} if it's not a - * class reference. - * @since 0.1 - */ - @Nullable - public static PsiJavaCodeReferenceElement getAppliesToValueClassReference( @NotNull PsiAnnotationMemberValue value ) - { - return getClassReference( value ); - } - - /** - * Returns a {@code boolean} indicator whether the specified {@code psiClass} is implements - * {@code AppliesToFilter} class. - * - * @param psiClass class to check. - * @param appliesToFilterClass {@code AppliesToFilter} class. - * @return {@code true} if {@code psiClass} implements {@code AppliesToFilter} class, {@code false} otherwise. - * @since 0.1 - */ - public static boolean isAnAppliesToFilter( @NotNull PsiClass psiClass, @NotNull PsiClass appliesToFilterClass ) - { - return !psiClass.isInterface() && psiClass.isInheritor( appliesToFilterClass, true ); - } - - private PolygeneAppliesToUtil() - { - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/PolygeneCreateActionGroup.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/PolygeneCreateActionGroup.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/PolygeneCreateActionGroup.java new file mode 100644 index 0000000..d53e0e1 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/PolygeneCreateActionGroup.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.common.actions; + +import com.intellij.ide.IdeView; +import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.psi.JavaDirectoryService; +import com.intellij.psi.PsiDirectory; + +import static org.apache.polygene.ide.plugin.idea.common.resource.PolygeneResourceBundle.message; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneCreateActionGroup extends DefaultActionGroup +{ + public PolygeneCreateActionGroup() + { + super( message( "polygene.action.group.title" ), true ); + getTemplatePresentation().setDescription( message( "polygene.action.group.description" ) ); + } + + public void update( AnActionEvent e ) + { + Presentation presentation = e.getPresentation(); + presentation.setVisible( shouldActionGroupVisible( e ) ); + } + + private boolean shouldActionGroupVisible( AnActionEvent e ) + { + Module module = e.getData( LangDataKeys.MODULE ); + if( module == null ) + { + return false; + } + + // TODO: Enable this once PolygeneFacet can be automatically added/removed +// if( PolygeneFacet.getInstance( module ) == null ) +// { +// return false; +// } + + // Are we on IDE View and under project source folder? + Project project = e.getData( PlatformDataKeys.PROJECT ); + IdeView view = e.getData( LangDataKeys.IDE_VIEW ); + if( view != null && project != null ) + { + ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance( project ).getFileIndex(); + PsiDirectory[] dirs = view.getDirectories(); + for( PsiDirectory dir : dirs ) + { + if( projectFileIndex.isInSourceContent( dir.getVirtualFile() ) && JavaDirectoryService.getInstance().getPackage( dir ) != null ) + { + return true; + } + } + } + + return false; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/ZestCreateActionGroup.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/ZestCreateActionGroup.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/ZestCreateActionGroup.java deleted file mode 100644 index d53e0e1..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/actions/ZestCreateActionGroup.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.common.actions; - -import com.intellij.ide.IdeView; -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.roots.ProjectRootManager; -import com.intellij.psi.JavaDirectoryService; -import com.intellij.psi.PsiDirectory; - -import static org.apache.polygene.ide.plugin.idea.common.resource.PolygeneResourceBundle.message; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneCreateActionGroup extends DefaultActionGroup -{ - public PolygeneCreateActionGroup() - { - super( message( "polygene.action.group.title" ), true ); - getTemplatePresentation().setDescription( message( "polygene.action.group.description" ) ); - } - - public void update( AnActionEvent e ) - { - Presentation presentation = e.getPresentation(); - presentation.setVisible( shouldActionGroupVisible( e ) ); - } - - private boolean shouldActionGroupVisible( AnActionEvent e ) - { - Module module = e.getData( LangDataKeys.MODULE ); - if( module == null ) - { - return false; - } - - // TODO: Enable this once PolygeneFacet can be automatically added/removed -// if( PolygeneFacet.getInstance( module ) == null ) -// { -// return false; -// } - - // Are we on IDE View and under project source folder? - Project project = e.getData( PlatformDataKeys.PROJECT ); - IdeView view = e.getData( LangDataKeys.IDE_VIEW ); - if( view != null && project != null ) - { - ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance( project ).getFileIndex(); - PsiDirectory[] dirs = view.getDirectories(); - for( PsiDirectory dir : dirs ) - { - if( projectFileIndex.isInSourceContent( dir.getVirtualFile() ) && JavaDirectoryService.getInstance().getPackage( dir ) != null ) - { - return true; - } - } - } - - return false; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacet.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacet.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacet.java new file mode 100644 index 0000000..7342707 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacet.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.common.facet; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetManager; +import com.intellij.facet.FacetType; +import com.intellij.openapi.module.Module; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneFacet extends Facet<PolygeneFacetConfiguration> +{ + public PolygeneFacet( @NotNull FacetType facetType, + @NotNull Module module, + String name, + @NotNull PolygeneFacetConfiguration configuration, + Facet underlyingFacet + ) + { + super( facetType, module, name, configuration, underlyingFacet ); + } + + @Nullable + public static PolygeneFacet getInstance( @NotNull Module module ) + { + return FacetManager.getInstance( module ).getFacetByType( PolygeneFacetType.ID ); + } + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetConfiguration.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetConfiguration.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetConfiguration.java new file mode 100644 index 0000000..6a6f28e --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetConfiguration.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.common.facet; + +import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.ui.FacetEditorContext; +import com.intellij.facet.ui.FacetEditorTab; +import com.intellij.facet.ui.FacetValidatorsManager; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.openapi.util.WriteExternalException; +import org.jdom.Element; +import org.apache.polygene.ide.plugin.idea.common.facet.ui.PolygeneFacetEditorTab; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneFacetConfiguration + implements FacetConfiguration +{ + public FacetEditorTab[] createEditorTabs( FacetEditorContext editorContext, + FacetValidatorsManager validatorsManager ) + { + return new FacetEditorTab[]{ + new PolygeneFacetEditorTab( editorContext ) + }; + } + + public final void readExternal( Element element ) + throws InvalidDataException + { + // Do nothing + } + + public final void writeExternal( Element element ) + throws WriteExternalException + { + // Do nothing + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetType.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetType.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetType.java new file mode 100644 index 0000000..b45de9f --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/PolygeneFacetType.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.common.facet; + +import com.intellij.facet.Facet; +import com.intellij.facet.FacetType; +import com.intellij.facet.FacetTypeId; +import com.intellij.facet.autodetecting.FacetDetector; +import com.intellij.facet.autodetecting.FacetDetectorRegistry; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.module.JavaModuleType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFileFilter; +import com.intellij.psi.JavaElementVisitor; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiImportStatement; +import com.intellij.psi.PsiReferenceExpression; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneFacetType extends FacetType<PolygeneFacet, PolygeneFacetConfiguration> +{ + public static final FacetTypeId<PolygeneFacet> ID = new FacetTypeId<PolygeneFacet>(); + + public PolygeneFacetType() + { + super( ID, "PolygeneFacet", "Polygene Facet" ); + } + + public final PolygeneFacetConfiguration createDefaultConfiguration() + { + return new PolygeneFacetConfiguration(); + } + + public final PolygeneFacet createFacet( @NotNull Module module, + String name, + @NotNull PolygeneFacetConfiguration configuration, + @Nullable Facet underlyingFacet ) + { + return new PolygeneFacet( this, module, name, configuration, underlyingFacet ); + } + + public final boolean isSuitableModuleType( ModuleType moduleType ) + { + return moduleType instanceof JavaModuleType; + } + + @Override + public final void registerDetectors( FacetDetectorRegistry<PolygeneFacetConfiguration> registry ) + { + registry.registerOnTheFlyDetector( + StdFileTypes.JAVA, VirtualFileFilter.ALL, new HasPolygeneImportPackageCondition(), + new FacetDetector<PsiFile, PolygeneFacetConfiguration>( "PolygeneFacetDetector" ) + { + @Override + public PolygeneFacetConfiguration detectFacet( PsiFile source, + Collection<PolygeneFacetConfiguration> existingConfigurations ) + { + if( !existingConfigurations.isEmpty() ) + { + return existingConfigurations.iterator().next(); + } + + return createDefaultConfiguration(); + } + } + ); + } + + private static class HasPolygeneImportPackageCondition + implements Condition<PsiFile> + { + public final boolean value( PsiFile psiFile ) + { + final boolean[] hasPolygeneImportPackage = new boolean[]{ false }; + + psiFile.accept( new JavaElementVisitor() + { + @Override + public final void visitImportStatement( PsiImportStatement statement ) + { + String packageName = statement.getQualifiedName(); + if( packageName != null && packageName.startsWith( "org.apache.polygene" ) ) + { + hasPolygeneImportPackage[ 0 ] = true; + } + } + + @Override + public void visitReferenceExpression( PsiReferenceExpression expression ) + { + // Ignore + } + } ); + return hasPolygeneImportPackage[ 0 ]; + } + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacet.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacet.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacet.java deleted file mode 100644 index 7342707..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacet.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.common.facet; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetManager; -import com.intellij.facet.FacetType; -import com.intellij.openapi.module.Module; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneFacet extends Facet<PolygeneFacetConfiguration> -{ - public PolygeneFacet( @NotNull FacetType facetType, - @NotNull Module module, - String name, - @NotNull PolygeneFacetConfiguration configuration, - Facet underlyingFacet - ) - { - super( facetType, module, name, configuration, underlyingFacet ); - } - - @Nullable - public static PolygeneFacet getInstance( @NotNull Module module ) - { - return FacetManager.getInstance( module ).getFacetByType( PolygeneFacetType.ID ); - } - -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetConfiguration.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetConfiguration.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetConfiguration.java deleted file mode 100644 index 6a6f28e..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.common.facet; - -import com.intellij.facet.FacetConfiguration; -import com.intellij.facet.ui.FacetEditorContext; -import com.intellij.facet.ui.FacetEditorTab; -import com.intellij.facet.ui.FacetValidatorsManager; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; -import org.jdom.Element; -import org.apache.polygene.ide.plugin.idea.common.facet.ui.PolygeneFacetEditorTab; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneFacetConfiguration - implements FacetConfiguration -{ - public FacetEditorTab[] createEditorTabs( FacetEditorContext editorContext, - FacetValidatorsManager validatorsManager ) - { - return new FacetEditorTab[]{ - new PolygeneFacetEditorTab( editorContext ) - }; - } - - public final void readExternal( Element element ) - throws InvalidDataException - { - // Do nothing - } - - public final void writeExternal( Element element ) - throws WriteExternalException - { - // Do nothing - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetType.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetType.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetType.java deleted file mode 100644 index b45de9f..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ZestFacetType.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.common.facet; - -import com.intellij.facet.Facet; -import com.intellij.facet.FacetType; -import com.intellij.facet.FacetTypeId; -import com.intellij.facet.autodetecting.FacetDetector; -import com.intellij.facet.autodetecting.FacetDetectorRegistry; -import com.intellij.openapi.fileTypes.StdFileTypes; -import com.intellij.openapi.module.JavaModuleType; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.vfs.VirtualFileFilter; -import com.intellij.psi.JavaElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiImportStatement; -import com.intellij.psi.PsiReferenceExpression; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneFacetType extends FacetType<PolygeneFacet, PolygeneFacetConfiguration> -{ - public static final FacetTypeId<PolygeneFacet> ID = new FacetTypeId<PolygeneFacet>(); - - public PolygeneFacetType() - { - super( ID, "PolygeneFacet", "Polygene Facet" ); - } - - public final PolygeneFacetConfiguration createDefaultConfiguration() - { - return new PolygeneFacetConfiguration(); - } - - public final PolygeneFacet createFacet( @NotNull Module module, - String name, - @NotNull PolygeneFacetConfiguration configuration, - @Nullable Facet underlyingFacet ) - { - return new PolygeneFacet( this, module, name, configuration, underlyingFacet ); - } - - public final boolean isSuitableModuleType( ModuleType moduleType ) - { - return moduleType instanceof JavaModuleType; - } - - @Override - public final void registerDetectors( FacetDetectorRegistry<PolygeneFacetConfiguration> registry ) - { - registry.registerOnTheFlyDetector( - StdFileTypes.JAVA, VirtualFileFilter.ALL, new HasPolygeneImportPackageCondition(), - new FacetDetector<PsiFile, PolygeneFacetConfiguration>( "PolygeneFacetDetector" ) - { - @Override - public PolygeneFacetConfiguration detectFacet( PsiFile source, - Collection<PolygeneFacetConfiguration> existingConfigurations ) - { - if( !existingConfigurations.isEmpty() ) - { - return existingConfigurations.iterator().next(); - } - - return createDefaultConfiguration(); - } - } - ); - } - - private static class HasPolygeneImportPackageCondition - implements Condition<PsiFile> - { - public final boolean value( PsiFile psiFile ) - { - final boolean[] hasPolygeneImportPackage = new boolean[]{ false }; - - psiFile.accept( new JavaElementVisitor() - { - @Override - public final void visitImportStatement( PsiImportStatement statement ) - { - String packageName = statement.getQualifiedName(); - if( packageName != null && packageName.startsWith( "org.apache.polygene" ) ) - { - hasPolygeneImportPackage[ 0 ] = true; - } - } - - @Override - public void visitReferenceExpression( PsiReferenceExpression expression ) - { - // Ignore - } - } ); - return hasPolygeneImportPackage[ 0 ]; - } - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/PolygeneFacetEditorTab.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/PolygeneFacetEditorTab.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/PolygeneFacetEditorTab.java new file mode 100644 index 0000000..dc4b121 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/PolygeneFacetEditorTab.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.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 PolygeneFacetEditorTab extends FacetEditorTab +{ + private final FacetEditorContext editorContext; + + public PolygeneFacetEditorTab( FacetEditorContext aContext ) + { + editorContext = aContext; + } + + @Nls + public final String getDisplayName() + { + return "Polygene"; + } + + 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/b45402f2/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 deleted file mode 100644 index dc4b121..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/facet/ui/ZestFacetEditorTab.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.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 PolygeneFacetEditorTab extends FacetEditorTab -{ - private final FacetEditorContext editorContext; - - public PolygeneFacetEditorTab( FacetEditorContext aContext ) - { - editorContext = aContext; - } - - @Nls - public final String getDisplayName() - { - return "Polygene"; - } - - 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/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/PolygeneResourceBundle.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/PolygeneResourceBundle.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/PolygeneResourceBundle.java new file mode 100644 index 0000000..c5f29b4 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/PolygeneResourceBundle.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.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 PolygeneResourceBundle +{ + + @NonNls + private static final String RESOURCE_BUNDLE_NAME = "org.apache.polygene.ide.plugin.idea.common.resource.PolygeneResourceBundle"; + + private static Reference<ResourceBundle> BUNDLE_REF; + + private PolygeneResourceBundle() + { + } + + 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( PolygeneResourceBundle.class.getName() ); + BUNDLE_REF = new SoftReference<ResourceBundle>( bundle ); + } + + return bundle; + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/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 deleted file mode 100644 index c5f29b4..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/common/resource/ZestResourceBundle.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.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 PolygeneResourceBundle -{ - - @NonNls - private static final String RESOURCE_BUNDLE_NAME = "org.apache.polygene.ide.plugin.idea.common.resource.PolygeneResourceBundle"; - - private static Reference<ResourceBundle> BUNDLE_REF; - - private PolygeneResourceBundle() - { - } - - 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( PolygeneResourceBundle.class.getName() ); - BUNDLE_REF = new SoftReference<ResourceBundle>( bundle ); - } - - return bundle; - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernConstants.java new file mode 100644 index 0000000..0bbe3a1 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernConstants.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.concerns.common; + +import org.jetbrains.annotations.NonNls; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneConcernConstants +{ + public static final String QUALIFIED_NAME_CONCERNS = "org.apache.polygene.api.concern.Concerns"; + + public static final String QUALIFIED_NAME_CONCERN_OF = "org.apache.polygene.api.concern.ConcernOf"; + public static final String QUALIFIED_NAME_GENERIC_CONCERN = "org.apache.polygene.api.concern.GenericConcern"; + + @NonNls + public static final String TEMPLATE_GENERIC_CONCERN_OF = "GenericConcernOf.java"; + + private PolygeneConcernConstants() + { + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernUtil.java new file mode 100644 index 0000000..4499143 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/PolygeneConcernUtil.java @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.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.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getAnnotationDefaultParameterValue; +import static org.apache.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getClassReference; +import static org.apache.polygene.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; +import static org.apache.polygene.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; +import static org.apache.polygene.ide.plugin.idea.concerns.common.PolygeneConcernConstants.*; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneConcernUtil +{ + + + /** + * @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 PolygeneConcernUtil() + { + } +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/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 deleted file mode 100644 index 0bbe3a1..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernConstants.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.concerns.common; - -import org.jetbrains.annotations.NonNls; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneConcernConstants -{ - public static final String QUALIFIED_NAME_CONCERNS = "org.apache.polygene.api.concern.Concerns"; - - public static final String QUALIFIED_NAME_CONCERN_OF = "org.apache.polygene.api.concern.ConcernOf"; - public static final String QUALIFIED_NAME_GENERIC_CONCERN = "org.apache.polygene.api.concern.GenericConcern"; - - @NonNls - public static final String TEMPLATE_GENERIC_CONCERN_OF = "GenericConcernOf.java"; - - private PolygeneConcernConstants() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/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 deleted file mode 100644 index 4499143..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/concerns/common/ZestConcernUtil.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.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.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getAnnotationDefaultParameterValue; -import static org.apache.polygene.ide.plugin.idea.common.psi.PsiAnnotationUtil.getClassReference; -import static org.apache.polygene.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; -import static org.apache.polygene.ide.plugin.idea.common.psi.search.GlobalSearchScopeUtil.determineSearchScope; -import static org.apache.polygene.ide.plugin.idea.concerns.common.PolygeneConcernConstants.*; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneConcernUtil -{ - - - /** - * @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 PolygeneConcernUtil() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationConstants.java new file mode 100644 index 0000000..25c1267 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationConstants.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.injections.invocation.common; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneInvocationAnnotationConstants +{ + public static final String QUALIFIED_NAME_INVOCATION_ANNOTATION = "org.apache.polygene.api.injection.scope.Invocation"; + + private PolygeneInvocationAnnotationConstants() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationUtil.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationUtil.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationUtil.java new file mode 100644 index 0000000..334918d --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/PolygeneInvocationAnnotationUtil.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.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.polygene.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; +import static org.apache.polygene.ide.plugin.idea.injections.invocation.common.PolygeneInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; +import static org.apache.polygene.ide.plugin.idea.injections.invocation.common.PolygeneInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult.*; +import static org.apache.polygene.ide.plugin.idea.injections.structure.common.PolygeneStructureAnnotationUtil.isInjecteableByStructureAnnotation; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneInvocationAnnotationUtil +{ + /** + * 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 PolygeneInvocationAnnotationUtil() + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/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 deleted file mode 100644 index 25c1267..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationConstants.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.ide.plugin.idea.injections.invocation.common; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneInvocationAnnotationConstants -{ - public static final String QUALIFIED_NAME_INVOCATION_ANNOTATION = "org.apache.polygene.api.injection.scope.Invocation"; - - private PolygeneInvocationAnnotationConstants() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/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 deleted file mode 100644 index 334918d..0000000 --- a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/invocation/common/ZestInvocationAnnotationUtil.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.polygene.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.polygene.ide.plugin.idea.common.psi.PsiClassUtil.getPSIClass; -import static org.apache.polygene.ide.plugin.idea.injections.invocation.common.PolygeneInvocationAnnotationConstants.QUALIFIED_NAME_INVOCATION_ANNOTATION; -import static org.apache.polygene.ide.plugin.idea.injections.invocation.common.PolygeneInvocationAnnotationUtil.InvocationAnnotationDeclarationValidationResult.*; -import static org.apache.polygene.ide.plugin.idea.injections.structure.common.PolygeneStructureAnnotationUtil.isInjecteableByStructureAnnotation; - -/** - * @author [email protected] - * @since 0.1 - */ -public final class PolygeneInvocationAnnotationUtil -{ - /** - * 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 PolygeneInvocationAnnotationUtil() - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/b45402f2/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/PolygeneServiceAnnotationConstants.java ---------------------------------------------------------------------- diff --git a/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/PolygeneServiceAnnotationConstants.java b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/PolygeneServiceAnnotationConstants.java new file mode 100644 index 0000000..5a95513 --- /dev/null +++ b/tools/qidea/src/main/java/org/apache/zest/ide/plugin/idea/injections/service/common/PolygeneServiceAnnotationConstants.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.polygene.ide.plugin.idea.injections.service.common; + +/** + * @author [email protected] + * @since 0.1 + */ +public final class PolygeneServiceAnnotationConstants +{ + public static final String QUALIFIED_NAME_SERVICE_ANNOTATION = "org.apache.polygene.api.injection.scope.Service"; + + private PolygeneServiceAnnotationConstants() + { + } +} \ No newline at end of file
