1

For example, I have this code:

// ... for (int i = 0; i < 5000; ++i) { for (int j = 0; j < 7000; ++j) { // Do something... } } // ... 

Can I change it using annotations? If yes, how I can perform it? Something like this:

// ... @SplitFor(value="i < 2000, j < 3000") for (int i = 0; i < 5000; ++i) { for (int j = 0; j < 7000; ++j) { // Do something... } } // ... 

Should translate to:

// ... for (int i = 0; i < 2000; ++i) { for (int j = 0; j < 3000; ++j) { // Do something... } } // ... 

It possible? If yes -- HOW?

P.S.: This is can used for easy parallelization: I can generate split loops for used it in Fork/Join framework, for example.

4
  • 1
    Even if you could do this, why would you do it? It just makes the code more difficult to read. Commented Aug 25, 2012 at 22:38
  • It's fairly easy to type the numbers in your self...I'm not sure if I see the benefit. Commented Aug 25, 2012 at 22:40
  • @vanveber you could implement this if you really wanted to. Commented Aug 25, 2012 at 22:43
  • For example it used for parallelization: I can wrap loops and generate code for Fork/Join. I think that this code contain enough information for create Fork/Join implementation, but this representation more easy to read than this analog. Commented Aug 25, 2012 at 22:51

1 Answer 1

1

Typically, you'd do this in one of two ways:

  1. An annotation processor, which would see the annotation, and alter the class code
  2. Aspectj, which could find the annotation, and do runtime weaving of code, though i'm not sure what capability it would have of doing a block replace of code. typically people use this for before/after/around advice not for replacing code.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.