org.eclipse.emf.common.util.SegmentSequence Java Examples
The following examples show how to use
org.eclipse.emf.common.util.SegmentSequence.
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: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override ParameterNameInitializer createParameterNameInitializer( IMethodBinding method, WorkingCopyOwner workingCopyOwner, JvmExecutable result, String handleIdentifier, String[] path, String name, SegmentSequence signaturex) { if (method.isConstructor() && method.getDeclaringClass().isEnum()) { String syntheticParams = "Ljava/lang/String;I"; String withoutSyntheticArgs = signaturex.toString(); // sometimes (don't really know when... JDT bug?) an enum constructor comes without synthetic arguments // this solution might wrongly strip off a (String,int) signature, but I don't see how this can be done differently here. if (withoutSyntheticArgs.startsWith(syntheticParams)) { withoutSyntheticArgs = withoutSyntheticArgs.substring(syntheticParams.length()); } return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, withoutSyntheticArgs); } return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); }
Example #2
Source File: EcoreUtil2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static String getFragmentPath(EObject object) { SegmentSequence.Builder builder = SegmentSequence.newBuilder("/"); InternalEObject internalEObject = (InternalEObject) object; boolean isContained = internalEObject.eDirectResource() != null; for (InternalEObject container = internalEObject.eInternalContainer(); container != null && !isContained; container = internalEObject.eInternalContainer()) { builder.append(getFragmentPathSegment(container, internalEObject.eContainingFeature(), internalEObject)); internalEObject = container; if (container.eDirectResource() != null) { isContained = true; } } if (!isContained) { return "/-1"; } builder.append(getFragmentPathRootSegment(internalEObject)); builder.append(""); builder.reverse(); return builder.toSegmentSequence().toString(); }
Example #3
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public URI getFullURI(IVariableBinding binding) { SegmentSequence.Builder builder = SegmentSequence.newBuilder(""); URI uri = getFullURI(binding.getDeclaringClass(), builder); builder.append("."); builder.append(binding.getName()); return uri.appendFragment(builder.toString()); }
Example #4
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public URI getFullURI(ITypeBinding typeBinding, String method) { SegmentSequence.Builder builder = SegmentSequence.newBuilder(""); URI uri = getFullURI(typeBinding, builder); URI[] uris = COMMON_METHOD_URIS.get(uri.lastSegment()); if (uris != null) { for (URI methodURI : uris) { String fragment = methodURI.fragment(); if (fragment.startsWith(method, fragment.length() - method.length() - 2)) { return methodURI; } } } builder.append(".").append(method).append("()"); return uri.appendFragment(builder.toString()); }
Example #5
Source File: TypeURIHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected SegmentSequence.Builder getQualifiedName(ITypeBinding binding, SegmentSequence.Builder builder) { if (binding.isParameterizedType()) { getQualifiedName(binding.getErasure(), builder); } else if (binding.isArray()) { getQualifiedName(binding.getComponentType(), builder).append("[]"); } else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) { builder.append(binding.getQualifiedName()); } else { getQualifiedName(binding.getDeclaringClass(), builder).append('$').append(binding.getName()); } return builder; }
Example #6
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override ParameterNameInitializer createParameterNameInitializer( IMethodBinding method, WorkingCopyOwner workingCopyOwner, JvmExecutable result, String handleIdentifier, String[] path, String name, SegmentSequence signaturex) { if (method.isConstructor()) { ITypeBinding declarator = method.getDeclaringClass(); if (declarator.isEnum()) { return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); } if (declarator.isMember()) { return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex) { @Override protected void setParameterNames(IMethod javaMethod, java.util.List<JvmFormalParameter> parameters) throws JavaModelException { String[] parameterNames = javaMethod.getParameterNames(); int size = parameters.size(); if (size == parameterNames.length) { super.setParameterNames(javaMethod, parameters); } else if (size == parameterNames.length - 1) { for (int i = 1; i < parameterNames.length; i++) { String string = parameterNames[i]; parameters.get(i - 1).setName(string); } } else { throw new IllegalStateException("unmatching arity for java method "+javaMethod.toString()+" and "+getExecutable().getIdentifier()); } } }; } } return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); }
Example #7
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
ParameterNameInitializer createParameterNameInitializer(IMethodBinding method, WorkingCopyOwner workingCopyOwner, JvmExecutable result, String handleIdentifier, String[] path, String name, SegmentSequence signaturex) { if (method.isConstructor() && method.getDeclaringClass().isEnum()) { return new EnumConstructorParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); } else { return new ParameterNameInitializer(workingCopyOwner, result, handleIdentifier, path, name, signaturex); } }
Example #8
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private SegmentSequence getSignatureAsSegmentSequence(IMethodBinding method) { String key = method.getKey(); int start = key.indexOf('('); int end = key.lastIndexOf(')'); SegmentSequence signaturex = SegmentSequence.create(";", key.substring(start + 1, end)); return signaturex; }
Example #9
Source File: N4JSResource.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * We don't use a {@link IFragmentProvider} here. The implementation is a complete copied from * {@link ResourceImpl#getURIFragment} * * @param eObject * the object the URI fragment should be calculated for. * @return the calculated URI fragment */ private String defaultGetURIFragment(EObject eObject) { // Copied from ResourceImpl.getURIFragment to avoid the caching // mechanism which will add a content // adapter which in turn will resolve / load the resource (while the // purpose of all the code is to // avoid resource loading) InternalEObject internalEObject = (InternalEObject) eObject; if (internalEObject.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(internalEObject)) { return "/" + getURIFragmentRootSegment(eObject); } else { SegmentSequence.Builder builder = SegmentSequence.newBuilder("/"); boolean isContained = false; for (InternalEObject container = internalEObject .eInternalContainer(); container != null; container = internalEObject .eInternalContainer()) { builder.append(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject)); internalEObject = container; if (container.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(container)) { isContained = true; break; } } if (!isContained) { return "/-1"; } builder.append(getURIFragmentRootSegment(internalEObject)); builder.append(""); builder.reverse(); // This comment also resides in ResourceImpl.getURIFragment: // Note that we convert it to a segment sequence because the // most common use case is that callers of this method will call // URI.appendFragment. // By creating the segment sequence here, we ensure that it's // found in the cache. // return builder.toSegmentSequence().toString(); } }
Example #10
Source File: JdtBasedTypeFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.4 */ protected void enhanceExecutable(StringBuilder fqn, String handleIdentifier, String[] path, JvmExecutable result, IMethodBinding method) { String name = method.getName(); fqn.append(name); fqn.append('('); ITypeBinding[] parameterTypes = method.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { if (i != 0) fqn.append(','); fqn.append(getQualifiedName(parameterTypes[i])); } fqn.append(')'); result.internalSetIdentifier(fqn.toString()); result.setSimpleName(name); setVisibility(result, method.getModifiers()); result.setDeprecated(method.isDeprecated()); if (parameterTypes.length > 0) { result.setVarArgs(method.isVarargs()); String[] parameterNames = null; // If the method is derived from source, we can efficiently determine the parameter names now. // ITypeBinding declaringClass = method.getDeclaringClass(); if (declaringClass.isFromSource()) { parameterNames = getParameterNamesFromSource(fqn, method); } else { // Use the key to determine the signature for the method. // SegmentSequence signaturex = getSignatureAsSegmentSequence(method); ParameterNameInitializer initializer = jdtCompliance.createParameterNameInitializer(method, workingCopyOwner, result, handleIdentifier, path, name, signaturex); ((JvmExecutableImplCustom)result).setParameterNameInitializer(initializer); } setParameterNamesAndAnnotations(method, parameterTypes, parameterNames, result); } ITypeBinding[] exceptionTypes = method.getExceptionTypes(); if (exceptionTypes.length > 0) { InternalEList<JvmTypeReference> exceptions = (InternalEList<JvmTypeReference>)result.getExceptions(); for (ITypeBinding exceptionType : exceptionTypes) { exceptions.addUnique(createTypeReference(exceptionType)); } } }