Java Code Examples for org.eclipse.jdt.core.dom.ITypeBinding#getKey()
The following examples show how to use
org.eclipse.jdt.core.dom.ITypeBinding#getKey() .
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 j2cl with Apache License 2.0 | 6 votes |
/** * Returns the binary name for a type binding. * * <p>NOTE: This accounts for the cases that JDT does not assign binary names, which are those of * unreachable local or anonymous classes. */ private static String getBinaryNameFromTypeBinding(ITypeBinding typeBinding) { String binaryName = typeBinding.getBinaryName(); if (binaryName == null && (typeBinding.isLocal() || typeBinding.isAnonymous())) { // Local and anonymous classes in unreachable code have null binary name. // The code here is a HACK that relies on the way that JDT synthesizes keys. Keys for // unreachable classes have the closest enclosing reachable class key as a prefix (minus the // ending semicolon) ITypeBinding closestReachableExclosingClass = typeBinding.getDeclaringClass(); while (closestReachableExclosingClass.getBinaryName() == null) { closestReachableExclosingClass = closestReachableExclosingClass.getDeclaringClass(); } String parentKey = closestReachableExclosingClass.getKey(); String key = typeBinding.getKey(); return getBinaryNameFromTypeBinding(typeBinding.getDeclaringClass()) + "$$Unreachable" // remove the parent prefix and the ending semicolon + key.substring(parentKey.length() - 1, key.length() - 1); } return binaryName; }
Example 2
Source File: InlineConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean areInSameType(ASTNode one, ASTNode other) { ASTNode onesContainer= getContainingTypeDeclaration(one); ASTNode othersContainer= getContainingTypeDeclaration(other); if (onesContainer == null || othersContainer == null) return false; ITypeBinding onesContainerBinding= getTypeBindingForTypeDeclaration(onesContainer); ITypeBinding othersContainerBinding= getTypeBindingForTypeDeclaration(othersContainer); Assert.isNotNull(onesContainerBinding); Assert.isNotNull(othersContainerBinding); String onesKey= onesContainerBinding.getKey(); String othersKey= othersContainerBinding.getKey(); if (onesKey == null || othersKey == null) return false; return onesKey.equals(othersKey); }
Example 3
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static void checkMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding returnType, ITypeBinding[] parameters, RefactoringStatus result, boolean reUseMethod) { IMethodBinding method = Bindings.findMethodInHierarchy(type, methodName, parameters); if (method != null) { boolean returnTypeClash = false; ITypeBinding methodReturnType = method.getReturnType(); if (returnType != null && methodReturnType != null) { String returnTypeKey = returnType.getKey(); String methodReturnTypeKey = methodReturnType.getKey(); if (returnTypeKey == null && methodReturnTypeKey == null) { returnTypeClash = returnType != methodReturnType; } else if (returnTypeKey != null && methodReturnTypeKey != null) { returnTypeClash = !returnTypeKey.equals(methodReturnTypeKey); } } ITypeBinding dc = method.getDeclaringClass(); if (returnTypeClash) { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_returnTypeClash, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName()) }), JavaStatusContext.create(method)); } else { if (!reUseMethod) { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}), JavaStatusContext.create(method)); } } } else { if (reUseMethod) { result.addError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nosuchmethod_status_fatalError, BasicElementLabels.getJavaElementName(methodName)), JavaStatusContext.create(method)); } } }
Example 4
Source File: SuperTypeConstraintsModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a new TType for the corresponding binding. * * @param binding The type binding * @return The corresponding TType */ public final TType createTType(final ITypeBinding binding) { final String key= binding.getKey(); final TType cached= fTTypeCache.get(key); if (cached != null) return cached; final TType type= fEnvironment.create(binding); fTTypeCache.put(key, type); return type; }
Example 5
Source File: InferTypeArgumentsTCModel.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public TType createTType(ITypeBinding typeBinding) { String key= typeBinding.getKey(); TType cached= fTTypeCache.get(key); if (cached != null) return cached; TType type= fTypeEnvironment.create(typeBinding); fTTypeCache.put(key, type); return type; }
Example 6
Source File: CollectionElementVariable2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param parentCv the parent constraint variable * @param typeVariable the type variable for this constraint * @param declarationTypeVariableIndex */ public CollectionElementVariable2(ConstraintVariable2 parentCv, ITypeBinding typeVariable, int declarationTypeVariableIndex) { super(null); fParentCv= parentCv; if (! typeVariable.isTypeVariable()) throw new IllegalArgumentException(typeVariable.toString()); fTypeVariableKey= typeVariable.getKey(); fDeclarationTypeVariableIndex= declarationTypeVariableIndex; }
Example 7
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the new method somehow conflicts with an already existing method in * the hierarchy. The following checks are done: * <ul> * <li> if the new method overrides a method defined in the given type or in one of its * super classes. </li> * </ul> * @param type * @param methodName * @param returnType * @param parameters * @return the status */ public static RefactoringStatus checkMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding returnType, ITypeBinding[] parameters) { RefactoringStatus result= new RefactoringStatus(); IMethodBinding method= Bindings.findMethodInHierarchy(type, methodName, parameters); if (method != null) { boolean returnTypeClash= false; ITypeBinding methodReturnType= method.getReturnType(); if (returnType != null && methodReturnType != null) { String returnTypeKey= returnType.getKey(); String methodReturnTypeKey= methodReturnType.getKey(); if (returnTypeKey == null && methodReturnTypeKey == null) { returnTypeClash= returnType != methodReturnType; } else if (returnTypeKey != null && methodReturnTypeKey != null) { returnTypeClash= !returnTypeKey.equals(methodReturnTypeKey); } } ITypeBinding dc= method.getDeclaringClass(); if (returnTypeClash) { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_returnTypeClash, new Object[] {BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}), JavaStatusContext.create(method)); } else { if (method.isConstructor()) { result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor, new Object[] { BasicElementLabels.getJavaElementName(dc.getName()) })); } else { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName()) }), JavaStatusContext.create(method)); } } } return result; }
Example 8
Source File: ConstraintVariableFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public DeclaringTypeVariable makeDeclaringTypeVariable(ITypeBinding memberTypeBinding) { String key = memberTypeBinding.getKey(); if (! fDeclaringTypeVariableMap.containsKey(key)){ fDeclaringTypeVariableMap.put(key, new DeclaringTypeVariable(memberTypeBinding)); if (REPORT) nrCreated++; } else { if (REPORT) nrRetrieved++; } if (REPORT) dumpConstraintStats(); return fDeclaringTypeVariableMap.get(key); }
Example 9
Source File: ConstraintVariableFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RawBindingVariable makeRawBindingVariable(ITypeBinding binding) { String key = binding.getKey(); if (! fRawBindingMap.containsKey(key)){ fRawBindingMap.put(key, new RawBindingVariable(binding)); if (REPORT) nrCreated++; } else { if (REPORT) nrRetrieved++; } if (REPORT) dumpConstraintStats(); return fRawBindingMap.get(key); }
Example 10
Source File: TType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Initialized the type from the given binding * * @param binding the binding to initialize from */ protected void initialize(ITypeBinding binding) { fBindingKey= binding.getKey(); Assert.isNotNull(fBindingKey); fModifiers= binding.getModifiers(); if (binding.isClass()) { fFlags= F_IS_CLASS; // the annotation test has to be done before test for interface // since annotations are interfaces as well. } else if (binding.isAnnotation()) { fFlags= F_IS_ANNOTATION | F_IS_INTERFACE; } else if (binding.isInterface()) { fFlags= F_IS_INTERFACE; } else if (binding.isEnum()) { fFlags= F_IS_ENUM; } if (binding.isTopLevel()) { fFlags|= F_IS_TOP_LEVEL; } else if (binding.isNested()) { fFlags|= F_IS_NESTED; if (binding.isMember()) { fFlags|= F_IS_MEMBER; } else if (binding.isLocal()) { fFlags|= F_IS_LOCAL; } else if (binding.isAnonymous()) { fFlags|= F_IS_ANONYMOUS; } } }
Example 11
Source File: TypeEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ParameterizedType createParameterizedType(ITypeBinding binding) { IJavaProject javaProject= binding.getJavaElement().getJavaProject(); String bindingKey= binding.getKey(); ProjectKeyPair pair= new ProjectKeyPair(javaProject, bindingKey); ParameterizedType result= fParameterizedTypes.get(pair); if (result != null) return result; result= new ParameterizedType(this); fParameterizedTypes.put(pair, result); result.initialize(binding, (IType)binding.getJavaElement()); cacheSubType(result.getSuperclass(), result); cacheSubTypes(result.getInterfaces(), result); return result; }
Example 12
Source File: TypeEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private CaptureType createCaptureType(ITypeBinding binding) { IJavaProject javaProject= binding.getDeclaringClass().getJavaElement().getJavaProject(); String bindingKey= binding.getKey(); ProjectKeyPair pair= new ProjectKeyPair(javaProject, bindingKey); CaptureType result= fCaptureTypes.get(pair); if (result != null) return result; result= new CaptureType(this); fCaptureTypes.put(pair, result); result.initialize(binding, javaProject); return result; }
Example 13
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void checkMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding returnType, ITypeBinding[] parameters, RefactoringStatus result, boolean reUseMethod) { IMethodBinding method= Bindings.findMethodInHierarchy(type, methodName, parameters); if (method != null) { boolean returnTypeClash= false; ITypeBinding methodReturnType= method.getReturnType(); if (returnType != null && methodReturnType != null) { String returnTypeKey= returnType.getKey(); String methodReturnTypeKey= methodReturnType.getKey(); if (returnTypeKey == null && methodReturnTypeKey == null) { returnTypeClash= returnType != methodReturnType; } else if (returnTypeKey != null && methodReturnTypeKey != null) { returnTypeClash= !returnTypeKey.equals(methodReturnTypeKey); } } ITypeBinding dc= method.getDeclaringClass(); if (returnTypeClash) { result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_returnTypeClash, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}), JavaStatusContext.create(method)); } else { if (!reUseMethod) result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName())}), JavaStatusContext.create(method)); } } else { if (reUseMethod){ result.addError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nosuchmethod_status_fatalError, BasicElementLabels.getJavaElementName(methodName)), JavaStatusContext.create(method)); } } }