]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/text/javadoc/JavadocContentAssistInvocationContext.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / text / javadoc / JavadocContentAssistInvocationContext.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2005, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.text.javadoc;
12
13import java.util.ArrayList;
14import java.util.Collections;
15import java.util.List;
16
17import org.eclipse.swt.graphics.Point;
18
19import org.eclipse.core.resources.IFile;
20
21import org.eclipse.jface.text.ITextViewer;
22import org.eclipse.jface.text.contentassist.ICompletionProposal;
23
24import org.eclipse.ui.IEditorInput;
25import org.eclipse.ui.IEditorPart;
26import org.eclipse.ui.part.FileEditorInput;
27
28import org.eclipse.jdt.core.ICompilationUnit;
29import org.eclipse.jdt.core.JavaModelException;
30
31import org.eclipse.jdt.ui.JavaUI;
32import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
33import org.eclipse.jdt.ui.text.java.IJavadocCompletionProcessor;
34import org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext;
35
36
37/**
38 *
39 * @since 3.2
40 */
41public final class JavadocContentAssistInvocationContext extends JavaContentAssistInvocationContext {
42
43 private final int fFlags;
44
45 /**
46 * @param viewer
47 * @param offset
48 * @param editor
49 * @param flags see {@link org.eclipse.jdt.ui.text.java.IJavadocCompletionProcessor#RESTRICT_TO_MATCHING_CASE}
50 */
51 public JavadocContentAssistInvocationContext(ITextViewer viewer, int offset, IEditorPart editor, int flags) {
52 super(viewer, offset, editor);
53 fFlags= flags;
54 }
55
56 /**
57 * Returns the flags for this content assist invocation.
58 *
59 * @return the flags for this content assist invocation
60 * @see org.eclipse.jdt.ui.text.java.IJavadocCompletionProcessor#RESTRICT_TO_MATCHING_CASE
61 */
62 public int getFlags() {
63 return fFlags;
64 }
65
66 /**
67 * Returns the selection length of the viewer.
68 *
69 * @return the selection length of the viewer
70 */
71 public int getSelectionLength() {
72 return getViewer().getSelectedRange().y;
73 }
74
75 /*
76 * @see org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext#equals(java.lang.Object)
77 */
78 @Override
79 public boolean equals(Object obj) {
80 if (!super.equals(obj))
81 return false;
82
83 return fFlags == ((JavadocContentAssistInvocationContext) obj).fFlags;
84 }
85
86 /*
87 * @see org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext#hashCode()
88 */
89 @Override
90 public int hashCode() {
91 return super.hashCode() << 2 | fFlags;
92 }
93
94 public List<ICompletionProposal> generated_3719129671907519056(HTMLTagCompletionProposalComputer htmltagcompletionproposalcomputer) {
95 int flags= getFlags();
96 htmltagcompletionproposalcomputer.fCurrentPos= getInvocationOffset();
97 htmltagcompletionproposalcomputer.fCurrentLength= getSelectionLength();
98 htmltagcompletionproposalcomputer.fRestrictToMatchingCase= (flags & IJavadocCompletionProcessor.RESTRICT_TO_MATCHING_CASE) != 0;
99
100 ICompilationUnit cu= getCompilationUnit();
101 if (cu == null)
102 return Collections.emptyList();
103 IEditorInput editorInput= new FileEditorInput((IFile) cu.getResource());
104 htmltagcompletionproposalcomputer.fDocument= JavaUI.getDocumentProvider().getDocument(editorInput);
105 if (htmltagcompletionproposalcomputer.fDocument == null) {
106 return null;
107 }
108
109 try {
110 htmltagcompletionproposalcomputer.fResult= new ArrayList<ICompletionProposal>(100);
111 htmltagcompletionproposalcomputer.evalProposals();
112 return htmltagcompletionproposalcomputer.fResult;
113 } catch (JavaModelException e) {
114 htmltagcompletionproposalcomputer.fErrorMessage= e.getLocalizedMessage();
115 } finally {
116 htmltagcompletionproposalcomputer.fResult= null;
117 }
118 return null;
119 }
120
121 public ArrayList<ICompletionProposal> generated_8004475765966742722(LegacyJavadocCompletionProposalComputer legacyjavadoccompletionproposalcomputer) {
122 ICompilationUnit cu= getCompilationUnit();
123 int offset= getInvocationOffset();
124 int length= getSelectionLength();
125 Point selection= getViewer().getSelectedRange();
126 if (selection.y > 0) {
127 offset= selection.x;
128 length= selection.y;
129 }
130
131 ArrayList<ICompletionProposal> result= new ArrayList<ICompletionProposal>();
132
133 IJavadocCompletionProcessor[] processors= legacyjavadoccompletionproposalcomputer.getContributedProcessors();
134 for (int i= 0; i < processors.length; i++) {
135 IJavadocCompletionProcessor curr= processors[i];
136 IJavaCompletionProposal[] proposals= curr.computeCompletionProposals(cu, offset, length, getFlags());
137 if (proposals != null) {
138 for (int k= 0; k < proposals.length; k++) {
139 result.add(proposals[k]);
140 }
141 }
142 }
143 return result;
144 }
145
146}