diff --git a/org.jboss.tools.maven.apt.ui/META-INF/MANIFEST.MF b/org.jboss.tools.maven.apt.ui/META-INF/MANIFEST.MF index c76d461..3204ca2 100644 --- a/org.jboss.tools.maven.apt.ui/META-INF/MANIFEST.MF +++ b/org.jboss.tools.maven.apt.ui/META-INF/MANIFEST.MF @@ -11,7 +11,15 @@ Require-Bundle: org.eclipse.ui, org.slf4j.api, org.eclipse.jdt.core;bundle-version="3.6.0", org.eclipse.jdt.ui, - org.eclipse.m2e.core;bundle-version="1.0.0" + org.eclipse.m2e.core;bundle-version="1.0.0", + org.eclipse.ui.workbench.texteditor, + org.eclipse.jface.text, + org.eclipse.wst.xml.ui, + org.eclipse.wst.sse.core, + org.eclipse.wst.xml.core, + org.eclipse.wst.sse.ui, + org.eclipse.text, + org.eclipse.m2e.editor.xml Eclipse-LazyStart: true Bundle-Activator: org.jboss.tools.maven.apt.ui.MavenJdtAptUIPlugin Bundle-RequiredExecutionEnvironment: JavaSE-1.7 diff --git a/org.jboss.tools.maven.apt.ui/plugin.xml b/org.jboss.tools.maven.apt.ui/plugin.xml index d33d85c..c39281a 100644 --- a/org.jboss.tools.maven.apt.ui/plugin.xml +++ b/org.jboss.tools.maven.apt.ui/plugin.xml @@ -43,5 +43,18 @@ <m2e.apt.activation>${cursor}${jdt_apt}</m2e.apt.activation> + + + + + + + diff --git a/org.jboss.tools.maven.apt.ui/src/org/jboss/tools/maven/apt/internal/ui/xml/AnnotationProcessingModeCompletionProposalComputer.java b/org.jboss.tools.maven.apt.ui/src/org/jboss/tools/maven/apt/internal/ui/xml/AnnotationProcessingModeCompletionProposalComputer.java new file mode 100644 index 0000000..9271276 --- /dev/null +++ b/org.jboss.tools.maven.apt.ui/src/org/jboss/tools/maven/apt/internal/ui/xml/AnnotationProcessingModeCompletionProposalComputer.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2008-2016 Sonatype, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are 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: + * Sonatype, Inc. - initial implementation of PomContentAssistProcessor + * Fred Bricon (Red Hat, Inc.) - adapted for <m2e.apt.activation> + *******************************************************************************/ +package org.jboss.tools.maven.apt.internal.ui.xml; + +import java.util.ArrayList; +import java.util.Collection; + +import org.jboss.tools.maven.apt.preferences.AnnotationProcessingMode; +import org.jboss.tools.maven.apt.ui.preferences.PreferenceMessages; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.templates.DocumentTemplateContext; +import org.eclipse.jface.text.templates.Template; +import org.eclipse.jface.text.templates.TemplateContext; +import org.eclipse.jface.text.templates.TemplateContextType; +import org.eclipse.jface.text.templates.TemplateProposal; +import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext; +import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal; +import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest; +import org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer; + +import org.eclipse.m2e.editor.xml.MvnIndexPlugin; + + +/** + * <m2e.apt.activation> completion proposal for the pom.xml editor. + * + * This class is heavily inspired from m2e's + * org.eclipse.m2e.editor.xml.PomContentAssistProcessor + * + * @author Fred Bricon + * @author Lukas Krecan + * @author Eugene Kuleshov + */ +@SuppressWarnings("restriction") +public class AnnotationProcessingModeCompletionProposalComputer extends DefaultXMLCompletionProposalComputer { + + private static final String M2E_PROPERTIES_CONTEXT_TYPE = "org.eclipse.m2e.editor.xml.templates.contextType.properties"; + + @Override + protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition, + CompletionProposalInvocationContext ctx) { + if (contentAssistRequest.getParent() == null || contentAssistRequest.getParent().getParentNode() == null) { + return; + } + String containerName = contentAssistRequest.getParent().getParentNode().getNodeName(); + String propertyName = contentAssistRequest.getParent().getNodeName(); + if (!"properties".equals(containerName) && !"m2e.apt.activation".equals(propertyName)) { + return; + } + int offset = contentAssistRequest.getReplacementBeginPosition(); + String prefix = extractPrefix(ctx.getViewer(), offset); + contentAssistRequest.setMatchString(prefix); + contentAssistRequest.setReplacementBeginPosition(offset - prefix.length()); + contentAssistRequest.setReplacementLength(prefix.length()); + addTemplateProposals(contentAssistRequest, ctx.getViewer()); + } + + public static final String extractPrefix(ITextViewer viewer, int offset) { + int i = offset; + IDocument document = viewer.getDocument(); + if(i > document.getLength()) { + return ""; //$NON-NLS-1$ + } + + try { + while(i > 0) { + char ch = document.getChar(i - 1); + if(ch == '>' || ch == '<' || ch == ' ' || ch == '\n' || ch == '\t') { + break; + } + i-- ; + } + return document.get(i, offset - i); + } catch(BadLocationException e) { + return ""; //$NON-NLS-1$ + } + } + + private Collection