Code Monkey home page Code Monkey logo

Comments (7)

AlexHaxe avatar AlexHaxe commented on August 18, 2024

second hint (because check detection logic might be a bit complex): check detection calls check.configureProperty which uses Reflect.setField on checks under detection to run them with different settings.
The same configureProperty is used after reading a checkstyle configuration file during a "normal" checkstyle run.

from genjvm.

Simn avatar Simn commented on August 18, 2024

I just checked and this is still a problem.

from genjvm.

Simn avatar Simn commented on August 18, 2024

I've changed one of the tests like so:

	@Test
	public function testDetectSeparatorWrap() {
		var check = new SeparatorWrapCheck();
		var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([check], [buildCheckFile(SAMPLE_CODING_STYLE)]);
		Assert.areEqual(1, detectedChecks.length);
		Assert.areEqual("SeparatorWrap", detectedChecks[0].type);
		var props = cast detectedChecks[0].props;
		Sys.println(props); // {}
		Sys.println(check.option); // eol
		Sys.println(props.option); // null
		Assert.areEqual(WrapCheckBaseOption.EOL, props.option);
	}

So the expected value is on the original instance of SeperatorWrapCheck, but the props object is empty.

I've noticed that ConfigUtils.makeCheckConfig uses Reflect.fields(check), which is not guaranteed to work for classes:

  This method is only guaranteed to work on anonymous structures. Refer to
  `Type.getInstanceFields` for a function supporting class instances.

from genjvm.

Simn avatar Simn commented on August 18, 2024

Yes the tests pass after changing that to for (prop in Type.getInstanceFields(Type.getClass(check))) {. But then the non-genjvm tests fail with Cannot access field for writing.

Anyway, genjvm is within the spec here, but to be honest I'm not sure why we can't just make Reflect.fields call Type.getInstanceFields if the passed object is a Haxe-class.

from genjvm.

AlexHaxe avatar AlexHaxe commented on August 18, 2024

I guess I should have read the docs more carefully instead of going with what worked when writing that function.

getInstanceFields works but an extra Reflect.isFunction is needed to skip putting functions into the resulting check configuration.

from genjvm.

AlexHaxe avatar AlexHaxe commented on August 18, 2024

fixed in HaxeCheckstyle/haxe-checkstyle#498

note: I rearranged build files a bit, there is now a testJava.hxml and a testJvm.hxml

from genjvm.

Simn avatar Simn commented on August 18, 2024

Alright, thanks for the info! I also realized that I would have to add this isFunction check if I wanted to call getInstanceFields from Reflect.fields. That seems pretty heavy, so I prefer to not do it and point to the documentation.

I would only consider this if all targets already worked like that, but I don't think that's the case. You probably just got lucky that it works on the targets you were using.

from genjvm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.