### Eclipse Workspace Patch 1.0
#P org.eclipse.mylyn.context.ui
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/mylyn/org.eclipse.mylyn.contexts/org.eclipse.mylyn.context.ui/META-INF/MANIFEST.MF,v
retrieving revision 1.381
diff -u -r1.381 MANIFEST.MF
--- META-INF/MANIFEST.MF 26 Jun 2010 07:37:24 -0000 1.381
+++ META-INF/MANIFEST.MF 12 Mar 2011 01:04:45 -0000
@@ -23,6 +23,7 @@
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.eclipse.mylyn.context.ui,
+ org.eclipse.mylyn.context.ui.strategy,
org.eclipse.mylyn.internal.context.ui;x-internal:=true,
org.eclipse.mylyn.internal.context.ui.actions;x-internal:=true,
org.eclipse.mylyn.internal.context.ui.commands;x-internal:=true,
Index: plugin.xml
===================================================================
RCS file: /cvsroot/mylyn/org.eclipse.mylyn.contexts/org.eclipse.mylyn.context.ui/plugin.xml,v
retrieving revision 1.168
diff -u -r1.168 plugin.xml
--- plugin.xml 3 Mar 2011 02:03:26 -0000 1.168
+++ plugin.xml 12 Mar 2011 01:04:45 -0000
@@ -13,6 +13,7 @@
+
Index: schema/strategies.exsd
===================================================================
RCS file: schema/strategies.exsd
diff -N schema/strategies.exsd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ schema/strategies.exsd 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+ [Enter description of this extension point.]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [Enter the first release in which this extension point appears.]
+
+
+
+
+
+
+
+
+ [Enter extension point usage example here.]
+
+
+
+
+
+
+
+
+ [Enter API information here.]
+
+
+
+
+
+
+
+
+ [Enter information about supplied implementation of this extension point.]
+
+
+
+
+
Index: src/org/eclipse/mylyn/context/ui/strategy/AbstractContextComputationStrategy.java
===================================================================
RCS file: src/org/eclipse/mylyn/context/ui/strategy/AbstractContextComputationStrategy.java
diff -N src/org/eclipse/mylyn/context/ui/strategy/AbstractContextComputationStrategy.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/mylyn/context/ui/strategy/AbstractContextComputationStrategy.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.context.ui.strategy;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.context.core.IInteractionContext;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+/**
+ * A strategy for computing context of a task. Implementations take a task data and from it derive a list of objects
+ * that can be added to the context.
+ *
+ * @author David Green
+ * @since 3.6
+ */
+public abstract class AbstractContextComputationStrategy {
+ /**
+ * compute a list of objects that should be added to the context based on the task data.
+ */
+ public abstract List
+
+
+
+
Index: src/org/eclipse/mylyn/internal/java/ui/AbstractJavaContextComputationStrategy.java
===================================================================
RCS file: src/org/eclipse/mylyn/internal/java/ui/AbstractJavaContextComputationStrategy.java
diff -N src/org/eclipse/mylyn/internal/java/ui/AbstractJavaContextComputationStrategy.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/mylyn/internal/java/ui/AbstractJavaContextComputationStrategy.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.java.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.TypeNameMatch;
+import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
+import org.eclipse.mylyn.context.ui.strategy.AbstractContextComputationStrategy;
+
+/**
+ * An abstract strategy that can find Java types in the workspace based on their fully qualified name.
+ *
+ * @author David Green
+ */
+public abstract class AbstractJavaContextComputationStrategy extends AbstractContextComputationStrategy {
+
+ protected IType findTypeInWorkspace(String typeName) throws CoreException {
+ int dot = typeName.lastIndexOf('.');
+ char[][] qualifications;
+ String simpleName;
+ if (dot != -1) {
+ qualifications = new char[][] { typeName.substring(0, dot).toCharArray() };
+ simpleName = typeName.substring(dot + 1);
+ } else {
+ qualifications = null;
+ simpleName = typeName;
+ }
+ char[][] typeNames = new char[][] { simpleName.toCharArray() };
+
+ class ResultException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private final IType fType;
+
+ public ResultException(IType type) {
+ fType = type;
+ }
+ }
+ TypeNameMatchRequestor requestor = new TypeNameMatchRequestor() {
+ @Override
+ public void acceptTypeNameMatch(TypeNameMatch match) {
+ throw new ResultException(match.getType());
+ }
+ };
+ try {
+ new SearchEngine().searchAllTypeNames(qualifications, typeNames, SearchEngine.createWorkspaceScope(),
+ requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ } catch (ResultException e) {
+ return e.fType;
+ } catch (Throwable t) {
+ // ignore
+ }
+ return null;
+ }
+}
Index: src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceContextComputationStrategy.java
===================================================================
RCS file: src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceContextComputationStrategy.java
diff -N src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceContextComputationStrategy.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/mylyn/internal/java/ui/JavaStackTraceContextComputationStrategy.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.java.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.mylyn.context.core.IInteractionContext;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+/**
+ * A strategy that computes Java items based on a Java stack trace in the task description.
+ *
+ * @author David Green
+ */
+public class JavaStackTraceContextComputationStrategy extends AbstractJavaContextComputationStrategy {
+
+ private static final String PACKAGE_PART = "([a-z][a-z0-9]*)"; //$NON-NLS-1$
+
+ private static final String CLASS_PART = "[A-Za-z][a-zA-Z0-9_$]*"; //$NON-NLS-1$
+
+ private static final String FQN_PART = "((" + PACKAGE_PART + "\\.)*" + CLASS_PART + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ private static final Pattern STACK_TRACE_PATTERN = Pattern.compile("\\s*((" + "((Caused by:\\s+)|(at\\s+))?" //$NON-NLS-1$//$NON-NLS-2$
+ + FQN_PART + "((:\\s+\\w.*)|(\\.((\\<(?:cl)?init\\>)|([a-zA-Z0-9_$]+))\\(.*?\\)))?" //$NON-NLS-1$
+ + ")|(\\.\\.\\.\\s\\d+\\smore))"); //$NON-NLS-1$
+
+ /**
+ * public for testing only
+ */
+ public static class Element {
+ String fqn;
+
+ String methodName;
+
+ public Element(String fqn, String methodName) {
+ this.fqn = fqn;
+ this.methodName = methodName;
+ }
+
+ public Element() {
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Element [fqn="); //$NON-NLS-1$
+ builder.append(fqn);
+ builder.append(", methodName="); //$NON-NLS-1$
+ builder.append(methodName);
+ builder.append("]"); //$NON-NLS-1$
+ return builder.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((fqn == null) ? 0 : fqn.hashCode());
+ result = prime * result + ((methodName == null) ? 0 : methodName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ Element other = (Element) obj;
+ if (fqn == null) {
+ if (other.fqn != null) {
+ return false;
+ }
+ } else if (!fqn.equals(other.fqn)) {
+ return false;
+ }
+ if (methodName == null) {
+ if (other.methodName != null) {
+ return false;
+ }
+ } else if (!methodName.equals(other.methodName)) {
+ return false;
+ }
+ return true;
+ }
+
+ }
+
+ private final int maxElements = 10;
+
+ @Override
+ public List computeContext(IProgressMonitor monitor, IInteractionContext context, TaskData taskData) {
+
+ TaskAttribute descriptionAttr = taskData.getRoot().getMappedAttribute(TaskAttribute.DESCRIPTION);
+ if (descriptionAttr != null) {
+ String description = descriptionAttr.getValue();
+ if (description != null && description.length() > 0) {
+ return computeContext(monitor, description);
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ public List computeContext(IProgressMonitor m, String description) {
+ SubMonitor monitor = SubMonitor.convert(m);
+ try {
+ List elements = computeElements(description);
+ if (!elements.isEmpty()) {
+
+ monitor.beginTask("Finding Java context elements", elements.size());
+
+ final List javaElements = new ArrayList();
+ try {
+ for (Element element : elements) {
+ try {
+ if (monitor.isCanceled()) {
+ break;
+ }
+ IType type = findTypeInWorkspace(element.fqn);
+ if (type != null) {
+ javaElements.add(type);
+ if (element.methodName != null) {
+ IMethod[] methods = type.getMethods();
+ for (IMethod method : methods) {
+ if (method.getElementName().equals(element.methodName)) {
+ javaElements.add(method);
+ }
+ }
+ }
+ }
+ } catch (CoreException e) {
+ JavaUiBridgePlugin.getDefault().getLog().log(e.getStatus());
+ }
+ monitor.worked(1);
+ }
+ } finally {
+ monitor.done();
+ }
+ return javaElements;
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Public for test purposes only
+ */
+ public List computeElements(String description) throws IOException {
+ List elements = new ArrayList();
+
+ BufferedReader reader = new BufferedReader(new StringReader(description));
+ for (String line = reader.readLine(); line != null && elements.size() < maxElements; line = reader.readLine()) {
+ Matcher matcher = STACK_TRACE_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ String fqn = matcher.group(6);
+ if (fqn != null) {
+ Element element = new Element(fqn, matcher.group(12));
+ elements.add(element);
+ }
+ }
+ }
+ return elements;
+ }
+}