/// <summary>
        /// Reads the type, which can either be a method return/parameter type or a field type, and skips it.
        /// </summary>
        public TypeOf? ReadTypeOf(bool isMethodParameter)
        {
            while(ReadAnnotation().HasValue){} // skip type annotations

            if (isMethodParameter)SkipIfMatch("final^s"); // skip final keyword in method parameters
            else SkipGenerics(); // skip method return type generics

            // void
            if (SkipIfMatch("void^s"))return TypeOf.Void();

            // primitive
            Primitives? primitive = ReadPrimitive();

            if (primitive.HasValue){
                SkipTypeArrayAndGenerics();
                return TypeOf.Primitive(primitive.Value);
            }

            // object name
            string typeName = ReadFullTypeName();

            if (typeName.Length > 0){
                SkipTypeArrayAndGenerics();
                return TypeOf.Object(JavaParseUtils.FullToSimpleName(typeName));
            }

            // nothing
            return null;
        }
Esempio n. 2
0
 public string AsSimpleType()
 {
     if (IsTypeObject)
     {
         return(JavaParseUtils.FullToSimpleName((string)obj));
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        /// https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.7
        /// </summary>
        public Annotation? ReadAnnotation()
        {
            if (Char != '@')return null;

            Skip().SkipSpaces(); // skip @ and spaces

            string simpleName = JavaParseUtils.FullToSimpleName(ReadFullTypeName()); // read type name
            if (simpleName.Length == 0)return null;

            if (SkipSpaces().Char == '('){ // skip arguments and ignore
                SkipBlock('(', ')');
            }

            Annotation annotation = new Annotation(simpleName);
            if (AnnotationCallback != null)AnnotationCallback(annotation);

            return annotation;
        }
Esempio n. 4
0
        public JavaFileInfo Process(File file)
        {
            JavaFileInfo info = new JavaFileInfo();

            fileInfo.Add(file, info);

            JavaCodeParser parser = new JavaCodeParser(JavaParseUtils.PrepareCodeFile(file.Contents));

            parser.AnnotationCallback += IncrementAnnotation;
            parser.CodeBlockCallback  += blockParser => ReadCodeBlock(blockParser, GlobalInfo);

            ReadPackage(parser, info);
            ReadImportList(parser, info);
            ReadTopLevelTypes(parser, info);

            UpdateLocalData(info);

            return(info);
        }
 public void TestFullToSimpleName()
 {
     Assert.AreEqual("SimpleName", JavaParseUtils.FullToSimpleName("this.is.a.full.name.SimpleName"));
     Assert.AreEqual("SimpleName", JavaParseUtils.FullToSimpleName("SimpleName"));
     Assert.AreEqual(string.Empty, JavaParseUtils.FullToSimpleName("broken.name."));
 }
 /// <summary>
 /// Skips spaces and finds all following modifiers.
 /// </summary>
 public List<Modifiers> SkipReadModifierList()
 {
     return JavaParseUtils.ReadStructList(this, ReadModifier, 2);
 }
 /// <summary>
 /// Skips spaces and finds all following annotations.
 /// </summary>
 public List<Annotation> SkipReadAnnotationList()
 {
     return JavaParseUtils.ReadStructList(this, ReadAnnotation, 1);
 }
Esempio n. 8
0
 public override string PrepareFileContents(string contents)
 {
     return(JavaParseUtils.PrepareCodeFile(contents));
 }