Author: dazarov
Date: 2010-08-27 09:54:47 -0400 (Fri, 27 Aug 2010)
New Revision: 24500
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteNameAnnotaionMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-6869
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-08-27
13:38:30 UTC (rev 24499)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2010-08-27
13:54:47 UTC (rev 24500)
@@ -19,6 +19,7 @@
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -83,8 +84,10 @@
* @author Alexey Kazakov
*/
public class SeamCoreValidator extends SeamValidationErrorManager implements IValidator
{
-
public static final String ID = "org.jboss.tools.seam.core.CoreValidator";
+
+ public static final String MESSAGE_ID_ATTRIBUTE_NAME = "Seam_message_id";
//$NON-NLS-1$
+ public static final int NONUNIQUE_COMPONENT_NAME_MESSAGE_ID = 1;
private ISeamProject seamProject;
private String projectName;
@@ -552,7 +555,7 @@
IResource checkedDeclarationResource = checkedDeclaration.getResource();
ITextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(!SeamUtil.isEmptyLocation(location)) {
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
checkedDeclarationResource);
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
checkedDeclarationResource, NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
markedDeclarations.add(checkedDeclaration);
}
@@ -560,7 +563,7 @@
markedDeclarations.add(javaDeclaration);
ITextSourceReference location =
((SeamComponentDeclaration)javaDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(!SeamUtil.isEmptyLocation(location)) {
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
javaDeclarationResource);
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
javaDeclarationResource, NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
}
}
@@ -609,7 +612,7 @@
IResource checkedDeclarationResource = checkedDeclaration.getResource();
ITextSourceReference location =
((SeamComponentDeclaration)checkedDeclaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(!SeamUtil.isEmptyLocation(location)) {
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
checkedDeclarationResource);
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
checkedDeclarationResource, NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
markedDeclarations.add(checkedDeclaration);
}
@@ -617,7 +620,7 @@
markedDeclarations.add(declaration);
ITextSourceReference location =
((SeamComponentDeclaration)declaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
if(!SeamUtil.isEmptyLocation(location)) {
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource());
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource(), NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
}
}
@@ -639,12 +642,12 @@
if(!markedJavaDeclarations.contains(javaDec)) {
markedJavaDeclarations.add(javaDec);
ITextSourceReference location =
((SeamComponentDeclaration)javaDec).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
javaDec.getResource());
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
javaDec.getResource(), NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
if(!markedDeclarations.contains(declaration)) {
markedDeclarations.add(declaration);
ITextSourceReference location =
((SeamComponentDeclaration)declaration).getLocationFor(SeamComponentDeclaration.PATH_OF_NAME);
- addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource());
+ addError(SeamValidationMessages.NONUNIQUE_COMPONENT_NAME_MESSAGE,
SeamPreferences.NONUNIQUE_COMPONENT_NAME, new String[]{componentName}, location,
declaration.getResource(), NONUNIQUE_COMPONENT_NAME_MESSAGE_ID);
}
}
}
@@ -1022,5 +1025,17 @@
}
}
+
+ public IMarker addError(String message, String preferenceKey,
+ String[] messageArguments, ITextSourceReference location,
+ IResource target, int messageId) {
+ IMarker marker = addError(message, preferenceKey, messageArguments, location, target);
+ try{
+ marker.setAttribute(MESSAGE_ID_ATTRIBUTE_NAME, new Integer(messageId));
+ }catch(CoreException ex){
+ SeamCorePlugin.getDefault().logError(ex);
+ }
+ return marker;
+ }
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2010-08-27 13:38:30 UTC (rev
24499)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2010-08-27 13:54:47 UTC (rev
24500)
@@ -708,5 +708,10 @@
</objectContribution>
</extension>
-
+ <extension point="org.eclipse.ui.ide.markerResolution">
+ <markerResolutionGenerator
+ markerType="org.eclipse.wst.validation.problemmarker"
+ class="org.jboss.tools.seam.ui.marker.SeamProblemMarkerResolutionGenerator">
+ </markerResolutionGenerator>
+ </extension>
</plugin>
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2010-08-27
13:38:30 UTC (rev 24499)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2010-08-27
13:54:47 UTC (rev 24500)
@@ -360,6 +360,8 @@
public static String SEAM_COMPONENT_RENAME_HANDLER_ERROR;
+ public static String DELETE_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE;
+
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, SeamUIMessages.class);
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-08-27
13:54:47 UTC (rev 24500)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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.seam.ui.marker;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IBuffer;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IImportContainer;
+import org.eclipse.jdt.core.IImportDeclaration;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+
+/**
+ * @author Daniel Azarov
+ */
+public abstract class AbstractSeamMarkerResolution implements
+ IMarkerResolution2 {
+ protected IFile file;
+ protected int start, end;
+
+ public AbstractSeamMarkerResolution(IFile file, int start, int end){
+ this.file = file;
+ this.start = start;
+ this.end = end;
+ }
+
+ protected void deleteAnnotation(String annotationTypeName){
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ IJavaElement javaElement = compilationUnit.getElementAt(start);
+ IType type = compilationUnit.findPrimaryType();
+ if(javaElement != null && type != null){
+ if(javaElement instanceof IAnnotatable){
+ IAnnotation annotation = findAnnotation(type, (IAnnotatable)javaElement,
annotationTypeName);
+ if(annotation != null){
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ // delete annotation
+ buffer.replace(annotation.getSourceRange().getOffset(),
annotation.getSourceRange().getLength(), "");
+
+ // check and delete import
+ IImportDeclaration importDeclaration =
compilationUnit.getImport(annotationTypeName);
+ IImportContainer importContainer = compilationUnit.getImportContainer();
+ if(importDeclaration != null && importContainer != null){
+ int importSize =
importContainer.getSourceRange().getOffset()+importContainer.getSourceRange().getLength();
+ String text = buffer.getText(importSize, buffer.getLength()-importSize);
+ if(checkImport(text, annotationTypeName))
+ importDeclaration.delete(false, new NullProgressMonitor());
+ }
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ }
+ }
+ }
+
+ }catch(CoreException ex){
+ SeamGuiPlugin.getPluginLog().logError(ex);
+ }
+ }
+
+ private boolean checkImport(String text, String qualifiedName){
+ int lastDot = qualifiedName.lastIndexOf('.');
+ String name;
+ if(lastDot < 0)
+ name = qualifiedName;
+ else
+ name = qualifiedName.substring(lastDot+1);
+
+ Pattern p = Pattern.compile(".*\\W"+name+"\\W.*",Pattern.DOTALL);
//$NON-NLS-1$ //$NON-NLS-2$
+ Matcher m = p.matcher(text);
+ return !m.matches();
+ }
+
+ protected void addAnnotation(String annotationTypeName, String annotationString){
+ try{
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+
+ if(compilationUnit.getImport(annotationTypeName) == null){
+ compilationUnit.createImport(annotationTypeName, null, new NullProgressMonitor());
+ }
+
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ buffer.replace(start, 0, annotationString+' ');
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ }catch(CoreException ex){
+ SeamGuiPlugin.getPluginLog().logError(ex);
+ }
+ }
+
+
+ private IAnnotation findAnnotation(IType sourceType, IAnnotatable member, String
annotationTypeName) {
+ try {
+ IAnnotation[] annotations = member.getAnnotations();
+ String simpleAnnotationTypeName = annotationTypeName;
+ int lastDot = annotationTypeName.lastIndexOf('.');
+ if(lastDot>-1) {
+ simpleAnnotationTypeName = simpleAnnotationTypeName.substring(lastDot + 1);
+ }
+ for (IAnnotation annotation : annotations) {
+ if(annotationTypeName.equals(annotation.getElementName())) {
+ return annotation;
+ }
+ if(simpleAnnotationTypeName.equals(annotation.getElementName())) {
+ String fullAnnotationclassName = EclipseJavaUtil.resolveType(sourceType,
simpleAnnotationTypeName);
+ if(fullAnnotationclassName!=null) {
+ IType annotationType =
sourceType.getJavaProject().findType(fullAnnotationclassName);
+ if(annotationType!=null &&
annotationType.getFullyQualifiedName().equals(annotationTypeName)) {
+ return annotation;
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ SeamGuiPlugin.getDefault().logError(e);
+ }
+ return null;
+ }
+
+ public String getLabel() {
+ return null;
+ }
+
+ public void run(IMarker marker) {
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteNameAnnotaionMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteNameAnnotaionMarkerResolution.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteNameAnnotaionMarkerResolution.java 2010-08-27
13:54:47 UTC (rev 24500)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.seam.ui.marker;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+
+/**
+ * @author Daniel Azarov
+ */
+public class DeleteNameAnnotaionMarkerResolution extends
+ AbstractSeamMarkerResolution {
+ public DeleteNameAnnotaionMarkerResolution(IFile file, int start, int end){
+ super(file, start, end);
+ }
+
+ public String getLabel() {
+ return SeamUIMessages.DELETE_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE;
+ }
+
+ public void run(IMarker marker) {
+ deleteAnnotation("org.jboss.seam.annotations.Name"); //$NON-NLS-1$
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/DeleteNameAnnotaionMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-08-27
13:54:47 UTC (rev 24500)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.seam.ui.marker;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.IMarkerResolution;
+import org.eclipse.ui.IMarkerResolutionGenerator2;
+import org.jboss.tools.seam.internal.core.validation.SeamCoreValidator;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+
+/**
+ * @author Daniel Azarov
+ */
+public class SeamProblemMarkerResolutionGenerator implements IMarkerResolutionGenerator2
{
+
+ public IMarkerResolution[] getResolutions(IMarker marker) {
+ try{
+ IMarkerResolution resolution = isOurCase(marker);
+ if(resolution != null){
+ return new IMarkerResolution[] {resolution};
+ }
+ }catch(CoreException ex){
+ SeamGuiPlugin.getPluginLog().logError(ex);
+ }
+ return new IMarkerResolution[]{};
+ }
+
+ private IMarkerResolution isOurCase(IMarker marker) throws CoreException{
+ Integer attribute =
((Integer)marker.getAttribute(SeamCoreValidator.MESSAGE_ID_ATTRIBUTE_NAME));
+ if(attribute == null)
+ return null;
+
+ int messageId = attribute.intValue();
+
+ IFile file = (IFile)marker.getResource();
+
+ attribute = ((Integer)marker.getAttribute(IMarker.CHAR_START));
+ if(attribute == null)
+ return null;
+ int start = attribute.intValue();
+
+ attribute = ((Integer)marker.getAttribute(IMarker.CHAR_END));
+ if(attribute == null)
+ return null;
+ int end = attribute.intValue();
+
+ if(messageId == SeamCoreValidator.NONUNIQUE_COMPONENT_NAME_MESSAGE_ID)
+ return new DeleteNameAnnotaionMarkerResolution(file, start, end);
+
+ return null;
+ }
+
+
+ public boolean hasResolutions(IMarker marker) {
+ try{
+ if(isOurCase(marker) != null)
+ return true;
+ }catch(CoreException ex){
+ SeamGuiPlugin.getPluginLog().logError(ex);
+ }
+ return false;
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2010-08-27
13:38:30 UTC (rev 24499)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2010-08-27
13:54:47 UTC (rev 24500)
@@ -187,4 +187,5 @@
RENAME_SEAM_COMPONENT = Rename Seam Component
RENAME_SEAM_CONTEXT_VARIABLE = Rename Seam Context Variable
FIND_USAGES_IN_EL = Find Usages in Expression Language
-SEAM_COMPONENT_RENAME_HANDLER_ERROR = Error
+SEAM_COMPONENT_RENAME_HANDLER_ERROR = Error
+DELETE_NAME_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete @Name annotation