Author: scabanovich
Date: 2012-05-24 14:02:26 -0400 (Thu, 24 May 2012)
New Revision: 41363
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/SecurityBindingDeclaration.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/AuthorizerHyperlinkDetector.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/JavaElementHyperlink.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.properties
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java
Log:
JBIDE-11552
https://issues.jboss.org/browse/JBIDE-11552
Open-on of authorizer method from security binding type annotation is implemented.
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/META-INF/MANIFEST.MF 2012-05-24
17:17:00 UTC (rev 41362)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/META-INF/MANIFEST.MF 2012-05-24
18:02:26 UTC (rev 41363)
@@ -14,6 +14,8 @@
org.jboss.tools.cdi.core,
org.jboss.tools.common.ui,
org.jboss.tools.cdi.ui,
+ org.jboss.tools.common.text.ext,
+ org.eclipse.jface.text,
org.jboss.tools.cdi.seam.solder.core,
org.eclipse.jdt.core;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.properties
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.properties 2012-05-24
17:17:00 UTC (rev 41362)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.properties 2012-05-24
18:02:26 UTC (rev 41363)
@@ -0,0 +1 @@
+AuthorizerHyperlinkDetector=Deltaspike Authorizer
\ No newline at end of file
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml 2012-05-24 17:17:00
UTC (rev 41362)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/plugin.xml 2012-05-24 18:02:26
UTC (rev 41363)
@@ -47,4 +47,14 @@
</provider>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+
class="org.jboss.tools.cdi.deltaspike.text.ext.AuthorizerHyperlinkDetector"
+
id="org.jboss.tools.cdi.deltaspike.text.ext.AuthorizerHyperlinkDetector"
+ name="%AuthorizerHyperlinkDetector"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+
+ </extension>
</plugin>
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java 2012-05-24
17:17:00 UTC (rev 41362)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeAuthorityMethod.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -30,7 +30,7 @@
IPath path;
String declaringTypeName;
- Map<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration> bindings = new
HashMap<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration>();
+ Map<SecurityBindingDeclaration, DeltaspikeSecurityBindingConfiguration> bindings =
new HashMap<SecurityBindingDeclaration, DeltaspikeSecurityBindingConfiguration>();
public DeltaspikeAuthorityMethod(MethodDefinition method) {
this.method = method;
@@ -53,11 +53,11 @@
return declaringTypeName;
}
- public void addBinding(IAnnotationDeclaration d, DeltaspikeSecurityBindingConfiguration
c) {
+ public void addBinding(SecurityBindingDeclaration d,
DeltaspikeSecurityBindingConfiguration c) {
bindings.put(d, c);
}
- public Map<IAnnotationDeclaration, DeltaspikeSecurityBindingConfiguration>
getBindings() {
+ public Map<SecurityBindingDeclaration, DeltaspikeSecurityBindingConfiguration>
getBindings() {
return bindings;
}
@@ -66,9 +66,9 @@
return false;
}
String key = CDIProject.getAnnotationDeclarationKey(d);
- for (IAnnotationDeclaration d2: bindings.keySet()) {
- if(d2.getTypeName().equals(d.getTypeName())) {
- if(key.equals(CDIProject.getAnnotationDeclarationKey(d2))) {
+ for (SecurityBindingDeclaration d2: bindings.keySet()) {
+ if(d2.getBinding().getTypeName().equals(d.getTypeName())) {
+ if(key.equals(CDIProject.getAnnotationDeclarationKey(d2.getBinding()))) {
return true;
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java 2012-05-24
17:17:00 UTC (rev 41362)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityBindingConfiguration.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -17,7 +17,7 @@
String securityBindingTypeName;
AnnotationDefinition securityBindingType;
- Map<AbstractMemberDefinition, IAnnotationDeclaration> boundMembers = new
HashMap<AbstractMemberDefinition, IAnnotationDeclaration>();
+ Map<AbstractMemberDefinition, SecurityBindingDeclaration> boundMembers = new
HashMap<AbstractMemberDefinition, SecurityBindingDeclaration>();
Set<DeltaspikeAuthorityMethod> authorizerMembers = new
HashSet<DeltaspikeAuthorityMethod>();
Set<IPath> involvedResources = new HashSet<IPath>();
@@ -49,11 +49,11 @@
}
}
- Map<AbstractMemberDefinition, IAnnotationDeclaration> getBoundMembers() {
+ public Map<AbstractMemberDefinition, SecurityBindingDeclaration> getBoundMembers()
{
return boundMembers;
}
- Set<DeltaspikeAuthorityMethod> getAuthorizerMembers() {
+ public Set<DeltaspikeAuthorityMethod> getAuthorizerMembers() {
return authorizerMembers;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java 2012-05-24
17:17:00 UTC (rev 41362)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/DeltaspikeSecurityExtension.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -22,7 +22,9 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.IRootDefinitionContext;
+import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.core.extension.ICDIExtension;
import org.jboss.tools.cdi.core.extension.IDefinitionContextExtension;
import org.jboss.tools.cdi.core.extension.feature.IBuildParticipantFeature;
@@ -38,6 +40,7 @@
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
+import org.jboss.tools.common.java.IAnnotated;
import org.jboss.tools.common.java.IAnnotationDeclaration;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.preferences.SeverityPreferences;
@@ -49,8 +52,13 @@
* @author Viacheslav Kabanovich
*/
public class DeltaspikeSecurityExtension implements ICDIExtension,
IBuildParticipantFeature, IProcessAnnotatedTypeFeature, IProcessAnnotatedMemberFeature,
IValidatorFeature, DeltaspikeConstants {
+ public static String ID =
"org.apache.deltaspike.security.impl.authorization.SecurityExtension";
//$NON-NLS-1$
DeltaspikeSecurityDefinitionContext context = new
DeltaspikeSecurityDefinitionContext();
+ public static DeltaspikeSecurityExtension getExtension(CDICoreNature project) {
+ return
(DeltaspikeSecurityExtension)project.getExtensionManager().getExtensionByRuntime(ID);
+ }
+
@Override
public IDefinitionContextExtension getContext() {
return context;
@@ -86,9 +94,9 @@
DeltaspikeAuthorityMethod authorizer = new DeltaspikeAuthorityMethod(method);
DeltaspikeSecurityDefinitionContext contextCopy =
((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy());
contextCopy.allAuthorizerMethods.getAuthorizerMembers().add(authorizer);
- List<IAnnotationDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(memberDefinition,
contextCopy.getRootContext());
- for (IAnnotationDeclaration d: ds) {
- DeltaspikeSecurityBindingConfiguration c =
((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy()).getConfiguration(d.getTypeName());
+ List<SecurityBindingDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(memberDefinition,
contextCopy.getRootContext());
+ for (SecurityBindingDeclaration d: ds) {
+ DeltaspikeSecurityBindingConfiguration c =
((DeltaspikeSecurityDefinitionContext)this.context.getWorkingCopy()).getConfiguration(d.getBinding().getTypeName());
authorizer.addBinding(d, c);
c.getAuthorizerMembers().add(authorizer);
addToDependencies(c, authorizer.getMethod(), context);
@@ -105,14 +113,14 @@
}
private void addSecurityMember(AbstractMemberDefinition def, IRootDefinitionContext
context) {
- List<IAnnotationDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(def, context);
- for (IAnnotationDeclaration d: ds) {
+ List<SecurityBindingDeclaration> ds =
findAnnotationAnnotatedWithSecurityBindingType(def, context);
+ for (SecurityBindingDeclaration d: ds) {
addBoundMember(def, d, context);
}
}
- private void addBoundMember(AbstractMemberDefinition def, IAnnotationDeclaration d,
IRootDefinitionContext context) {
- String securityBindingType = d.getTypeName();
+ private void addBoundMember(AbstractMemberDefinition def, SecurityBindingDeclaration d,
IRootDefinitionContext context) {
+ String securityBindingType = d.getBinding().getTypeName();
if(def instanceof MethodDefinition) {
((MethodDefinition)def).setCDIAnnotated(true);
}
@@ -137,24 +145,67 @@
}
}
- static List<IAnnotationDeclaration> EMPTY =
Collections.<IAnnotationDeclaration>emptyList();
+ static List<SecurityBindingDeclaration> EMPTY =
Collections.<SecurityBindingDeclaration>emptyList();
- private List<IAnnotationDeclaration>
findAnnotationAnnotatedWithSecurityBindingType(AbstractMemberDefinition m,
IRootDefinitionContext context) {
- List<IAnnotationDeclaration> result = null;
+ private List<SecurityBindingDeclaration>
findAnnotationAnnotatedWithSecurityBindingType(AbstractMemberDefinition m,
IRootDefinitionContext context) {
+ List<SecurityBindingDeclaration> result = null;
List<IAnnotationDeclaration> ds = m.getAnnotations();
for (IAnnotationDeclaration d: ds) {
+ if(d instanceof IStereotypeDeclaration) {
+ AnnotationDefinition t = context.getAnnotation(d.getTypeName());
+ if(t != null) {
+ List<IAnnotationDeclaration> ds1 = findSecurityBindingAnnotations(t, null,
context);
+ if(ds1 != null) {
+ for (IAnnotationDeclaration d1: ds1) {
+ result.add(new SecurityBindingDeclaration(d, d1));
+ }
+ }
+ }
+ } else if(d.getTypeName() != null) {
+ AnnotationDefinition a = context.getAnnotation(d.getTypeName());
+ if(a != null && a.isAnnotationPresent(SECURITY_BINDING_ANNOTATION_TYPE_NAME))
{
+ if(result == null) {
+ result = new ArrayList<SecurityBindingDeclaration>();
+ }
+ result.add(new SecurityBindingDeclaration(d, d));
+ } else if(a != null && d instanceof IStereotypeDeclaration) {
+ List<IAnnotationDeclaration> ds1 = findSecurityBindingAnnotations(a, null,
context);
+ if(ds1 != null) {
+ if(result == null) {
+ result = new ArrayList<SecurityBindingDeclaration>();
+ }
+ for (IAnnotationDeclaration d1: ds1) {
+ result.add(new SecurityBindingDeclaration(d, d1));
+ }
+ }
+ }
+ }
+ }
+ return result == null ? EMPTY : result;
+ }
+
+ private List<IAnnotationDeclaration> findSecurityBindingAnnotations(IAnnotated s,
List<IAnnotationDeclaration> result, IRootDefinitionContext context) {
+ List<IAnnotationDeclaration> ds = s.getAnnotations();
+ for (IAnnotationDeclaration d: ds) {
if(d.getTypeName() != null) {
-// context.getAnnotationKind(d.getType());
AnnotationDefinition a = context.getAnnotation(d.getTypeName());
if(a != null && a.isAnnotationPresent(SECURITY_BINDING_ANNOTATION_TYPE_NAME))
{
if(result == null) {
result = new ArrayList<IAnnotationDeclaration>();
}
result.add(d);
+ } else if(a != null && d instanceof IStereotypeDeclaration) {
+ List<IAnnotationDeclaration> ds1 = findSecurityBindingAnnotations(a, null,
context);
+ if(ds1 != null) {
+ if(result == null) {
+ result = new ArrayList<IAnnotationDeclaration>();
+ }
+ result.addAll(ds1);
+ }
}
}
- }
- return result == null ? EMPTY : result;
+ }
+ return result;
}
@Override
@@ -191,16 +242,16 @@
for (DeltaspikeSecurityBindingConfiguration c: context.getConfigurations().values()) {
if(c.getInvolvedTypes().contains(file.getFullPath())) {
Set<DeltaspikeAuthorityMethod> authorizers2 = c.getAuthorizerMembers();
- Map<AbstractMemberDefinition, IAnnotationDeclaration> bound =
c.getBoundMembers();
+ Map<AbstractMemberDefinition, SecurityBindingDeclaration> bound =
c.getBoundMembers();
for (AbstractMemberDefinition d: bound.keySet()) {
String name = d instanceof MethodDefinition ?
((MethodDefinition)d).getMethod().getElementName()
: d instanceof TypeDefinition ? ((TypeDefinition)d).getQualifiedName() :
"";
if(file.getFullPath().equals(d.getTypeDefinition().getType().getPath())) {
- IAnnotationDeclaration dc = bound.get(d);
+ SecurityBindingDeclaration dc = bound.get(d);
int k = 0;
for (DeltaspikeAuthorityMethod a: authorizers2) {
try {
- if(a.isMatching(dc)) k++;
+ if(a.isMatching(dc.getBinding())) k++;
} catch (CoreException e) {
DeltaspikeCorePlugin.getDefault().logError(e);
}
@@ -208,13 +259,13 @@
if(k == 0) {
validator.addError(DeltaspikeValidationMessages.UNRESOLVED_AUTHORIZER,
DeltaspikeSeverityPreferences.UNRESOLVED_AUTHORIZER,
- new String[]{dc.getTypeName(), name},
- dc, file);
+ new String[]{dc.getBinding().getTypeName(), name},
+ dc.getDeclaration(), file);
} else if(k > 1) {
validator.addError(DeltaspikeValidationMessages.AMBIGUOUS_AUTHORIZER,
DeltaspikeSeverityPreferences.AMBIGUOUS_AUTHORIZER,
- new String[]{dc.getTypeName(), name},
- dc, file);
+ new String[]{dc.getBinding().getTypeName(), name},
+ dc.getDeclaration(), file);
}
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/SecurityBindingDeclaration.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/SecurityBindingDeclaration.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/SecurityBindingDeclaration.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.core;
+
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+
+/**
+ *
+ * @author Viacheslav Kabanovih
+ *
+ */
+public class SecurityBindingDeclaration {
+ IAnnotationDeclaration declaration;
+ IAnnotationDeclaration binding;
+
+ public SecurityBindingDeclaration(IAnnotationDeclaration declaration,
IAnnotationDeclaration binding) {
+ this.declaration = declaration;
+ this.binding = binding;
+ }
+
+ public IAnnotationDeclaration getDeclaration() {
+ return declaration;
+ }
+
+ public IAnnotationDeclaration getBinding() {
+ return binding;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/core/SecurityBindingDeclaration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/AuthorizerHyperlinkDetector.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/AuthorizerHyperlinkDetector.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/AuthorizerHyperlinkDetector.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.text.ext;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDIUtil;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeAuthorityMethod;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeCorePlugin;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeSecurityBindingConfiguration;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeSecurityDefinitionContext;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeSecurityExtension;
+import org.jboss.tools.cdi.deltaspike.core.SecurityBindingDeclaration;
+import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
+import org.jboss.tools.common.java.IAnnotationDeclaration;
+
+public class AuthorizerHyperlinkDetector extends AbstractHyperlinkDetector{
+ protected IRegion region;
+ protected IDocument document;
+ protected ITextViewer viewer;
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+ this.region = region;
+ this.viewer = textViewer;
+
+ ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
+ if (region == null || !canShowMultipleHyperlinks || !(textEditor instanceof
JavaEditor))
+ return null;
+
+ int offset= region.getOffset();
+
+ ITypeRoot input = EditorUtility.getEditorInputJavaElement(textEditor, false);
+ if (input == null)
+ return null;
+
+ document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IRegion wordRegion= JavaWordFinder.findWord(document, offset);
+ if (wordRegion == null)
+ return null;
+
+ IProject project = null;
+
+ project = input.getJavaProject().getProject();
+
+ if(project == null)
+ return null;
+
+ CDICoreNature cdiNature = CDIUtil.getCDINatureWithProgress(project);
+ if(cdiNature == null)
+ return null;
+
+ IJavaElement[] elements = null;
+ IType annotationType = null;
+
+ try {
+ elements = input.codeSelect(wordRegion.getOffset(), wordRegion.getLength());
+ if (elements == null)
+ return null;
+ if(elements.length != 1)
+ return null;
+
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ int position = 0;
+ if(elements[0] instanceof IType){
+ annotationType = (IType)elements[0];
+ if(!annotationType.isAnnotation()) {
+ annotationType = null;
+ }
+ elements[0] = input.getElementAt(wordRegion.getOffset());
+ if(elements[0] == null)
+ return null;
+
+ if(elements[0] instanceof IMethod){
+ position = offset;
+ }
+ }
+
+ findAuthorizerMethods(cdiNature, elements[0], annotationType, position,
input.getPath(), hyperlinks);
+
+ if (hyperlinks != null && !hyperlinks.isEmpty()) {
+ return (IHyperlink[])hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
+ }
+ } catch (JavaModelException jme) {
+ DeltaspikeCorePlugin.getDefault().logError(jme);
+ }
+ return null;
+ }
+
+ protected void findAuthorizerMethods(CDICoreNature nature, IJavaElement element, IType
annotationType, int offset, IPath path, ArrayList<IHyperlink> hyperlinks){
+ ICDIProject cdiProject = nature.getDelegate();
+
+ if(cdiProject == null) {
+ return;
+ }
+
+ DeltaspikeSecurityExtension extension =
DeltaspikeSecurityExtension.getExtension(nature);
+ if(extension == null) return;
+
+ DeltaspikeSecurityDefinitionContext context =
(DeltaspikeSecurityDefinitionContext)extension.getContext();
+
+ Map<String, DeltaspikeSecurityBindingConfiguration> cs =
context.getConfigurations();
+
+ for (DeltaspikeSecurityBindingConfiguration c: cs.values()) {
+ Map<AbstractMemberDefinition, SecurityBindingDeclaration> ms =
c.getBoundMembers();
+ Set<DeltaspikeAuthorityMethod> as = c.getAuthorizerMembers();
+ Set<String> authorityMethods = new HashSet<String>();
+ for (AbstractMemberDefinition m: ms.keySet()) {
+ if(element.equals(m.getMember())) {
+ for (DeltaspikeAuthorityMethod a: as) {
+ try {
+ IAnnotationDeclaration b = ms.get(m).getBinding();
+ IAnnotationDeclaration d = ms.get(m).getDeclaration();
+ if(annotationType != null &&
!annotationType.getFullyQualifiedName().equals(d.getTypeName())) {
+ continue;
+ }
+ if(a.isMatching(b)) {
+ IMethod method = a.getMethod().getMethod();
+ if(authorityMethods.contains(method.getSignature())) {
+ continue;
+ }
+ authorityMethods.add(method.getSignature());
+ JavaElementHyperlink h = new JavaElementHyperlink(region, method, document);
+ hyperlinks.add(h);
+ }
+ } catch (CoreException e) {
+ DeltaspikeCorePlugin.getDefault().logError(e);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/AuthorizerHyperlinkDetector.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/JavaElementHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/JavaElementHyperlink.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/JavaElementHyperlink.java 2012-05-24
18:02:26 UTC (rev 41363)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.deltaspike.text.ext;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.jboss.tools.cdi.deltaspike.core.DeltaspikeCorePlugin;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+
+public class JavaElementHyperlink extends AbstractHyperlink {
+ protected IJavaElement element;
+
+ public JavaElementHyperlink(IRegion region, IJavaElement element, IDocument document){
+ this.element = element;
+ setRegion(region);
+ setDocument(document);
+ }
+
+ public void doHyperlink(IRegion region) {
+ IEditorPart part = null;
+
+ if(element != null && element.exists() &&
element.getAncestor(IJavaElement.TYPE) != null) {
+ try{
+ part = JavaUI.openInEditor(element.getAncestor(IJavaElement.TYPE));
+ }catch(JavaModelException ex){
+ DeltaspikeCorePlugin.getDefault().logError(ex);
+ }catch(PartInitException ex){
+ DeltaspikeCorePlugin.getDefault().logError(ex);
+ }
+
+ if (part != null) {
+ JavaUI.revealInEditor(part, element);
+ }
+ }
+ if (part == null)
+ openFileFailed();
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ String s = "";
+ if(element instanceof IMethod) {
+ IMethod m = (IMethod)element;
+ s = m.getDeclaringType().getElementName() + "." + m.getElementName() +
"()";
+ }
+ String text = "Open authorizer method " + s;
+ return text;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.deltaspike.core/src/org/jboss/tools/cdi/deltaspike/text/ext/JavaElementHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain