org.eclipse.jdt.core.ILocalVariable Java Examples
The following examples show how to use
org.eclipse.jdt.core.ILocalVariable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static ISourceRange getNameRange(IJavaElement element) throws JavaModelException { ISourceRange nameRange = null; if (element instanceof IMember) { IMember member = (IMember) element; nameRange = member.getNameRange(); if ((!SourceRange.isAvailable(nameRange))) { nameRange = member.getSourceRange(); } } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) { nameRange = ((ISourceReference) element).getNameRange(); } else if (element instanceof ISourceReference) { nameRange = ((ISourceReference) element).getSourceRange(); } if (!SourceRange.isAvailable(nameRange) && element.getParent() != null) { nameRange = getNameRange(element.getParent()); } return nameRange; }
Example #2
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static boolean isAvailable(IJavaElement javaElement) throws JavaModelException { if (javaElement == null) return false; if (! javaElement.exists()) return false; if (javaElement.isReadOnly()) return false; // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422 // the Java project is now cheating regarding its children so we shouldn't // call isStructureKnown if the project isn't open. // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474 if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown()) return false; if (javaElement instanceof IMember && ((IMember)javaElement).isBinary()) return false; return true; }
Example #3
Source File: RefactoringAvailabilityTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException { if (element != null && element.exists()) { String type= null; if (element instanceof IMethod) type= ((IMethod) element).getReturnType(); else if (element instanceof IField) { final IField field= (IField) element; if (JdtFlags.isEnum(field)) return false; type= field.getTypeSignature(); } else if (element instanceof ILocalVariable) return true; else if (element instanceof IType) { final IType clazz= (IType) element; if (JdtFlags.isEnum(clazz)) return false; return true; } if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) return false; return true; } return false; }
Example #4
Source File: LambdaMethod.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void getHandleMemento(StringBuffer buff, boolean serializeParent) { if (serializeParent) { ((LambdaExpression) getParent()).getHandleMemento(buff, true, false); } appendEscapedDelimiter(buff, getHandleMementoDelimiter()); escapeMementoName(buff, getElementName()); buff.append(JEM_COUNT); buff.append(this.parameterTypes.length); for (int i = 0, length = this.parameterTypes.length; i < length; i++) { appendEscapedDelimiter(buff, JEM_STRING); escapeMementoName(buff, this.parameterTypes[i]); appendEscapedDelimiter(buff, JEM_STRING); escapeMementoName(buff, this.parameterNameStrings[i]); } appendEscapedDelimiter(buff, JEM_STRING); escapeMementoName(buff, this.returnTypeString); appendEscapedDelimiter(buff, JEM_STRING); escapeMementoName(buff, this.key); ILocalVariable[] arguments = this.elementInfo.arguments; for (int i = 0, length = arguments.length; i < length; i++) { LocalVariable local = (LocalVariable) arguments[i]; local.getHandleMemento(buff, false); } }
Example #5
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Appends the styled label for a local variable. * * @param localVariable the element to render * @param flags the rendering flags. Flags with names starting with 'F_' are considered. */ public void appendLocalVariableLabel(ILocalVariable localVariable, long flags) { if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) { appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags); fBuilder.append(' '); } if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) { appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuilder.append('.'); } fBuilder.append(getElementName(localVariable)); if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE)) { fBuilder.append(JavaElementLabels.DECL_STRING); appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags); } // post qualification if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) { fBuilder.append(JavaElementLabels.CONCAT_STRING); appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); } }
Example #6
Source File: RenameTypeWizardSimilarElementsPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ISourceRange getNameRange(IJavaElement element) throws JavaModelException { if (element instanceof IMember) return ((IMember) element).getNameRange(); else if (element instanceof ILocalVariable) return ((ILocalVariable) element).getNameRange(); else return null; }
Example #7
Source File: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) { return isRenameAvailable(method.getDeclaringType()); } else { return isRenameAvailable(method); } case IJavaElement.FIELD: final IField field = (IField) element; if (Flags.isEnum(field.getFlags())) { return isRenameEnumConstAvailable(field); } else { return isRenameFieldAvailable(field); } case IJavaElement.TYPE_PARAMETER: return isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return isRenameAvailable((ILocalVariable) element); } return false; }
Example #8
Source File: RefactoringAvailabilityTester.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isGeneralizeTypeAvailable(final IJavaElement element) throws JavaModelException { if (element != null && element.exists()) { String type = null; if (element instanceof IMethod) { type = ((IMethod) element).getReturnType(); } else if (element instanceof IField) { final IField field = (IField) element; if (JdtFlags.isEnum(field)) { return false; } type = field.getTypeSignature(); } else if (element instanceof ILocalVariable) { return true; } else if (element instanceof IType) { final IType clazz = (IType) element; if (JdtFlags.isEnum(clazz)) { return false; } return true; } if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) { return false; } return true; } return false; }
Example #9
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Appends the styled label for a local variable. * * @param localVariable the element to render * @param flags the rendering flags. Flags with names starting with 'F_' are considered. */ public void appendLocalVariableLabel(ILocalVariable localVariable, long flags) { if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) { appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags); fBuffer.append(' '); } if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) { appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } fBuffer.append(getElementName(localVariable)); if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE)) { int offset= fBuffer.length(); fBuffer.append(JavaElementLabels.DECL_STRING); appendTypeSignatureLabel(localVariable, localVariable.getTypeSignature(), flags); if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE); } } // post qualification if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) { fBuffer.append(JavaElementLabels.CONCAT_STRING); appendElementLabel(localVariable.getDeclaringMember(), JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS)); } }
Example #10
Source File: Jdt2Ecore.java From sarl with Apache License 2.0 | 5 votes |
/** Create the formal parameters for the given operation. * * @param parameterBuilder the code builder. * @param operation the operation that describes the formal parameters. * @return the parameters. * @throws JavaModelException if the Java model is invalid. * @throws IllegalArgumentException if the signature is not syntactically correct. */ protected IFormalParameterBuilder[] createFormalParametersWith( ParameterBuilder parameterBuilder, IMethod operation) throws JavaModelException, IllegalArgumentException { final boolean isVarargs = Flags.isVarargs(operation.getFlags()); final ILocalVariable[] rawParameters = operation.getParameters(); final FormalParameterProvider parameters = getFormalParameterProvider(operation); final int len = parameters.getFormalParameterCount(); final IFormalParameterBuilder[] paramBuilders = new IFormalParameterBuilder[len]; for (int i = 0; i < len; ++i) { final ILocalVariable rawParameter = rawParameters[i]; final IAnnotation annotation = getAnnotation(rawParameter, DefaultValue.class.getName()); final String defaultValue = (annotation != null) ? extractDefaultValue(operation, annotation) : null; final boolean isV = isVarargs && i == len - 1; String type = parameters.getFormalParameterType(i, isV); if (isV && type.endsWith("[]")) { //$NON-NLS-1$ type = type.substring(0, type.length() - 2); } final IFormalParameterBuilder sarlParameter = parameterBuilder.addParameter(parameters.getFormalParameterName(i)); sarlParameter.setParameterType(type); if (defaultValue != null) { sarlParameter.getDefaultValue().setExpression(defaultValue); } if (isV) { sarlParameter.setVarArg(true); } paramBuilders[i] = sarlParameter; } return paramBuilders; }
Example #11
Source File: RenameSupport.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static RenameSupport create(IJavaElement element, String newName, int flags) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: //return RenameSupport.create((IJavaProject) element, newName, flags); return null; case IJavaElement.PACKAGE_FRAGMENT_ROOT: //return RenameSupport.create((IPackageFragmentRoot) element, newName); return null; case IJavaElement.PACKAGE_FRAGMENT: return RenameSupport.create((IPackageFragment) element, newName, flags); case IJavaElement.COMPILATION_UNIT: return RenameSupport.create((ICompilationUnit) element, newName, flags); case IJavaElement.TYPE: return RenameSupport.create((IType) element, newName, flags); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) { return create(method.getDeclaringType(), newName, flags); } else { return RenameSupport.create((IMethod) element, newName, flags); } case IJavaElement.FIELD: return RenameSupport.create((IField) element, newName, flags); case IJavaElement.TYPE_PARAMETER: return RenameSupport.create((ITypeParameter) element, newName, flags); case IJavaElement.LOCAL_VARIABLE: return RenameSupport.create((ILocalVariable) element, newName, flags); } return null; }
Example #12
Source File: Jdt2Ecore.java From sarl with Apache License 2.0 | 5 votes |
/** Constructor. * @param operation the operation. * @throws JavaModelException if the parameters cannot be retreived. */ JdtFormalParameterList(IMethod operation) throws JavaModelException { this.nb = operation.getNumberOfParameters(); this.names = operation.getParameterNames(); this.types = new String[this.nb]; final ILocalVariable[] unresolvedParameters = operation.getParameters(); for (int i = 0; i < this.nb; ++i) { this.types[i] = resolve(operation, unresolvedParameters[i].getTypeSignature()); } }
Example #13
Source File: RenameLocalVariableProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new rename local variable processor. * @param localVariable the local variable, or <code>null</code> if invoked by scripting */ public RenameLocalVariableProcessor(ILocalVariable localVariable) { fLocalVariable= localVariable; fUpdateReferences= true; if (localVariable != null) { fCu= (ICompilationUnit) localVariable.getAncestor(IJavaElement.COMPILATION_UNIT); } fNewName= ""; //$NON-NLS-1$ fIsComposite= false; }
Example #14
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static ISourceRange getSourceRange(IJavaElement element) throws JavaModelException { ISourceRange sourceRange = null; if (element instanceof IMember) { IMember member = (IMember) element; sourceRange = member.getSourceRange(); } else if (element instanceof ITypeParameter || element instanceof ILocalVariable) { sourceRange = ((ISourceReference) element).getSourceRange(); } else if (element instanceof ISourceReference) { sourceRange = ((ISourceReference) element).getSourceRange(); } if (!SourceRange.isAvailable(sourceRange) && element.getParent() != null) { sourceRange = getSourceRange(element.getParent()); } return sourceRange; }
Example #15
Source File: JavaSourceHover.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Deprecated public String getHoverInfo(ITextViewer textViewer, IRegion region) { IJavaElement[] result= getJavaElementsAt(textViewer, region); fUpwardShiftInLines= 0; fBracketHoverStatus= null; if (result == null || result.length == 0) { return getBracketHoverInfo(textViewer, region); } if (result.length > 1) return null; IJavaElement curr= result[0]; if ((curr instanceof IMember || curr instanceof ILocalVariable || curr instanceof ITypeParameter) && curr instanceof ISourceReference) { try { String source= ((ISourceReference) curr).getSource(); String[] sourceLines= getTrimmedSource(source, curr); if (sourceLines == null) return null; String delim= StubUtility.getLineDelimiterUsed(curr); source= Strings.concatenate(sourceLines, delim); return source; } catch (JavaModelException ex) { //do nothing } } return null; }
Example #16
Source File: JavaElementHyperlinkDeclaredTypeDetector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the type signature of the element. * * @param element an instance of <code>ILocalVariable</code> or <code>IField</code> * @return the type signature of the element * @throws JavaModelException if this element does not exist or if an exception occurs while * accessing its corresponding resource. */ static String getTypeSignature(IJavaElement element) throws JavaModelException { if (element instanceof ILocalVariable) { return ((ILocalVariable)element).getTypeSignature(); } else if (element instanceof IField) { return ((IField)element).getTypeSignature(); } throw new IllegalArgumentException(); }
Example #17
Source File: JavaMatchFilter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean isApplicable(JavaSearchQuery query) { QuerySpecification spec= query.getSpecification(); if (spec instanceof ElementQuerySpecification) { ElementQuerySpecification elementSpec= (ElementQuerySpecification) spec; IJavaElement element= elementSpec.getElement(); return element instanceof IField || element instanceof ILocalVariable; } else if (spec instanceof PatternQuerySpecification) { PatternQuerySpecification patternSpec= (PatternQuerySpecification) spec; return patternSpec.getSearchFor() == IJavaSearchConstants.FIELD; } return false; }
Example #18
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source, JavadocLookup lookup) { Assert.isNotNull(element); Assert.isTrue(element instanceof IMethod || element instanceof ILocalVariable || element instanceof ITypeParameter); fElement = element; fMethod = (IMethod) ((element instanceof ILocalVariable || element instanceof ITypeParameter) ? element.getParent() : element); fJavadoc = javadoc; fSource = source; fJavadocLookup = lookup; }
Example #19
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source) { Assert.isTrue(element instanceof IMember || element instanceof IPackageFragment || element instanceof ILocalVariable || element instanceof ITypeParameter); fElement = element; fMethod = null; fJavadoc = javadoc; fSource = source; fJavadocLookup = JavadocLookup.NONE; }
Example #20
Source File: JavadocContentAccess2.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private String toHTML() { fBuf = new StringBuffer(); fLiteralContent = 0; if (fElement instanceof ILocalVariable || fElement instanceof ITypeParameter) { parameterToHTML(); } else { elementToHTML(); } String result = fBuf.toString(); fBuf = null; return result; }
Example #21
Source File: AbstractInfoView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Computes the contents description that will be displayed for the current element. * * @param part the part that triggered the current element update, or <code>null</code> * @param selection the new selection, or <code>null</code> * @param inputElement the new java element that will be displayed * @param localASTMonitor a progress monitor * @return the contents description for the provided <code>inputElement</code> * @since 3.4 */ protected String computeDescription(IWorkbenchPart part, ISelection selection, IJavaElement inputElement, IProgressMonitor localASTMonitor) { long flags; if (inputElement instanceof ILocalVariable) flags= LOCAL_VARIABLE_TITLE_FLAGS; else if (inputElement instanceof ITypeParameter) flags= TYPE_PARAMETER_TITLE_FLAGS; else flags= TITLE_FLAGS; return JavaElementLabels.getElementLabel(inputElement, flags); }
Example #22
Source File: RenameLocalVariableProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new rename local variable processor. * @param localVariable the local variable, or <code>null</code> if invoked by scripting */ public RenameLocalVariableProcessor(ILocalVariable localVariable) { fLocalVariable= localVariable; fUpdateReferences= true; if (localVariable != null) fCu= (ICompilationUnit) localVariable.getAncestor(IJavaElement.COMPILATION_UNIT); fNewName= ""; //$NON-NLS-1$ fIsComposite= false; }
Example #23
Source File: RenameTypeProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param matchOffset offset of the match * @param parentElement parent element of the match * @return true iff the given search match offset (must be a match of a type * reference) lies before the element name of its enclosing java element, * false if not. In other words: If this method returns true, the match is * the declared type (or return type) of the enclosing element. * @throws JavaModelException should not happen * */ private boolean isInDeclaredType(int matchOffset, IJavaElement parentElement) throws JavaModelException { if (parentElement != null) { int enclosingNameOffset= 0; if (parentElement instanceof IMethod || parentElement instanceof IField) enclosingNameOffset= ((IMember) parentElement).getNameRange().getOffset(); else if (parentElement instanceof ILocalVariable) enclosingNameOffset= ((ILocalVariable) parentElement).getNameRange().getOffset(); return (matchOffset < enclosingNameOffset); } return false; }
Example #24
Source File: RefactoringAvailabilityTester.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isRenameElementAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method= (IMethod) element; if (method.isConstructor()) return isRenameAvailable(method.getDeclaringType()); else return isRenameAvailable(method); case IJavaElement.FIELD: final IField field= (IField) element; if (Flags.isEnum(field.getFlags())) return isRenameEnumConstAvailable(field); else return isRenameFieldAvailable(field); case IJavaElement.TYPE_PARAMETER: return isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return isRenameAvailable((ILocalVariable) element); } return false; }
Example #25
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static RenameSupport createRenameSupport(IJavaElement element, String newName, int flags) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return RenameSupport.create((IJavaProject) element, newName, flags); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return RenameSupport.create((IPackageFragmentRoot) element, newName); case IJavaElement.PACKAGE_FRAGMENT: return RenameSupport.create((IPackageFragment) element, newName, flags); case IJavaElement.COMPILATION_UNIT: return RenameSupport.create((ICompilationUnit) element, newName, flags); case IJavaElement.TYPE: return RenameSupport.create((IType) element, newName, flags); case IJavaElement.METHOD: final IMethod method= (IMethod) element; if (method.isConstructor()) return createRenameSupport(method.getDeclaringType(), newName, flags); else return RenameSupport.create((IMethod) element, newName, flags); case IJavaElement.FIELD: return RenameSupport.create((IField) element, newName, flags); case IJavaElement.TYPE_PARAMETER: return RenameSupport.create((ITypeParameter) element, newName, flags); case IJavaElement.LOCAL_VARIABLE: return RenameSupport.create((ILocalVariable) element, newName, flags); } return null; }
Example #26
Source File: RenameTypeWizardSimilarElementsPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Object getParent(Object element) { if (element instanceof IMember || element instanceof ILocalVariable) { return ((IJavaElement) element).getParent(); } if (element instanceof ICompilationUnit) return null; Assert.isTrue(false, "Should not get here"); //$NON-NLS-1$ return null; }
Example #27
Source File: RenameTypeWizardSimilarElementsPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public int category(Object element) { /* * We'd like to present the elements in the same order as they * appear in the source. This can be achieved by assigning a * distinct category to every element; the category being derived * from the source position of the element. */ ISourceRange sourceRange= null; if (element instanceof IMember) { IMember member= (IMember) element; try { sourceRange= member.getNameRange(); } catch (JavaModelException e) { // fall through } } if (element instanceof ILocalVariable) { ILocalVariable var= (ILocalVariable) element; sourceRange= var.getNameRange(); } if (sourceRange != null) return 100 + sourceRange.getOffset(); // +100: safe distance from all other categories. return super.category(element); }
Example #28
Source File: JdtRenameRefactoringProcessorFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public JavaRenameProcessor createRenameProcessor(IJavaElement element) { try { switch (element.getElementType()) { case IJavaElement.TYPE: return new RenameTypeProcessor((IType) element); case IJavaElement.FIELD: if (((IField) element).getDeclaringType().isEnum()) return new RenameEnumConstProcessor((IField) element); else return new RenameFieldProcessor((IField) element); case IJavaElement.METHOD: if(((IMethod)element).isConstructor()) break; if (Flags.isStatic(((IMethod) element).getFlags()) || Flags.isPrivate(((IMethod) element).getFlags())) return new RenameNonVirtualMethodProcessor((IMethod) element); else return new RenameVirtualMethodProcessor((IMethod) element); case IJavaElement.TYPE_PARAMETER: return new RenameTypeParameterProcessor((ITypeParameter)element); case IJavaElement.LOCAL_VARIABLE: return new RenameLocalVariableProcessor((ILocalVariable)element); } } catch (JavaModelException exc) { LOG.error("Error creating refactoring processor for " + element.getElementName(), exc); } return null; }
Example #29
Source File: JavaElementImageProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private int computeJavaAdornmentFlags(IJavaElement element, int renderFlags) { int flags= 0; if (showOverlayIcons(renderFlags)) { try { if (element instanceof IMember) { IMember member= (IMember)element; int modifiers= member.getFlags(); if (confirmAbstract(member) && JdtFlags.isAbstract(member)) flags|= JavaElementImageDescriptor.ABSTRACT; if (Flags.isFinal(modifiers) || isInterfaceOrAnnotationField(member) || isEnumConstant(member, modifiers)) flags|= JavaElementImageDescriptor.FINAL; if (Flags.isStatic(modifiers) || isInterfaceOrAnnotationFieldOrType(member) || isEnumConstant(member, modifiers)) flags|= JavaElementImageDescriptor.STATIC; if (Flags.isDeprecated(modifiers)) flags|= JavaElementImageDescriptor.DEPRECATED; int elementType= element.getElementType(); if (elementType == IJavaElement.METHOD) { if (((IMethod)element).isConstructor()) flags|= JavaElementImageDescriptor.CONSTRUCTOR; if (Flags.isSynchronized(modifiers)) // collides with 'super' flag flags|= JavaElementImageDescriptor.SYNCHRONIZED; if (Flags.isNative(modifiers)) flags|= JavaElementImageDescriptor.NATIVE; if (Flags.isDefaultMethod(modifiers)) flags|= JavaElementImageDescriptor.DEFAULT_METHOD; if (Flags.isAnnnotationDefault(modifiers)) flags|= JavaElementImageDescriptor.ANNOTATION_DEFAULT; } if (member.getElementType() == IJavaElement.TYPE) { if (JavaModelUtil.hasMainMethod((IType)member)) { flags|= JavaElementImageDescriptor.RUNNABLE; } } if (member.getElementType() == IJavaElement.FIELD) { if (Flags.isVolatile(modifiers)) flags|= JavaElementImageDescriptor.VOLATILE; if (Flags.isTransient(modifiers)) flags|= JavaElementImageDescriptor.TRANSIENT; } } else if (element instanceof ILocalVariable && Flags.isFinal(((ILocalVariable)element).getFlags())) { flags|= JavaElementImageDescriptor.FINAL; } } catch (JavaModelException e) { // do nothing. Can't compute runnable adornment or get flags } } return flags; }
Example #30
Source File: FindDeclarationsInHierarchyAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override Class<?>[] getValidTypes() { return new Class[] { IField.class, IMethod.class, ILocalVariable.class, ITypeParameter.class }; }