protected void createFragmentForArray(String signature, StringBuilder uriBuilder) { String elementType = Signature.getElementType(signature); createFragment(elementType, uriBuilder); int dim = Signature.getArrayCount(signature); for (int i = 0; i < dim; i++) { uriBuilder.append("[]"); } }
/** * Returns the qualified signature corresponding to <code>signature</code>. * * @param signature the signature to qualify * @param context the type inside which an unqualified type will be resolved to find the * qualifier, or <code>null</code> if no context is available * @return the qualified signature */ public static String qualifySignature(final String signature, final IType context) { if (context == null) return signature; String qualifier = Signature.getSignatureQualifier(signature); if (qualifier.length() > 0) return signature; String elementType = Signature.getElementType(signature); String erasure = Signature.getTypeErasure(elementType); String simpleName = Signature.getSignatureSimpleName(erasure); String genericSimpleName = Signature.getSignatureSimpleName(elementType); int dim = Signature.getArrayCount(signature); try { String[][] strings = context.resolveType(simpleName); if (strings != null && strings.length > 0) qualifier = strings[0][0]; } catch (JavaModelException e) { // ignore - not found } if (qualifier.length() == 0) return signature; String qualifiedType = Signature.toQualifiedName(new String[] {qualifier, genericSimpleName}); String qualifiedSignature = Signature.createTypeSignature(qualifiedType, true); String newSignature = Signature.createArraySignature(qualifiedSignature, dim); return newSignature; }
public static String getReturnTypeString(IMethod method, boolean classTypesOnly) { try { String qualifiedReturnType = Signature.getReturnType(method.getSignature()); if (!classTypesOnly || qualifiedReturnType.startsWith("L") || qualifiedReturnType.startsWith("Q")) { return Signature.getSignatureSimpleName(qualifiedReturnType.replace('/', '.')); } } catch (IllegalArgumentException e) { } catch (JavaModelException e) { } return null; }
public void computeTypeName(String signature, StringBuilder uriBuilder) { int signatureKind = Signature.getTypeSignatureKind(signature); switch (signatureKind) { case Signature.CLASS_TYPE_SIGNATURE: case Signature.BASE_TYPE_SIGNATURE: case Signature.ARRAY_TYPE_SIGNATURE: case Signature.TYPE_VARIABLE_SIGNATURE: String erased = getTypeErasure(signature); uriBuilder.append(Signature.toString(erased)); return; default: throw new IllegalStateException("Unexpected Signature: " + signature); } }
protected void createResourceURIForClassImpl(String signature, StringBuilder uriBuilder) { String topLevel = signature; int idx = topLevel.indexOf('$'); if (idx != -1) { topLevel = topLevel.substring(0, idx) + ';'; if (topLevel.endsWith(".;") || topLevel.endsWith("$;")) { topLevel = signature.substring(1, signature.length() - 1); } else { topLevel = Signature.toString(topLevel); } } else { topLevel = Signature.toString(topLevel); } uriBuilder.append(URIHelperConstants.OBJECTS).append(topLevel); }
public static String[] getParameterTypesString(IMethod method) { try { String[] parameterQualifiedTypes = Signature.getParameterTypes(method.getSignature()); int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length; String[] parameterPackages = new String[length]; for (int i = 0; i < length; i++) { parameterQualifiedTypes[i] = parameterQualifiedTypes[i].replace('/', '.'); parameterPackages[i] = Signature.getSignatureSimpleName(parameterQualifiedTypes[i]); } return parameterPackages; } catch (IllegalArgumentException e) { } catch (JavaModelException e) { } return null; }
/** * Returns the lower bound of a type signature. Returns the null type signature if <code>signature * </code> is a wildcard or upper bound (<code>? extends T</code>); returns the signature of the * type <code>T</code> of a lower bound (<code>? super T</code>) or <code>signature</code> itself * if it is not a bound signature. * * @param signature the signature * @return the lower bound signature of <code>signature</code> */ public static char[] getLowerBound(char[] signature) { if (signature.length < 1) return signature; if (signature.length == 1 && signature[0] == Signature.C_STAR) return signature; int superIndex = indexOf(signature, Signature.C_EXTENDS); if (superIndex == 0) return NULL_TYPE_SIGNATURE_ARRAY; if (superIndex != -1) { char afterSuper = signature[superIndex + 1]; if (afterSuper == Signature.C_STAR || afterSuper == Signature.C_EXTENDS) // impossible captured type return NULL_TYPE_SIGNATURE_ARRAY; } char[][] typeArguments = Signature.getTypeArguments(signature); for (int i = 0; i < typeArguments.length; i++) if (Arrays.equals(typeArguments[i], NULL_TYPE_SIGNATURE_ARRAY)) return NULL_TYPE_SIGNATURE_ARRAY; if (signature[0] == Signature.C_SUPER) { char[] type = new char[signature.length - 1]; System.arraycopy(signature, 1, type, 0, signature.length - 1); return type; } return signature; }
public void computeParameter(String signature, StringBuilder uriBuilder) { int signatureKind = Signature.getTypeSignatureKind(signature); if (signatureKind == Signature.WILDCARD_TYPE_SIGNATURE) { switch (signature.charAt(0)) { case '*': { uriBuilder.append("? extends java.lang.Object"); } break; case '+': { uriBuilder.append("? extends "); String upperBoundSignature = signature.substring(1); computeParameterizedTypeName(upperBoundSignature, uriBuilder); } break; case '-': { uriBuilder.append("? extends java.lang.Object & super "); String lowerBoundSignature = signature.substring(1); computeParameterizedTypeName(lowerBoundSignature, uriBuilder); } break; default: throw new IllegalArgumentException("Signature: " + signature); } } else { computeParameterizedTypeName(signature, uriBuilder); } }
private JavaElement getJavaElement(LocalVariableBinding binding) { LocalDeclaration local = binding.declaration; JavaElement parent = null; ReferenceContext referenceContext = binding.declaringScope.isLambdaSubscope() ? binding.declaringScope.namedMethodScope().referenceContext() : binding.declaringScope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext; parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding); } else if (referenceContext instanceof TypeDeclaration) { // Local variable is declared inside an initializer TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding); parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type); } if (parent == null) return null; return new LocalVariable( parent, new String(local.name), local.declarationSourceStart, local.declarationSourceEnd, local.sourceStart, local.sourceEnd, local.type == null ? Signature.createTypeSignature(binding.type.signableName(), true) : Util.typeSignature(local.type), binding.declaration.annotations, local.modifiers, local.getKind() == AbstractVariableDeclaration.PARAMETER); }
private String extractSignature(String sig) { String args = Signature.toString(sig); args = args.substring(args.indexOf("(") + 1, args.indexOf(")")); args = args.replaceAll("\\s+", ""); args = args.replaceAll("/", "."); return args; }
public static String getMethodSignature( final MethodLocation location, final boolean withReturnType) { String methodSignature = location.getLocationMethodSignature().replace('/', '.'); if (methodSignature.length() == 0) return methodSignature; final int signatureStartIndex = methodSignature.indexOf('('); if (signatureStartIndex < 0) { return methodSignature; } String methodName = methodSignature.substring(0, signatureStartIndex); methodName = methodName.substring(methodName.lastIndexOf('.') + 1); if (methodName.equals("<clinit>")) { // $NON-NLS-1$ return CLINIT_MSG; } boolean includeReturnType = withReturnType; if (methodName.equals("<init>")) { // $NON-NLS-1$ final String className = getClassName(location); methodName = className.substring(className.lastIndexOf('.') + 1); includeReturnType = false; } methodSignature = methodSignature.substring(signatureStartIndex); return Signature.toString( methodSignature, methodName, null /* parameterNames */, true /* fullyQualifiedName */, includeReturnType); }
/** * Tries to find the given {@link IApiMethod} in the given {@link IType}. If a matching method is * not found <code>null</code> is returned * * @param type the type top look in for the given {@link IApiMethod} * @param method the {@link IApiMethod} to look for * @return the {@link IMethod} from the given {@link IType} that matches the given {@link * IApiMethod} or <code>null</code> if no matching method is found * @throws JavaModelException * @throws CoreException */ protected IMethod findMethodInType(IType type, IApiMethod method) throws JavaModelException, CoreException { String[] parameterTypes = Signature.getParameterTypes(method.getSignature()); for (int i = 0; i < parameterTypes.length; i++) { parameterTypes[i] = parameterTypes[i].replace('/', '.'); } String methodname = method.getName(); if (method.isConstructor()) { IApiType enclosingType = method.getEnclosingType(); if (enclosingType.isMemberType() && !Flags.isStatic(enclosingType.getModifiers())) { // remove the synthetic argument that corresponds to the enclosing type int length = parameterTypes.length - 1; System.arraycopy(parameterTypes, 1, (parameterTypes = new String[length]), 0, length); } methodname = enclosingType.getSimpleName(); } IMethod Qmethod = type.getMethod(methodname, parameterTypes); IMethod[] methods = type.getMethods(); IMethod match = null; for (int i = 0; i < methods.length; i++) { IMethod m = methods[i]; if (m.isSimilar(Qmethod)) { match = m; break; } } return match; }
/** * Gets the fully qualified name of the supplied java element. * * <p>NOTE: For easy of determining fields and method segments, they are appended with a javadoc * style '#' instead of the normal '.'. * * @param element The IJavaElement. * @return The fully qualified name. */ public static String getFullyQualifiedName(IJavaElement element) { IJavaElement parent = element; while (parent.getElementType() != IJavaElement.COMPILATION_UNIT && parent.getElementType() != IJavaElement.CLASS_FILE) { parent = parent.getParent(); } StringBuffer elementName = new StringBuffer() .append(parent.getParent().getElementName()) .append('.') .append(FileUtils.getFileName(parent.getElementName())); switch (element.getElementType()) { case IJavaElement.FIELD: IField field = (IField) element; elementName.append('#').append(field.getElementName()); break; case IJavaElement.METHOD: IMethod method = (IMethod) element; elementName.append('#').append(method.getElementName()).append('('); String[] parameters = method.getParameterTypes(); for (int ii = 0; ii < parameters.length; ii++) { if (ii != 0) { elementName.append(", "); } elementName.append(Signature.toString(parameters[ii]).replace('/', '.')); } elementName.append(')'); break; } return elementName.toString(); }
private static String[] getParameterTypesAsStringArray(IMethod method) { Set<String> typeParameterNames = new HashSet<String>(); try { for (ITypeParameter param : method.getDeclaringType().getTypeParameters()) { typeParameterNames.add(param.getElementName()); } for (ITypeParameter param : method.getTypeParameters()) { typeParameterNames.add(param.getElementName()); } } catch (JavaModelException e) { } String[] parameterTypesAsString = new String[method.getParameterTypes().length]; for (int i = 0; i < method.getParameterTypes().length; i++) { String parameterTypeString = Signature.getElementType(method.getParameterTypes()[i]); boolean isArray = !parameterTypeString.equals(method.getParameterTypes()[i]); String parameterType = resolveClassNameBySignature(parameterTypeString, method.getDeclaringType()); if (typeParameterNames.contains(parameterType)) { parameterTypesAsString[i] = Object.class.getName() + (isArray ? ClassUtils.ARRAY_SUFFIX : ""); } else { parameterTypesAsString[i] = parameterType + (isArray ? ClassUtils.ARRAY_SUFFIX : ""); } } return parameterTypesAsString; }
public void switchToJavaEditor(IType type, String methodName, List<String> parameterTypes) { JavaEditor javaEditor = openJavaEditor(type); if (javaEditor == null) { return; } IMethod newMethod = null; try { String[] parameterTypeSignatures = new String[parameterTypes.size()]; for (int i = 0; i < parameterTypeSignatures.length; i++) { String qualifiedName = parameterTypes.get(i); String signature = Signature.createTypeSignature(qualifiedName, true); parameterTypeSignatures[i] = signature; } newMethod = JavaModelUtil.findMethod(methodName, parameterTypeSignatures, false, type); } catch (JavaModelException e) { // ignore this } if (newMethod == null) { return; } javaEditor.setSelection(newMethod); }
/* * (non-Javadoc) * @see org.eclipse.pde.api.tools.internal.builder.AbstractProblemDetector# * getMessageArgs * (org.eclipse.pde.api.tools.internal.provisional.builder.IReference) */ @Override protected String[] getMessageArgs(IReference reference) throws CoreException { IApiMember member = reference.getMember(); String eeValue = ProfileModifiers.getName(this.referenceEEs.get(reference).intValue()); String simpleTypeName = Signatures.getSimpleTypeName(reference.getReferencedTypeName()); if (simpleTypeName.indexOf('$') != -1) { simpleTypeName = simpleTypeName.replace('$', '.'); } switch (reference.getReferenceType()) { case IReference.T_TYPE_REFERENCE: { return new String[] { getDisplay(member, false), simpleTypeName, eeValue, }; } case IReference.T_FIELD_REFERENCE: { return new String[] { getDisplay(member, false), simpleTypeName, reference.getReferencedMemberName(), eeValue, }; } case IReference.T_METHOD_REFERENCE: { String referenceMemberName = reference.getReferencedMemberName(); if (Util.isConstructor(referenceMemberName)) { return new String[] { getDisplay(member, false), Signature.toString( reference.getReferencedSignature(), simpleTypeName, null, false, false), eeValue, }; } else { return new String[] { getDisplay(member, false), simpleTypeName, Signature.toString( reference.getReferencedSignature(), referenceMemberName, null, false, false), eeValue, }; } } default: break; } return null; }
protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo) { buffer.append(tabString(tab)); if (info != NO_INFO) { buffer.append(Signature.toString(getTypeSignature())); buffer.append(" "); // $NON-NLS-1$ } toStringName(buffer); }
private boolean checkParameters( char[] methodDescriptor, char[][] parameterSimpleNames, char[][] parameterQualifications, boolean isCaseSensitive, boolean isCamelCase) { char[][] arguments = Signature.getParameterTypes(methodDescriptor); int parameterCount = parameterSimpleNames.length; if (parameterCount != arguments.length) return false; for (int i = 0; i < parameterCount; i++) if (!checkTypeName( parameterSimpleNames[i], parameterQualifications[i], Signature.toCharArray(arguments[i]), isCaseSensitive, isCamelCase)) return false; return true; }
public Object convertToObject(String parameterValue) throws ParameterValueConversionException { assertWellFormed(parameterValue != null); final int projectEndPosition = parameterValue.indexOf(PROJECT_END_CHAR); assertWellFormed(projectEndPosition != -1); String projectName = parameterValue.substring(0, projectEndPosition); String javaElementRef = parameterValue.substring(projectEndPosition + 1); IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); assertExists(javaModel); IJavaProject javaProject = javaModel.getJavaProject(projectName); assertExists(javaProject); final int typeEndPosition = javaElementRef.indexOf(TYPE_END_CHAR); String typeName; if (typeEndPosition == -1) { typeName = javaElementRef; } else { typeName = javaElementRef.substring(0, typeEndPosition); } IType type = null; try { type = javaProject.findType(typeName); } catch (JavaModelException ex) { // type == null } assertExists(type); if (typeEndPosition == -1) { return type; } String memberRef = javaElementRef.substring(typeEndPosition + 1); final int paramStartPosition = memberRef.indexOf(PARAM_START_CHAR); if (paramStartPosition == -1) { IField field = type.getField(memberRef); assertExists(field); return field; } String methodName = memberRef.substring(0, paramStartPosition); String signature = memberRef.substring(paramStartPosition); String[] parameterTypes = null; try { parameterTypes = Signature.getParameterTypes(signature); } catch (IllegalArgumentException ex) { // parameterTypes == null } assertWellFormed(parameterTypes != null); IMethod method = type.getMethod(methodName, parameterTypes); assertExists(method); return method; }
private void addImports(final ICompilationUnit unit, ClipboardData data) throws CoreException { final ImportRewrite rewrite = StubUtility.createImportRewrite(unit, true); String[] imports = data.getTypeImports(); for (int i = 0; i < imports.length; i++) { rewrite.addImport(imports[i]); } String[] staticImports = data.getStaticImports(); for (int i = 0; i < staticImports.length; i++) { String name = Signature.getSimpleName(staticImports[i]); boolean isField = !name.endsWith("()"); // $NON-NLS-1$ if (!isField) { name = name.substring(0, name.length() - 2); } String qualifier = Signature.getQualifier(staticImports[i]); rewrite.addStaticImport(qualifier, name, isField); } try { getProgressService() .busyCursorWhile( new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { JavaModelUtil.applyEdit(unit, rewrite.rewriteImports(monitor), false, null); } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof CoreException) throw (CoreException) cause; throw new CoreException( new Status( IStatus.ERROR, JavaUI.ID_PLUGIN, IJavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.JavaPlugin_internal_error, cause)); } catch (InterruptedException e) { // Canceled by the user } }
public static String getType(final IField field) { try { return Signature.toString(field.getTypeSignature()); } catch (final IllegalArgumentException e) { e.printStackTrace(); } catch (final JavaModelException e) { e.printStackTrace(); } return null; }
/** * Takes a method signature <code> * [< typeVariableName : formalTypeDecl >] ( paramTypeSig1* ) retTypeSig</code> and returns * it with any parameter signatures filtered through <code>getLowerBound</code> and the return * type filtered through <code>getUpperBound</code>. Any preceding formal type variable * declarations are removed. * * <p>TODO this is a temporary workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=83600 * * @param signature the method signature to convert * @return the signature with no bounded types */ public static char[] unboundedSignature(char[] signature) { if (signature == null || signature.length < 2) return signature; final boolean BUG_83600 = true; // XXX the signatures from CompletionRequestor contain a superfluous '+' // before type parameters to parameter types if (BUG_83600) { signature = fix83600(signature); } StringBuffer res = new StringBuffer("("); // $NON-NLS-1$ char[][] parameters = Signature.getParameterTypes(signature); for (int i = 0; i < parameters.length; i++) { char[] param = parameters[i]; res.append(getLowerBound(param)); } res.append(')'); res.append(getUpperBound(Signature.getReturnType(signature))); return res.toString().toCharArray(); }
/* * @see org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal#computeContextInformation() * @since 3.3 */ @Override protected IContextInformation computeContextInformation() { char[] signature = fProposal.getSignature(); char[][] typeParameters = Signature.getTypeArguments(signature); if (typeParameters.length == 0) return super.computeContextInformation(); ProposalContextInformation contextInformation = new ProposalContextInformation(fProposal); if (fContextInformationPosition != 0 && fProposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; }
private static void appendMethodReference(IMethod meth, StringBuffer buf) throws JavaModelException { buf.append(meth.getElementName()); /* * The Javadoc tool for Java SE 8 changed the anchor syntax and now tries to avoid "strange" characters in URLs. * This breaks all clients that directly create such URLs. * We can't know what format is required, so we just guess by the project's compiler compliance. */ boolean is18OrHigher = JavaModelUtil.is18OrHigher(meth.getJavaProject()); buf.append(is18OrHigher ? '-' : '('); String[] params = meth.getParameterTypes(); IType declaringType = meth.getDeclaringType(); boolean isVararg = Flags.isVarargs(meth.getFlags()); int lastParam = params.length - 1; for (int i = 0; i <= lastParam; i++) { if (i != 0) { buf.append(is18OrHigher ? "-" : ", "); // $NON-NLS-1$ //$NON-NLS-2$ } String curr = Signature.getTypeErasure(params[i]); String fullName = JavaModelUtil.getResolvedTypeName(curr, declaringType); if (fullName == null) { // e.g. a type parameter "QE;" fullName = Signature.toString(Signature.getElementType(curr)); } if (fullName != null) { buf.append(fullName); int dim = Signature.getArrayCount(curr); if (i == lastParam && isVararg) { dim--; } while (dim > 0) { buf.append(is18OrHigher ? ":A" : "[]"); // $NON-NLS-1$ //$NON-NLS-2$ dim--; } if (i == lastParam && isVararg) { buf.append("..."); // $NON-NLS-1$ } } } buf.append(is18OrHigher ? '-' : ')'); }
public void computeParameterizedTypeName(String signature, StringBuilder uriBuilder) { computeTypeName(signature, uriBuilder); String[] typeArguments = Signature.getTypeArguments(signature); if (typeArguments.length != 0) { uriBuilder.append('<'); for (int i = 0; i < typeArguments.length; i++) { if (i != 0) uriBuilder.append(','); computeParameter(typeArguments[i], uriBuilder); } uriBuilder.append('>'); } }
boolean matchMethod(MethodPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!pattern.findDeclarations) return false; // only relevant when finding declarations if (!(binaryInfo instanceof IBinaryMethod)) return false; IBinaryMethod method = (IBinaryMethod) binaryInfo; if (!pattern.matchesName(pattern.selector, method.getSelector())) return false; if (!checkDeclaringType( enclosingBinaryType, pattern.declaringSimpleName, pattern.declaringQualification, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; // look at return type only if declaring type is not specified boolean checkReturnType = pattern.declaringSimpleName == null && (pattern.returnSimpleName != null || pattern.returnQualification != null); boolean checkParameters = pattern.parameterSimpleNames != null; if (checkReturnType || checkParameters) { char[] methodDescriptor = convertClassFileFormat(method.getMethodDescriptor()); if (checkReturnType) { char[] returnTypeSignature = Signature.toCharArray(Signature.getReturnType(methodDescriptor)); if (!checkTypeName( pattern.returnSimpleName, pattern.returnQualification, returnTypeSignature, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } if (checkParameters && !checkParameters( methodDescriptor, pattern.parameterSimpleNames, pattern.parameterQualifications, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } return true; }
/** * Create a {@link BeansJavaCompletionProposal} for the given {@link IMethod} and report it on the * {@link ContentAssistRequest}. */ protected void createMethodProposal(IContentAssistProposalRecorder recorder, IMethod method) { try { String[] parameterNames = method.getParameterNames(); String[] parameterTypes = JdtUtils.getParameterTypesString(method); String returnType = JdtUtils.getReturnTypeString(method, true); String methodName = JdtUtils.getMethodName(method); String replaceText = methodName; StringBuilder buf = new StringBuilder(); // add method name buf.append(replaceText); // add method parameters if (parameterTypes.length > 0 && parameterNames.length > 0) { buf.append(" ("); for (int i = 0; i < parameterTypes.length; i++) { buf.append(parameterTypes[i]); buf.append(' '); buf.append(parameterNames[i]); if (i < (parameterTypes.length - 1)) { buf.append(", "); } } buf.append(") "); } else { buf.append("() "); } // add return type if (returnType != null) { buf.append(Signature.getSimpleName(returnType)); buf.append(" - "); } else { buf.append(" void - "); } // add class name buf.append(JdtUtils.getParentName(method)); String displayText = buf.toString(); Image image = Activator.getDefault() .getJavaElementLabelProvider() .getImageLabel(method, method.getFlags() | JavaElementImageProvider.SMALL_ICONS); recorder.recordProposal(image, METHOD_RELEVANCE, displayText, replaceText, method); } catch (JavaModelException e) { // do nothing } }
private ISymbol internalCreateFromBaseType( String symbolName, ValueType valueType, IJavaProject javaProject) { // based on JSF 1.1 spec section 4.2.1.4 the data model // value binding can be one of a number of object that will // get an implicit DataModel wrapper at runtime // could be an array if (Signature.getArrayCount(valueType.getSignature()) > 0) { return getSymbolFactory() .createArraySymbol( symbolName, valueType.getSignature(), ERuntimeSource.TAG_INSTANTIATED_SYMBOL_LITERAL, javaProject); } // if is a list, then we have extra work to do if it // is generic and has info about its contents if (valueType.isInstanceOf(TypeConstants.TYPE_LIST)) { return getSymbolFactory() .createFromList( symbolName, valueType, ERuntimeSource.TAG_INSTANTIATED_SYMBOL_LITERAL, null, javaProject); } // if is JSTL ResultSet, java ResultSet or DataModel // return the default symbol -- in the absence of definite // template info, these row containers are opaque to us else if (valueType.isInstanceOf(TypeConstants.TYPE_JAVAX_SERVLET_JSP_JSTL_SQL_RESULT) || valueType.isInstanceOf(TypeConstants.TYPE_RESULT_SET) || valueType.isInstanceOf(TypeConstants.TYPE_DATA_MODEL)) { return getSymbolFactory() .createDefaultSymbol( symbolName, ERuntimeSource.TAG_INSTANTIATED_SYMBOL_LITERAL, Messages.getString( "AbstractDataModelVariableFactory.DataModel.Symbol.RowVariable.DetailedDescription")); //$NON-NLS-1$ } // in other cases, we assume that the value is an explicit single row // scalar object return getSymbolFactory() .createScalarSymbol( symbolName, valueType.getSignature(), ERuntimeSource.TAG_INSTANTIATED_SYMBOL_LITERAL, javaProject); }
/** * Builds a string of the constructor parameters. * * @param type The type containing the fields. * @param fields The array of fields. * @return The parameters string. */ protected String buildParams(IType type, String[] fields) throws Exception { StringBuffer params = new StringBuffer(); for (int ii = 0; ii < fields.length; ii++) { if (ii != 0) { params.append(", "); } IField field = type.getField(fields[ii]); params .append(Signature.getSignatureSimpleName(field.getTypeSignature())) .append(' ') .append(field.getElementName()); } return params.toString(); }
/** * Determines is the java element contains a specific method. * * <p>The syntax for the property tester is of the form: methodname, signature, modifiers. * * <ol> * <li>methodname - case sensitive method name, required. For example, <code>toString</code>. * <li>signature - JLS style method signature, required. For example, <code>(QString;)V</code>. * <li>modifiers - optional space separated list of modifiers, for example, <code>public static * </code>. * </ol> * * @param element the element to check for the method * @param args first arg is method name, secondary args are parameter types signatures * @return true if the method is found in the element, false otherwise */ private boolean hasMethod(IJavaElement element, Object[] args) { try { if (args.length > 1) { IType type = getType(element); if (type != null && type.exists()) { String name = (String) args[0]; String signature = (String) args[1]; String[] parms = Signature.getParameterTypes(signature); String returnType = Signature.getReturnType(signature); IMethod candidate = type.getMethod(name, parms); if (candidate.exists()) { // check return type if (candidate.getReturnType().equals(returnType)) { // check modifiers if (args.length > 2) { String modifierText = (String) args[2]; String[] modifiers = modifierText.split(" "); // $NON-NLS-1$ int flags = 0; for (int j = 0; j < modifiers.length; j++) { String modifier = modifiers[j]; Integer flag = (Integer) fgModifiers.get(modifier); if (flag != null) { flags = flags | flag.intValue(); } } if (candidate.getFlags() == flags) { return true; } } } } } } } catch (JavaModelException e) { } return false; }