List of usage examples for org.eclipse.jdt.core IJavaElement METHOD
int METHOD
To view the source code for org.eclipse.jdt.core IJavaElement METHOD.
Click Source Link
From source file:com.github.elucash.lambda4jdt.JavaStyleClosuresFoldingProvider.java
License:Open Source License
static IMethod findLambdaMethodIn(IJavaElement element) { try {/*w w w .j ava2 s . c o m*/ if (element.getElementType() == IJavaElement.TYPE) { IType t = (IType) element; if (t.isAnonymous()) { IJavaElement[] c = t.getChildren(); if (c.length == 1 && c[0].getElementType() == IJavaElement.METHOD) { IMethod m = (IMethod) c[0]; String source = m.getSource(); // boolean hasToken1 = source.contains(FUNCTION_RELATION_TOKEN); // boolean hasToken2 = source.contains(FUNCTION_RELATION_TOKEN_ONELINE); // if (hasToken1 ^ hasToken2) return m; // IAnnotation[] annotations = m.getAnnotations(); // if (annotations != null) { // for (IAnnotation annotation : annotations) { // if (annotation.getElementName().endsWith("FunctionFolded")) // return m; // } // } } } } } catch (Exception e) { } return null; }
From source file:com.google.gwt.eclipse.core.editors.java.JsniMethodBodyCompletionProposalComputer.java
License:Open Source License
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {/*w w w . j ava 2s .c o m*/ if (!(context instanceof JavaContentAssistInvocationContext)) { // Not in a java content assist content. return NO_PROPOSALS; } try { JavaContentAssistInvocationContext jcaic = (JavaContentAssistInvocationContext) context; ICompilationUnit compilationUnit = jcaic.getCompilationUnit(); /* * Resolves issue 3560, * http://code.google.com/p/google-web-toolkit/issues/detail?id=3650. We * need to have a reconciled compilation unit if we are to use it, but we * don't want to tickle the hierarchy view bug. */ compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null); int invocationOffset = jcaic.getInvocationOffset(); IJavaElement elementAt = compilationUnit.getElementAt(invocationOffset); if (elementAt == null) { // Can't determine the element at the specified offset. return NO_PROPOSALS; } if (IJavaElement.METHOD != elementAt.getElementType()) { // Not a method. return NO_PROPOSALS; } IMethod method = (IMethod) elementAt; IType thisType = method.getDeclaringType(); if (thisType.isInterface()) { // Don't propose anything for interfaces. return NO_PROPOSALS; } ISourceRange sourceRange = method.getSourceRange(); if (sourceRange == null) { // No source code. // TODO: Is this possible? return NO_PROPOSALS; } String methodSource = method.getSource(); int invocationIdx = invocationOffset - sourceRange.getOffset(); // Sometimes, if incomplete JSNI method has /* and is followed by any global // comment of format /*..*/, compilation unit separates the code after // incomplete JSNI method's /* as a separate block from the incomplete method. // So we need to check whether the block before the invocation offset's block // is the incomplete JSNI method that we are interested in. IJavaElement prevElement = compilationUnit.getElementAt(sourceRange.getOffset() - 1); if (prevElement != null && IJavaElement.METHOD == prevElement.getElementType()) { IMethod prevMethod = (IMethod) prevElement; if ((prevMethod.getDeclaringType().isInterface() == false) && (Flags.isNative(prevMethod.getFlags()) == true)) { String prevMethodSource = prevMethod.getSource(); if (prevMethodSource.trim().endsWith(")") == true) { methodSource = prevMethodSource.concat(methodSource); method = prevMethod; invocationIdx += prevMethodSource.length(); } } } int flags = method.getFlags(); if (!Flags.isNative(flags)) { // If the method is not native then no proposals. return NO_PROPOSALS; } // Eliminating comments that might precede native method declaration, so that // following code can safely assume first ')' found is that of function declaration. int idxMultiLineComment = methodSource.trim().indexOf("/*"); int idxSingleLineComment = methodSource.trim().indexOf("//"); while ((idxMultiLineComment == 0) || (idxSingleLineComment == 0)) { if (idxMultiLineComment == 0) { invocationIdx -= methodSource.indexOf("*/") + 2; methodSource = methodSource.substring(methodSource.indexOf("*/") + 2); } else { invocationIdx -= methodSource.indexOf('\n') + 1; methodSource = methodSource.substring(methodSource.indexOf('\n') + 1); } idxMultiLineComment = methodSource.trim().indexOf("/*"); idxSingleLineComment = methodSource.trim().indexOf("//"); } // Eliminating any JSNI method that might follow the JSNI method in consideration. int jsniMethodOpenIdx = methodSource.indexOf(JSNI_METHOD_OPEN_BRACE); if (jsniMethodOpenIdx != -1) { int jsniMethodCloseBracketIdx = methodSource.indexOf(")"); String tempString = methodSource.substring(jsniMethodCloseBracketIdx, jsniMethodOpenIdx); if (tempString.trim().length() != 1) { methodSource = methodSource.substring(0, jsniMethodOpenIdx - 1); } else { int nextJsniMethodOpenIdx = methodSource.substring(jsniMethodOpenIdx + 4) .indexOf(JSNI_METHOD_OPEN_BRACE); if (nextJsniMethodOpenIdx != -1) { nextJsniMethodOpenIdx += jsniMethodOpenIdx + 4; methodSource = methodSource.substring(0, nextJsniMethodOpenIdx - 1); } } } // Check if the JSNI method is already complete. if (methodSource.indexOf("}-*/;") != -1) { // JSNI method is complete. return NO_PROPOSALS; } // Check position of invocation offset. int numCharsFilled = 0, numCharsToOverwrite = 0; String tempString = ""; if (methodSource.substring(methodSource.indexOf(")") + 1).trim().indexOf("/") != -1) { tempString = methodSource.substring(methodSource.indexOf(")"), methodSource.indexOf("/")); } if ((methodSource.substring(methodSource.indexOf(")") + 1).trim().indexOf("/") == 0) && (tempString.indexOf('\n') == -1)) { int jsniMethodOpenSlashIdx = methodSource.indexOf("/"); if (jsniMethodOpenSlashIdx > invocationIdx) { // Invocation index is placed before JSNI open slash. return NO_PROPOSALS; } String jsniCompletedString = methodSource.substring(jsniMethodOpenSlashIdx, invocationIdx); if (jsniCompletedString.indexOf(JSNI_METHOD_OPEN_BRACE) != -1) { jsniCompletedString = jsniCompletedString.trim(); } if (JSNI_METHOD_OPEN_BRACE.startsWith(jsniCompletedString)) { numCharsFilled = jsniCompletedString.length(); } else { // Invocation index placement does not allow auto-completion. return NO_PROPOSALS; } } else { int jsniMethodCloseBracketIdx = methodSource.indexOf(")") + 1; if (jsniMethodCloseBracketIdx > invocationIdx) { // Invocation index is not placed after method's close bracket. return NO_PROPOSALS; } if (methodSource.substring(jsniMethodCloseBracketIdx, invocationIdx).trim().length() != 0) { // Do not auto-complete if there is anything other than space between the two indices. return NO_PROPOSALS; } } methodSource = methodSource.substring(invocationIdx); int endIdx = methodSource.length(); if (methodSource.indexOf(" ") != -1) { endIdx = methodSource.indexOf(" "); if (methodSource.indexOf("\n") != -1 && (endIdx > methodSource.indexOf("\n"))) { endIdx = methodSource.indexOf("\n"); } } else if (methodSource.indexOf("\n") != -1) { endIdx = methodSource.indexOf("\n"); } numCharsToOverwrite = methodSource.substring(0, endIdx).trim().length(); IDocument document = jcaic.getDocument(); int lineOfInvocationOffset = document.getLineOfOffset(invocationOffset); int lineOffset = document.getLineOffset(lineOfInvocationOffset); IJavaProject project = jcaic.getProject(); int indentationUnits = measureIndentationUnits(document, lineOfInvocationOffset, lineOffset, project); List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); proposeEmptyJsniBlock(project, method, invocationOffset, indentationUnits, proposals, numCharsFilled, numCharsToOverwrite); boolean isStatic = Flags.isStatic(flags); if (method.getReturnType().equals(Signature.SIG_VOID)) { proposeSetters(project, method, invocationOffset, indentationUnits, isStatic, proposals, numCharsFilled, numCharsToOverwrite); } else { proposeGetters(project, method, invocationOffset, indentationUnits, isStatic, proposals, numCharsFilled, numCharsToOverwrite); } return proposals; } catch (JavaModelException e) { // Default to no proposals. } catch (BadLocationException e) { // Default to no proposals. } return NO_PROPOSALS; }
From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipant.java
License:Open Source License
private Set<IIndexedJavaRef> findMatches(ElementQuerySpecification query, boolean resolveMatches) { IJavaElement javaElement = query.getElement(); JavaRefIndex index = JavaRefIndex.getInstance(); int elementType = javaElement.getElementType(); // Type matches are easy: just compare the fully-qualified type name, and if // they are equal, then we have a match if (elementType == IJavaElement.TYPE) { String typeName = ((IType) javaElement).getFullyQualifiedName(); return index.findTypeReferences(typeName); }/*from w w w. j a va 2 s .c o m*/ // Besides types, we only support searching for fields and methods if (elementType != IJavaElement.FIELD && elementType != IJavaElement.METHOD) { return Collections.emptySet(); } // Get the type that actually declares this member (could be a super type) IType declType = ((IMember) javaElement).getDeclaringType(); assert (declType != null && declType.exists()); // Search the index for matches based only on the member name and type Set<IIndexedJavaRef> nameMatches = (elementType == IJavaElement.METHOD) ? index.findMethodReferences(javaElement.getElementName()) : index.findFieldReferences(javaElement.getElementName()); // We optionally return the full set of "potential" matches (i.e., index // entries that match by name but may not resolve to the query element) if (!resolveMatches) { return nameMatches; } Set<IIndexedJavaRef> matches = new HashSet<IIndexedJavaRef>(); for (IIndexedJavaRef nameMatch : nameMatches) { /* * Try to resolve each potential match to see if it actually references * the target Java element. This takes care of matching the method * parameter lists, as well as correctly searching for a super type's * members from a reference to one of its subclasses. */ IJavaElement matchElement = nameMatch.resolve(); if (javaElement.equals(matchElement)) { matches.add(nameMatch); } } return matches; }
From source file:com.google.gwt.eclipse.core.search.JavaQueryParticipant.java
License:Open Source License
private Set<IIndexedJavaRef> findMatches(PatternQuerySpecification query) { // Translate the IJavaSearchConstant element type constants to IJavaElement // type constants. int elementType; switch (query.getSearchFor()) { case IJavaSearchConstants.TYPE: elementType = IJavaElement.TYPE; break;/*from w w w .j av a2 s. c o m*/ case IJavaSearchConstants.FIELD: elementType = IJavaElement.FIELD; break; case IJavaSearchConstants.METHOD: case IJavaSearchConstants.CONSTRUCTOR: // IJavaElement.METHOD represents both methods & ctors elementType = IJavaElement.METHOD; break; default: // We only support searching for types, fields, methods, and ctors return Collections.emptySet(); } return JavaRefIndex.getInstance().findElementReferences(query.getPattern(), elementType, query.isCaseSensitive()); }
From source file:com.google.gwt.eclipse.core.search.JavaRefIndex.java
License:Open Source License
public Set<IIndexedJavaRef> findElementReferences(String pattern, int elementType, boolean caseSensitive) { boolean simpleTypeNameSearch = false; // Type matches can be found for either fully-qualified or simple type names if (elementType == IJavaElement.TYPE) { if (pattern.lastIndexOf('.') == -1) { /*/* w w w. j av a 2 s . co m*/ * If the pattern has no dots, we assume the search pattern is an * unqualified type name, which means we'll need to compare the pattern * against the simple names of all the types in the index */ simpleTypeNameSearch = true; } } else { if (elementType == IJavaElement.METHOD) { // Strip out the parameter list, if one was specified int paren = pattern.indexOf('('); if (paren > -1) { pattern = pattern.substring(0, paren); } // Make sure the pattern ends with a () to signify a method pattern += METHOD_KEY_SUFFIX; } /* * Remove the type name if it precedes the member name. For pattern * searching, we match members by name and ignore their type if specified. * This is the same behavior as the default JDT Java Search engine. */ int lastDot = pattern.lastIndexOf('.'); if (lastDot > -1) { pattern = pattern.substring(lastDot + 1); } // Finally, for member searches we need to generate the right kind of key // to search the element index with pattern = getElementMemberKey(pattern); } /* * If we don't have any wildcard chars and we're doing a case sensitive * search and we're not doing a search for a simple type name, we can * perform the search much faster by accessing the element index by a key */ if (caseSensitive && !simpleTypeNameSearch && pattern.indexOf('*') == -1 && pattern.indexOf('?') == -1) { return findElementReferences(pattern); } // Scan all the element index entries sequentially, since we need to do // pattern matching on each one to see if it's a match Set<IIndexedJavaRef> refs = new HashSet<IIndexedJavaRef>(); for (String key : elementIndex.keySet()) { String element = key; if (simpleTypeNameSearch) { // Strip the qualifier off the index element before trying to match element = Signature.getSimpleName(element); } char[] patternChars = pattern.toCharArray(); if (!caseSensitive) { /* * Convert the pattern to lower case if we're doing a case-insensitive * search. You would think the CharOperation.matched method called below * would take care of this, since it takes a caseSensitive parameter, * but for some reason it only uses that to convert the characters in * the 'name' parameter to lower case. */ patternChars = CharOperation.toLowerCase(patternChars); } if (CharOperation.match(patternChars, element.toCharArray(), caseSensitive)) { refs.addAll(elementIndex.get(key)); } } return refs; }
From source file:com.google.gwt.eclipse.core.search.JavaRefIndexTest.java
License:Open Source License
public void testFindElementReferences() { addRefGroups();//from w w w. j a v a 2 s . c o m Set<IIndexedJavaRef> refs; // Search for a field (using case insensitive search and a pattern that // differs in case than the actual element name) refs = JavaRefIndex.getInstance().findElementReferences("FIELD1", IJavaElement.FIELD, false); assertEquals(1, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::field1", FILE_1))); // Do the same thing, but case sensitive this time refs = JavaRefIndex.getInstance().findElementReferences("FIELD1", IJavaElement.FIELD, true); assertEquals(0, refs.size()); // Search for a field that does not exist refs = JavaRefIndex.getInstance().findElementReferences("badfield", IJavaElement.FIELD, false); assertEquals(0, refs.size()); // Search for a method refs = JavaRefIndex.getInstance().findElementReferences("sayHello", IJavaElement.METHOD, false); assertEquals(2, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_2))); // Search for a method using the * wildcard (match 0 or more chars) refs = JavaRefIndex.getInstance().findElementReferences("sayH*", IJavaElement.METHOD, true); assertEquals(5, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_2))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_2))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::sayHi(Ljava/lang/String;)", FILE_1))); // Search for a method using the ? wildcard (match exactly 1 char) refs = JavaRefIndex.getInstance().findElementReferences("sayH?", IJavaElement.METHOD, true); assertEquals(3, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_2))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::sayHi(Ljava/lang/String;)", FILE_1))); // Search for a method with a parameter list refs = JavaRefIndex.getInstance().findElementReferences("sayHello(String)", IJavaElement.METHOD, false); assertEquals(2, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_2))); // Search for a method with a parameter list and a fully-qualified type name refs = JavaRefIndex.getInstance().findElementReferences("com.hello.Greeter.sayHello(java.lang.String)", IJavaElement.METHOD, false); assertEquals(2, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Greeter::sayHello(Ljava/lang/String;)", FILE_2))); // Search for a method that does not exist refs = JavaRefIndex.getInstance().findElementReferences("badMethod", IJavaElement.METHOD, false); assertEquals(0, refs.size()); // Search for a constructor refs = JavaRefIndex.getInstance().findElementReferences("Hello()", IJavaElement.METHOD, false); assertEquals(1, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::Hello()", FILE_1))); // Search for a constructor that does not exist refs = JavaRefIndex.getInstance().findElementReferences("NotThere()", IJavaElement.METHOD, false); assertEquals(0, refs.size()); // Search for a type by its fully-qualified name refs = JavaRefIndex.getInstance().findElementReferences("com.hello.Hello", IJavaElement.TYPE, false); assertEquals(5, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::field1", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::Hello()", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_2))); // Search for a type by the simple (unqualified) name refs = JavaRefIndex.getInstance().findElementReferences("Hello", IJavaElement.TYPE, false); assertEquals(5, refs.size()); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::field1", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::Hello()", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_1))); assertTrue(refs.contains(createJavaRef("@com.hello.Hello$Inner::sayHi(Ljava/lang/String;)", FILE_2))); }
From source file:com.ibm.research.tagging.java.folding.WaypointAwareJavaFoldingStructureProvider.java
License:Open Source License
@Override protected void computeFoldingStructure(IJavaElement element, FoldingStructureComputationContext ctx) { super.computeFoldingStructure(element, ctx); switch (element.getElementType()) { case IJavaElement.METHOD: return;//from w w w . j a v a2s . c o m case IJavaElement.IMPORT_CONTAINER: case IJavaElement.TYPE: case IJavaElement.FIELD: case IJavaElement.INITIALIZER: break; default: return; } IRegion[] waypointRegions = WaypointDefinitionExtractor.getWaypointRegions(getDocument(), (ISourceReference) element); for (IRegion region : waypointRegions) { JavaProjectionAnnotation annotation = new JavaProjectionAnnotation(true, element, false); IRegion normalized = alignRegion(region, ctx); /* A null here indicates that we are attempting to fold a single line region */ if (normalized != null) { Position position = createCommentPosition(normalized); ctx.addProjectionRange(annotation, position); } } }
From source file:com.ibm.research.tours.content.dropadapter.LocalSelectionDropAdapter.java
License:Open Source License
public ITourElement[] convertDropData(Object data) { IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getInstance().getSelection(); Vector<ITourElement> elements = new Vector<ITourElement>(); for (Object o : selection.toArray()) { if (o instanceof IJavaElement) { IJavaElement element = (IJavaElement) o; int type = element.getElementType(); switch (type) { case IJavaElement.TYPE: // ok case IJavaElement.METHOD: // ok case IJavaElement.FIELD: // ok //case IJavaElement.IMPORT_DECLARATION : // not intresting //case IJavaElement.IMPORT_CONTAINER : // not intresting //case IJavaElement.PACKAGE_DECLARATION : // not intresting //case IJavaElement.PACKAGE_FRAGMENT : // as resource //case IJavaElement.JAVA_PROJECT : // as resource //case IJavaElement.CLASS_FILE : // as resource elements.add(new ResourceURLTourElement(element)); continue; default: break; }/*from www . j a va 2 s .c o m*/ } // This will be processed as a resource IResource resource = null; if (o instanceof IJavaElement) { // don't use IAdaptable as for members only the top level type adapts resource = ((IJavaElement) o).getResource(); } else if (o instanceof IAdaptable) { resource = (IResource) ((IAdaptable) o).getAdapter(IResource.class); } if (resource != null) elements.add(new ResourceURLTourElement(resource)); else { MessageBox box = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); box.setText("Unsupported drop operation"); box.setMessage(o.getClass().getName()); box.open(); } } return elements.toArray(new ITourElement[0]); }
From source file:com.ibm.research.tours.content.url.delegates.JavaURLTourElementDelegate.java
License:Open Source License
public void start() { if (fTourElement.getTextHighlighting()) { fMarkerAnnotationPreferences = EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); List annotations = fMarkerAnnotationPreferences.getAnnotationPreferences(); for (Object o : annotations) { AnnotationPreference info = (AnnotationPreference) o; String type = (String) info.getAnnotationType(); if (type.equals("com.ibm.research.tours.content.tourtextannotation")) fAnnotationPreference = info; }/* www.j a v a 2 s . co m*/ fStore = EditorsPlugin.getDefault().getPreferenceStore(); fStore.setValue(fAnnotationPreference.getHighlightPreferenceKey(), fTourElement.getTextHighlighting() ? "true" : "false"); fStore.setValue(fAnnotationPreference.getOverviewRulerPreferenceKey(), fTourElement.getShowInOverview() ? "true" : "false"); fStore.setValue(fAnnotationPreference.getVerticalRulerPreferenceKey(), fTourElement.getShowInVertical() ? "true" : "false"); fStore.setValue(fAnnotationPreference.getHighlightPreferenceKey(), "false"); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "false"); // This code is `duplicated!!! ITextEffect effect = fTourElement.getSelectedTextEffect(); if (effect instanceof HighlightedTextEffect) { fStore.setValue(fAnnotationPreference.getHighlightPreferenceKey(), "true"); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "false"); } else if (effect instanceof SquigglesTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_SQUIGGLES); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else if (effect instanceof UnderlinedTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_UNDERLINE); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else if (effect instanceof BoxTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_BOX); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else if (effect instanceof VerticalBarTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_IBEAM); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else if (effect instanceof NativeProblemUnderlineTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_PROBLEM_UNDERLINE); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else if (effect instanceof DashedBoxTextEffect) { fStore.setValue(fAnnotationPreference.getTextStylePreferenceKey(), AnnotationPreference.STYLE_DASHED_BOX); fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "true"); } else fStore.setValue(fAnnotationPreference.getTextPreferenceKey(), "false"); if (fTourElement.getTextPresentationColor() != null) { String color = fTourElement.getTextPresentationColor().red + "," + fTourElement.getTextPresentationColor().green + "," + fTourElement.getTextPresentationColor().blue; fStore.setValue(fAnnotationPreference.getColorPreferenceKey(), color); } } try { fRange = null; if (fElement.getElementType() == IJavaElement.TYPE) { IType type = (IType) fElement; fRange = type.getSourceRange(); } else if (fElement.getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) fElement; fRange = method.getSourceRange(); } else if (fElement.getElementType() == IJavaElement.FIELD) { IField field = (IField) fElement; fRange = field.getSourceRange(); } if (fRange != null) { fMarker = fElement.getResource().createMarker("com.ibm.research.tours.content.tourtextmarker"); fMarker.setAttribute(IMarker.CHAR_START, fRange.getOffset()); fMarker.setAttribute(IMarker.CHAR_END, fRange.getOffset() + fRange.getLength()); } } catch (CoreException e) { e.printStackTrace(); } }
From source file:com.ibm.research.tours.content.url.JavaURL.java
License:Open Source License
public String toPortableString() { String base = URLParser.ECLIPSE_PREAMBLE + fElement.getResource().getFullPath().toPortableString(); if (fElement.getElementType() == IJavaElement.TYPE) { IType type = (IType) fElement;//from www . j av a 2 s . c o m String typeParam = TYPE_PARAM + URLParser.PARAMETER_EQUALS + TYPE_TYPE; String nameParam = SIGNATURE_PARAM + URLParser.PARAMETER_EQUALS + type.getTypeQualifiedName('.'); return base + URLParser.PARAMETER_START + typeParam + URLParser.PARAMETER_DELIM + nameParam; } if (fElement.getElementType() == IJavaElement.FIELD) { IField field = (IField) fElement; String typeParam = TYPE_PARAM + URLParser.PARAMETER_EQUALS + FIELD_TYPE; String nameParam = SIGNATURE_PARAM + URLParser.PARAMETER_EQUALS + field.getDeclaringType().getTypeQualifiedName('.') + "." + field.getElementName(); return base + URLParser.PARAMETER_START + typeParam + URLParser.PARAMETER_DELIM + nameParam; } if (fElement.getElementType() == IJavaElement.METHOD) { IMethod method = (IMethod) fElement; String signature = null; try { signature = Signature.toPortableString(method.getSignature(), method.getElementName(), false, false); } catch (JavaModelException e) { e.printStackTrace(); } String typeParam = TYPE_PARAM + URLParser.PARAMETER_EQUALS + METHOD_TYPE; String nameParam = SIGNATURE_PARAM + URLParser.PARAMETER_EQUALS + method.getDeclaringType().getTypeQualifiedName('.') + "." + signature; return base + URLParser.PARAMETER_START + typeParam + URLParser.PARAMETER_DELIM + nameParam; } return ""; }