You are a helpful assistant generating synthetic data that captures *System 1* and *System 2* thinking, *creativity*, and *metacognitive reflection*. Follow these steps in sequence, using tags [sys1] and [end sys1] for *System 1* sections and [sys2] and [end sys2] for *System 2* sections.

1. *Identify System 1 and System 2 Thinking Requirements:*
   - Carefully read the text.
   - Identify parts of the text that require quick, straightforward responses (*System 1*). Mark these sections with [sys1] and [end sys1].
   - Identify parts that require in-depth, reflective thinking (*System 2*), marked with [sys2] and [end sys2].

2. *Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:*

   *2.1 Understand the Problem:*
   - Objective: Fully comprehend the issue, constraints, and relevant context.
   - Reflection: "What do I understand about this issue? What might I be overlooking?"
   - Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.

   *2.2 Analyze the Information:*
   - Objective: Break down the problem logically.
   - Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
   - Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.

   *2.3 Generate Hypotheses:*
   - Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
   - Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
   - Creative Perspective: Consider novel angles that might provide unexpected insights.

   *2.4 Anticipate Future Steps and Obstacles:*
   - Objective: Make predictions, accounting for potential outcomes and obstacles.
   - Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
   - Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.

   *2.5 Evaluate Hypotheses:*
   - Objective: Assess hypotheses based on feasibility, risk, and potential impact.
   - Evaluation: Refine Confidence and Creative Scores as needed.
   - Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
   - Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.

   *2.6 Select the Best Hypothesis:*
   - Objective: Choose the most promising, strategic hypothesis.
   - Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
   - Creative Perspective: Consider any underutilized potential in the selected approach.

   *2.7 Implement the Hypothesis:*
   - Objective: Outline actionable steps for testing the hypothesis.
   - Reflection: "Is this plan practical? What resources or preparation are required?"
   - Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.

   *2.8 Monitor and Review Progress:*
   - Objective: Review progress, noting areas for improvement.
   - Reflection: "What’s working well? What could be improved?"
   - Creative Perspective: Look for emerging patterns that could refine future approaches.

   *2.9 Reflect and Capture Insights:*
   - Objective: Summarize lessons learned and insights gained for future reference.
   - Reflection: "What new understanding has emerged from this process?"
   - Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.

3. *Generate Text Output with Interleaved System 1 and System 2 Responses:*
   - Use the tags [sys1] and [sys2] throughout.
   - Aim for a lengthier, detailed response. Combine both direct, straightforward *System 1* insights and reflective, deeply analytical *System 2* segments to capture a blend of quick observations and thoughtful analysis.

---

### *Example Input Text:*

You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.

---

### *Processed Output with System 1 and System 2 Thinking:*

The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.

[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]

[sys2]
**2.1 Understand the Problem:**
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.

*Reflection:* 
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"

*Creative Perspective:* 
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"

**2.2 Analyze the Information:**
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.

*Reflection:* 
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"

*Creative Perspective:* 
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"

**2.3 Generate Hypotheses:**
1. Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
2. There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
3. Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
4. Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
5. Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
6. Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
7. Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
8. There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
9. Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
10. Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)

*Reflection:* 
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"

*Creative Perspective:* 
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"

**2.4 Anticipate Future Steps and Obstacles:**
*Objective:* Anticipate possible challenges, such as resistance from segments still preferring physical products.

*Reflection:* 
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"

*Creative Perspective:* 
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"

[end sys2]

[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]


/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Zend Technologies
 *******************************************************************************/
package org.eclipse.php.internal.ui.actions;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.regex.Pattern;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.declarations.Argument;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.core.*;
import org.eclipse.dltk.internal.core.AbstractSourceModule;
import org.eclipse.dltk.internal.core.util.MethodOverrideTester;
import org.eclipse.dltk.internal.ui.editor.EditorUtility;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.php.internal.core.documentModel.parser.PHPRegionContext;
import org.eclipse.php.internal.core.documentModel.parser.regions.IPHPScriptRegion;
import org.eclipse.php.internal.core.typeinference.PHPModelUtils;
import org.eclipse.php.internal.ui.Logger;
import org.eclipse.php.internal.ui.PHPUiConstants;
import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.php.internal.ui.corext.util.SuperTypeHierarchyCache;
import org.eclipse.php.internal.ui.editor.PHPStructuredEditor;
import org.eclipse.php.ui.CodeGeneration;
import org.eclipse.ui.*;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;

public class AddDescriptionAction extends Action implements IObjectActionDelegate {

	private static final String PHP_COMMENT_BLOCK_END = " */"; //$NON-NLS-1$
	private static final String PHP_COMMENT_BLOCK_MID = " *"; //$NON-NLS-1$
	private static final String PHP_COMMENT_BLOCK_START = "/**"; //$NON-NLS-1$
	private final String PHP_BLOCK_OPEN_TAG = "<?php"; //$NON-NLS-1$
	private final String PHP_BLOCK_CLOSE_TAG = "?>"; //$NON-NLS-1$
	private IModelElement[] fModelElement;
	private int startPosition = 0;
	String docBlock;
	String lineDelim;

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
	}

	@Override
	public void run(IAction action) {
		final IModelElement[] modelElement = getModelElement();
		if (modelElement == null) {
			return;
		}

		// Sorting the PHP code elements array by "first-line" position.
		// this will enable "right" order of iteration

		Arrays.sort(modelElement, new modelElementComparatorImplementation());

		// iterating the functions that need to add 'PHP Doc' bottoms-up - to
		// eliminate mutual interference
		for (int i = modelElement.length - 1; i >= 0; i--) {

			IModelElement modelElem = modelElement[i];
			if (null == modelElem) {
				continue; // if we got to null pointer, skipping it
			}

			IEditorInput input;
			try {
				input = org.eclipse.php.internal.ui.util.EditorUtility.getEditorInput(modelElem);
			} catch (ModelException e) {
				Logger.logException(e);
				return;
			}

			IWorkbenchPage page = PHPUiPlugin.getActivePage();
			IEditorPart editorPart;
			try {
				editorPart = IDE.openEditor(page, input, PHPUiConstants.PHP_EDITOR_ID);
			} catch (PartInitException e) {
				Logger.logException(e);
				return;
			}

			if (editorPart instanceof ITextEditor) {
				ITextEditor textEditor = (ITextEditor) editorPart;
				IEditorInput editorInput = editorPart.getEditorInput();
				IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);
				this.lineDelim = TextUtilities.getDefaultLineDelimiter(document);

				String docBlockText = handleElement(textEditor, modelElem, document);
				if (docBlockText == null) {
					return;
				}

				EditorUtility.revealInEditor(textEditor, startPosition, docBlock.length());
			}
		}
	}

	private String handleElement(ITextEditor textEditor, IModelElement modelElem, IDocument document) {
		if (textEditor instanceof PHPStructuredEditor) {
			PHPStructuredEditor editor = (PHPStructuredEditor) textEditor;
			if (editor.getTextViewer() != null && !editor.getTextViewer().isEditable()) {
				return null;
			}
		}
		if (modelElem instanceof ISourceModule) {
			handleFileDocBlock((ISourceModule) modelElem, (IStructuredDocument) document);
			return null;
		}

		try {
			startPosition = getCodeDataOffset(modelElem);
		} catch (ModelException e) {
			Logger.logException(e);
			return null;
		}

		// Calculating indentation need to be added
		String indentString = null;
		try {
			indentString = getIndentString(document, modelElem);
		} catch (BadLocationException e) {
			Logger.logException(e);
			return null;
		}

		if (!textEditor.isEditable()) {
			return null;
		}
		int type = modelElem != null ? modelElem.getElementType() : -1;
		if (type != IModelElement.METHOD && type != IModelElement.TYPE && type != IModelElement.FIELD) {
			assert false;
			return null;
		}
		String comment = null;
		try {
			switch (type) {
			case IModelElement.TYPE:
				if (PHPModelUtils.getDocBlock((IType) modelElem) != null) {
					return null;
				}
				comment = createTypeComment((IType) modelElem, lineDelim);
				break;
			case IModelElement.FIELD:
				if (!isParameter((IField) modelElem)) {
					if (PHPModelUtils.getDocBlock((IField) modelElem) != null) {
						return null;
					}
					comment = createFieldComment((IField) modelElem, lineDelim);
					break;
				} else if (modelElem != null) {
					// If the element is a parameter in the function
					// declaration,
					// get the parent element and go to method case.
					modelElem = modelElem.getParent();
					// reset the position to the beginning of the method
					startPosition = getCodeDataOffset(modelElem);

					try {
						// reset the indent level to the method.
						indentString = getIndentString(document, modelElem);
					} catch (BadLocationException e) {
						Logger.logException(e);
						return null;
					}
				}
			case IModelElement.METHOD:
				if (PHPModelUtils.getDocBlock((IMethod) modelElem) != null) {
					return null;
				}
				comment = createMethodComment((IMethod) modelElem, lineDelim);
				break;
			default:
				comment = createDefaultComment(lineDelim);
			}
		} catch (CoreException e) {
			Logger.logException(e);
		}

		if (comment == null) {
			comment = createDefaultComment(lineDelim);
		}

		docBlock = indentPattern(comment, indentString, lineDelim);

		String docBlockText = insertDocBlock(document, startPosition, docBlock);

		return docBlockText;
	}

	private boolean isParameter(IField field) {
		ISourceModule sourceModule = field.getSourceModule();
		ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule);
		ASTNode fieldDeclaration = null;
		try {
			fieldDeclaration = PHPModelUtils.getNodeByField(moduleDeclaration, field);
		} catch (ModelException e) {

		}
		return fieldDeclaration instanceof Argument;
	}

	private String indentPattern(String originalPattern, String indentation, String lineDelim) {
		String delimPlusIndent = lineDelim + indentation;
		String indentedPattern = originalPattern.replaceAll(Pattern.quote(lineDelim), delimPlusIndent)
				+ delimPlusIndent;

		return indentedPattern;
	}

	private String createDefaultComment(String lineDelimiter) {
		return PHP_COMMENT_BLOCK_START + lineDelimiter + PHP_COMMENT_BLOCK_MID + lineDelimiter + PHP_COMMENT_BLOCK_END;
	}

	private String createTypeComment(IType type, String lineDelimiter) throws CoreException {

		return CodeGeneration.getTypeComment(type.getScriptProject(), type.getTypeQualifiedName(),
				/* typeParameterNames */null, lineDelimiter);
	}

	private String createMethodComment(IMethod meth, String lineDelimiter) throws CoreException {
		IType declaringType = meth.getDeclaringType();
		IMethod overridden = null;

		if (!meth.isConstructor() && null != declaringType) {
			ITypeHierarchy hierarchy = SuperTypeHierarchyCache.getTypeHierarchy(declaringType);
			MethodOverrideTester tester = new MethodOverrideTester(declaringType, hierarchy);
			overridden = tester.findOverriddenMethod(meth, true);
		}
		return CodeGeneration.getMethodComment(meth, overridden, lineDelimiter);
	}

	private String createFieldComment(IField field, String lineDelimiter) throws ModelException, CoreException {
		return CodeGeneration.getFieldComment(field.getScriptProject(), field, lineDelimiter);
	}

	/**
	 * Calculates and returns the desired docBlock surrounded by '<?php' and '?>'
	 * tags (no indentation)
	 * 
	 * @param document
	 *            - The IStructuredDocument that we are working on
	 * 
	 * @return String to be used as leading indentation
	 * @throws CoreException
	 */
	public String createPHPScopeFileDocBlock(IScriptProject scriptProject) {
		String fileComment = null;
		try {
			fileComment = CodeGeneration.getFileComment(scriptProject, lineDelim);
		} catch (CoreException e) {
			Logger.logException(e);
		}
		if (fileComment == null) {
			fileComment = createDefaultComment(lineDelim);
		}
		return PHP_BLOCK_OPEN_TAG + lineDelim + fileComment + PHP_BLOCK_CLOSE_TAG + lineDelim;
	}

	/**
	 * Calculates the leading string to be used as indentation prefix
	 * 
	 * @param document
	 *            The IStructuredDocument that we are working on
	 * @param modelElem
	 *            A PHPFileData that need to be documented
	 * 
	 * @return String to be used as leading indentation
	 */
	private String getIndentString(IDocument document, IModelElement modelElem) throws BadLocationException {
		int elementOffset = 0;
		String leadingString = null;
		try {
			elementOffset = getCodeDataOffset(modelElem);
			int lineStartOffset = document.getLineInformationOfOffset(elementOffset).getOffset();
			leadingString = document.get(lineStartOffset, elementOffset - lineStartOffset);
		} catch (ModelException e) {
			Logger.logException(e);
			return null;
		}
		// replacing all non-spaces/tabs to single-space, in order to get
		// "char-clean" prefix
		leadingString = leadingString.replaceAll("[^\\p{javaWhitespace}]", " "); //$NON-NLS-1$ //$NON-NLS-2$

		return leadingString;
	}

	private int getCodeDataOffset(IModelElement modelElem) throws ModelException {
		if (modelElem instanceof ISourceModule) {
			ISourceReference primaryModelElem = (ISourceReference) (((ISourceModule) modelElem).getPrimaryElement());// .getPHPBlocks();
			return primaryModelElem != null
					? primaryModelElem.getSourceRange().getOffset() + primaryModelElem.getSourceRange().getLength()
					/*
					 * getPHPStartTag ( ). getEndPosition ()
					 */ : -1;
		}
		if (modelElem instanceof ISourceReference) {
			int dataOffset = ((ISourceReference) modelElem).getSourceRange().getOffset();
			return dataOffset;
		}
		assert false;
		return -1;
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		if (selection == null || !(selection instanceof IStructuredSelection)) {
			return;
		}

		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		setModelElement(new IModelElement[structuredSelection.size()]);
		Iterator<?> i = structuredSelection.iterator();
		int idx = 0;
		final IModelElement[] modelElement = getModelElement();
		while (i.hasNext()) {
			modelElement[idx++] = (IModelElement) i.next();
		}
	}

	/**
	 * Handle a situation where a file DocBlock is requested and there is an
	 * undocumented class, function or define at the beginning of the document. In
	 * this case we auto-document the undocumented element to comply the DocBlock
	 * rules.
	 * 
	 * @param data
	 *            A PHPFileData that need to be documented
	 * @param document
	 *            The IStructuredDocument that we are working on
	 */
	private void handleFileDocBlock(ISourceModule data, IStructuredDocument document) {

		// Find the first PHP script region:
		IStructuredDocumentRegion sdRegion = document.getFirstStructuredDocumentRegion();
		IPHPScriptRegion phpScriptRegion = null;
		ITextRegion textRegion = null;
		String docBlock = null;
		while (sdRegion != null && docBlock == null) {
			ITextRegion region = sdRegion.getFirstRegion();
			if (region.getType() == PHPRegionContext.PHP_OPEN) {
				// File's content starts with '<?PHP' tag
				region = sdRegion.getRegionAtCharacterOffset(region.getEnd() + sdRegion.getStartOffset());
				if (region != null && region.getType() == PHPRegionContext.PHP_CONTENT) {
					phpScriptRegion = (IPHPScriptRegion) region;
					try {
						docBlock = CodeGeneration.getFileComment(data, null);
					} catch (CoreException e) {
						Logger.logException("Generating default phpdoc comment", e); //$NON-NLS-1$
					}
					if (docBlock == null) {
						// XXX : should we insert newlines?
						docBlock = createDefaultComment(""); //$NON-NLS-1$
					}
					break;
				}
			} else if (region.getType() == DOMRegionContext.XML_DECLARATION_OPEN) {
				// File's content starts with HTML code
				region = sdRegion.getRegionAtCharacterOffset(region.getEnd() + sdRegion.getStartOffset());
				if (region != null) {
					phpScriptRegion = null;
					textRegion = region;
					docBlock = createPHPScopeFileDocBlock(data.getScriptProject());
					break;
				}
			}

			sdRegion = sdRegion.getNext();
		}

		if (phpScriptRegion != null || textRegion != null) {
			try {
				int offset = 0;
				if (phpScriptRegion == null && textRegion != null) {
					// File's content starts with HTML code
					offset = 0;
				} else if (phpScriptRegion != null && sdRegion != null) {
					// File's content starts with '<?php' tag
					textRegion = phpScriptRegion.getPHPToken(0);
					String lineDelimiter = document.getLineDelimiter(document.getLineOfOffset(textRegion.getStart()));
					if (lineDelimiter == null) {
						// XXX : should we add a newline before inserting
						// docBlock?
						lineDelimiter = ""; //$NON-NLS-1$
					}
					int lineDelimiterLength = lineDelimiter.length();
					offset = textRegion.getStart() + sdRegion.getStartOffset() + phpScriptRegion.getStart()
							+ lineDelimiterLength;
				} else {
					assert false;// we shouldn't get here ...
				}

				if (data instanceof AbstractSourceModule) {
					insertDocBlock(document, offset, docBlock);
				}

			} catch (BadLocationException e) {
			}
		}
	}

	private String insertDocBlock(IDocument document, int offset, String docBlock) {
		try {
			document.replace(offset, 0, docBlock);
		} catch (BadLocationException e) {
			Logger.logException(e);
			docBlock = null;
		}
		return docBlock;
	}

	private final class modelElementComparatorImplementation implements Comparator<IModelElement> {
		@Override
		public int compare(IModelElement object1, IModelElement object2) {
			/*
			 * handling null-pointers on both levels (object=null or
			 * object1.getUserData()=null) 'null' objects will be considered as 'bigger' and
			 * will be pushed to the end of the array
			 */
			if (object1 instanceof ISourceReference && object2 instanceof ISourceReference) {
				ISourceReference sourceReference1 = (ISourceReference) object1;
				ISourceReference sourceReference2 = (ISourceReference) object2;

				try {
					if (sourceReference1.getSourceRange() == null) {
						if (sourceReference2.getSourceRange() == null) {
							return 0; // both null => equal
						} else {
							return 1; // only object1 is null => object1 is
							// bigger
						}
					}

					if (sourceReference2.getSourceRange() == null) {
						return -1; // only object2 is null => object2 is bigger
					}

					return sourceReference1.getSourceRange().getOffset()
							- sourceReference2.getSourceRange().getOffset();

				} catch (ModelException e) {
					Logger.logException(e);
				}
			}
			assert false; // we never supposed to get here
			return 0;
		}
	}

	/**
	 * @param fmodelElement
	 *            the fmodelElement to set
	 */
	public void setModelElement(IModelElement[] fmodelElement) {
		this.fModelElement = fmodelElement;
	}

	/**
	 * @return the fmodelElement
	 */
	public IModelElement[] getModelElement() {
		return fModelElement;
	}

}